X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearch.pm;h=34ebd1a6e7d59b02eaa0931fd1c39413d96e0e56;hb=936670cb83971bf250571a7dd9b0a0a0b33babd8;hp=91251246ccf4ddf20a94af806787aae89637d14a;hpb=35ff6bb106909b1c1232666a9792156dfa398ea8;p=public-inbox.git diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index 91251246..34ebd1a6 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -9,7 +9,8 @@ use warnings; # values for searching use constant TS => 0; # Received: header in Unix time -use constant YYYYMMDD => 1; # for searching in the WWW UI +use constant YYYYMMDD => 1; # Date: header for searching in the WWW UI +use constant DT => 2; # Date: YYYYMMDDHHMMSS use Search::Xapian qw/:standard/; use PublicInbox::SearchMsg; @@ -88,6 +89,9 @@ our @HELP = ( date range as YYYYMMDD e.g. d:19931002..20101002 Open-ended ranges such as d:19931002.. and d:..20101002 are also supported +EOF + 'dt:' => < 'match within message body, including text attachments', 'nq:' => 'match non-quoted text within message body', @@ -179,16 +183,22 @@ sub query { } sub get_thread { - my ($self, $mid, $opts) = @_; - $self->{over_ro}->get_thread($mid, $opts); + my ($self, $mid, $prev) = @_; + $self->{over_ro}->get_thread($mid, $prev); } sub retry_reopen { my ($self, $cb) = @_; - my $ret; for my $i (1..10) { - eval { $ret = $cb->() }; - return $ret unless $@; + if (wantarray) { + my @ret; + eval { @ret = $cb->() }; + return @ret unless $@; + } else { + my $ret; + eval { $ret = $cb->() }; + return $ret unless $@; + } # Exception: The revision being read has been discarded - # you should call Xapian::Database::reopen() if (ref($@) eq 'Search::Xapian::DatabaseModifiedError') { @@ -210,11 +220,14 @@ sub _do_enquire { sub _enquire_once { my ($self, $query, $opts) = @_; my $enquire = enquire($self); - $query = Search::Xapian::Query->new(OP_AND,$query); $enquire->set_query($query); $opts ||= {}; my $desc = !$opts->{asc}; - if ($opts->{relevance}) { + if (($opts->{mset} || 0) == 2) { + $enquire->set_docid_order(Search::Xapian::ENQ_ASCENDING()); + $enquire->set_weighting_scheme(Search::Xapian::BoolWeight->new); + delete $self->{enquire}; + } elsif ($opts->{relevance}) { $enquire->set_sort_by_relevance_then_value(TS, $desc); } else { $enquire->set_sort_by_value_then_relevance(TS, $desc); @@ -226,8 +239,9 @@ sub _enquire_once { my @msgs = map { PublicInbox::SearchMsg->load_doc($_->get_document); } $mset->items; + return \@msgs unless wantarray; - { total => $mset->get_matches_estimated, msgs => \@msgs } + ($mset->get_matches_estimated, \@msgs) } # read-write @@ -248,6 +262,8 @@ sub qp { $qp->set_stemming_strategy(STEM_SOME); $qp->add_valuerangeprocessor( Search::Xapian::NumberValueRangeProcessor->new(YYYYMMDD, 'd:')); + $qp->add_valuerangeprocessor( + Search::Xapian::NumberValueRangeProcessor->new(DT, 'dt:')); while (my ($name, $prefix) = each %bool_pfx_external) { $qp->add_boolean_prefix($name, $prefix); @@ -284,8 +300,8 @@ sub query_xover { } sub query_ts { - my ($self, $ts, $offset) = @_; - $self->{over_ro}->query_ts($ts, $offset); + my ($self, $ts, $prev) = @_; + $self->{over_ro}->query_ts($ts, $prev); } sub first_smsg_by_mid {