]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchView.pm
remove Email::Address dependency
[public-inbox.git] / lib / PublicInbox / SearchView.pm
index 41d32007e79c6f5f42c34db84456fcd0e6f9ab4e..0ae050529ca0601da056463b11ab5acece6ccf25 100644 (file)
@@ -11,6 +11,7 @@ use PublicInbox::View;
 use PublicInbox::MID qw(mid2path mid_clean mid_mime);
 use Email::MIME;
 require PublicInbox::Git;
+require PublicInbox::Thread;
 our $LIM = 50;
 
 sub sres_top_html {
@@ -151,23 +152,19 @@ sub tdump {
        } ($mset->items);
 
        my @rootset;
-       my $th = PublicInbox::View::thread_results(\@m, 0, $q->{r});
-       if ($q->{r}) {
+       my $th = PublicInbox::Thread->new(@m);
+       $th->thread;
+       if ($q->{r}) { # order by relevance
                $th->order(sub {
                        sort { (eval { $pct{$b->topmost->messageid} } || 0)
                                        <=>
                                (eval { $pct{$a->topmost->messageid} } || 0)
                        } @_;
                });
-               @rootset = $th->rootset;
-       } else {
-               @rootset = sort {
-                       (eval { $b->topmost->message->header('X-PI-TS') } || 0)
-                               <=>
-                       (eval { $a->topmost->message->header('X-PI-TS') } || 0)
-               } $th->rootset;
+       } else { # order by time (default for threaded view)
+               $th->order(*PublicInbox::View::sort_ts);
        }
-
+       @rootset = $th->rootset;
        my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
        my $state = {
                ctx => $ctx,
@@ -179,7 +176,6 @@ sub tdump {
        $ctx->{searchview} = 1;
        tdump_ent($git, $state, $_, 0) for @rootset;
        PublicInbox::View::thread_adj_level($state, 0);
-       Email::Address->purge_cache;
 
        $fh->write(search_nav_bot($mset, $q). "\n\n" .
                        foot($ctx). '</pre></body></html>');
@@ -266,10 +262,11 @@ use PublicInbox::Hval;
 sub new {
        my ($class, $cgi) = @_;
        my $r = $cgi->param('r');
+       my ($off) = (($cgi->param('o') || '0') =~ /(\d+)/);
        bless {
                q => $cgi->param('q'),
                x => $cgi->param('x') || '',
-               o => int($cgi->param('o') || 0) || 0,
+               o => $off,
                r => (defined $r && $r ne '0'),
        }, $class;
 }