about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchView.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-12-20 23:42:36 +0000
committerEric Wong <e@80x24.org>2016-12-21 07:32:56 +0000
commit90b3d23352a0c37680ac266acaf4fef73a781bc9 (patch)
tree93d0a1a539f923a7045c517a882bd42995fd7567 /lib/PublicInbox/SearchView.pm
parent93474f58d361b2ace4d5e51d5be4c220513da8d0 (diff)
downloadpublic-inbox-90b3d23352a0c37680ac266acaf4fef73a781bc9.tar.gz
This simplifies callers to prevent errors and avoids
needless object-orientation in favor of a single procedure
call to handle threading and ordering.
Diffstat (limited to 'lib/PublicInbox/SearchView.pm')
-rw-r--r--lib/PublicInbox/SearchView.pm25
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 50a2c01c..bd634d8d 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -161,6 +161,15 @@ sub search_nav_bot {
         $rv .= '</pre>';
 }
 
+sub sort_relevance {
+        my ($pct) = @_;
+        sub {
+                [ sort { (eval { $pct->{$b->topmost->{id}} } || 0)
+                                <=>
+                        (eval { $pct->{$a->topmost->{id}} } || 0)
+        } @{$_[0]} ] };
+}
+
 sub mset_thread {
         my ($ctx, $mset, $q) = @_;
         my %pct;
@@ -171,18 +180,8 @@ sub mset_thread {
                 $smsg;
         } ($mset->items) ]});
 
-        my $th = PublicInbox::SearchThread->new($msgs);
-        $th->thread;
-        if ($q->{r}) { # order by relevance
-                $th->order(sub {
-                        [ sort { (eval { $pct{$b->topmost->{id}} } || 0)
-                                        <=>
-                                (eval { $pct{$a->topmost->{id}} } || 0)
-                        } @{$_[0]} ];
-                });
-        } else { # order by time (default for threaded view)
-                $th->order(*PublicInbox::View::sort_ts);
-        }
+        my $rootset = PublicInbox::SearchThread::thread($msgs,
+                $q->{r} ? sort_relevance(\%pct) : *PublicInbox::View::sort_ts);
         my $skel = search_nav_bot($mset, $q). "<pre>";
         my $inbox = $ctx->{-inbox};
         $ctx->{-upfx} = '';
@@ -196,7 +195,7 @@ sub mset_thread {
         $ctx->{seen} = {};
         $ctx->{s_nr} = scalar(@$msgs).'+ results';
 
-        PublicInbox::View::walk_thread($th, $ctx,
+        PublicInbox::View::walk_thread($rootset, $ctx,
                 *PublicInbox::View::pre_thread);
 
         my $mime;