From 9b5bf24a115346ef6095f4c613b4579fde112714 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 25 Dec 2019 07:50:59 +0000 Subject: searchview: remove anonymous sub when sorting threads by relevance We don't need to return a closure or have a separate hash for sorting threads by relevance. Instead, we can stuff the relevance {pct} into the SearchMsg object itself and use that. Note: upon reviewing this code, the sort-by-relevance seems bogus as it only considers the relevance of the topmost message. Instead, it would make more sense to the user to sort by the highest relevance of all messages in that particular thread. --- lib/PublicInbox/SearchView.pm | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'lib/PublicInbox/SearchView.pm') diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 6aa815ca..8cffdedb 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -256,12 +256,10 @@ sub search_nav_bot { } sub sort_relevance { - my ($pct) = @_; - sub { - [ sort { (eval { $pct->{$b->topmost->{id}} } || 0) - <=> - (eval { $pct->{$a->topmost->{id}} } || 0) - } @{$_[0]} ] }; + [ sort { + (eval { $b->topmost->{smsg}->{pct} } // 0) <=> + (eval { $a->topmost->{smsg}->{pct} } // 0) + } @{$_[0]} ] } sub get_pct ($) { @@ -274,16 +272,15 @@ sub get_pct ($) { sub mset_thread { my ($ctx, $mset, $q) = @_; - my %pct; my $msgs = $ctx->{-inbox}->search->retry_reopen(sub { [ map { my $i = $_; my $smsg = PublicInbox::SearchMsg->load_doc($i->get_document); - $pct{$smsg->mid} = get_pct($i); + $smsg->{pct} = get_pct($i); $smsg; } ($mset->items) ]}); my $r = $q->{r}; my $rootset = PublicInbox::SearchThread::thread($msgs, - $r ? sort_relevance(\%pct) : \&PublicInbox::View::sort_ds, + $r ? \&sort_relevance : \&PublicInbox::View::sort_ds, $ctx); my $skel = search_nav_bot($mset, $q). "
";
 	$ctx->{-upfx} = '';
@@ -291,7 +288,7 @@ sub mset_thread {
 	$ctx->{cur_level} = 0;
 	$ctx->{dst} = \$skel;
 	$ctx->{mapping} = {};
-	$ctx->{pct} = \%pct;
+	$ctx->{searchview} = 1;
 	$ctx->{prev_attr} = '';
 	$ctx->{prev_level} = 0;
 	$ctx->{s_nr} = scalar(@$msgs).'+ results';
-- 
cgit v1.2.3-24-ge0c7