From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id F1301205BD for ; Thu, 23 May 2019 09:37:05 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 04/26] search: reenable phrase search on non-chert Xapian Date: Thu, 23 May 2019 09:36:42 +0000 Message-Id: <20190523093704.18367-5-e@80x24.org> In-Reply-To: <20190523093704.18367-1-e@80x24.org> References: <20190523093704.18367-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This is assuming nobody uses flint or earlier, anymore; as flint predates the existence of this project. --- lib/PublicInbox/Search.pm | 48 +++++++++++++++++++++++---------------- t/search.t | 1 + 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index eae10d8..d861cf4 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -24,8 +24,8 @@ sub load_xapian () { # n.b. FLAG_PURE_NOT is expensive not suitable for a public # website as it could become a denial-of-service vector - # FLAG_PHRASE also seems to cause performance problems - # sometimes. + # FLAG_PHRASE also seems to cause performance problems chert + # (and probably earlier Xapian DBs). glass seems fine... # TODO: make this an option, maybe? # or make indexlevel=medium as default FLAG_PHRASE()|FLAG_BOOLEAN()|FLAG_LOVEHATE()|FLAG_WILDCARD(); @@ -137,26 +137,35 @@ sub xdir ($;$) { } } +sub _xdb ($) { + my ($self) = @_; + my $dir = xdir($self, 1); + my ($xdb, $slow_phrase); + my $qpf = \($self->{qp_flags} ||= $QP_FLAGS); + if ($self->{version} >= 2) { + foreach my $part (<$dir/*>) { + -d $part && $part =~ m!/\d+\z! or next; + my $sub = Search::Xapian::Database->new($part); + if ($xdb) { + $xdb->add_database($sub); + } else { + $xdb = $sub; + } + $slow_phrase ||= -f "$part/iamchert"; + } + } else { + $slow_phrase = -f "$dir/iamchert"; + $xdb = Search::Xapian::Database->new($dir); + } + $$qpf |= FLAG_PHRASE() unless $slow_phrase; + $xdb; +} + sub xdb ($) { my ($self) = @_; $self->{xdb} ||= do { load_xapian(); - my $dir = xdir($self, 1); - if ($self->{version} >= 2) { - my $xdb; - foreach my $part (<$dir/*>) { - -d $part && $part =~ m!/\d+\z! or next; - my $sub = Search::Xapian::Database->new($part); - if ($xdb) { - $xdb->add_database($sub); - } else { - $xdb = $sub; - } - } - $xdb; - } else { - Search::Xapian::Database->new($dir); - } + _xdb($self); }; } @@ -194,7 +203,8 @@ sub query { $self->{over_ro}->recent($opts); } else { my $qp = qp($self); - my $query = $qp->parse_query($query_string, $QP_FLAGS); + my $qp_flags = $self->{qp_flags}; + my $query = $qp->parse_query($query_string, $qp_flags); $opts->{relevance} = 1 unless exists $opts->{relevance}; _do_enquire($self, $query, $opts); } diff --git a/t/search.t b/t/search.t index c063620..538baef 100644 --- a/t/search.t +++ b/t/search.t @@ -30,6 +30,7 @@ my $ro = PublicInbox::Search->new($git_dir); my $rw_commit = sub { $rw->commit_txn_lazy if $rw; $rw = PublicInbox::SearchIdx->new($git_dir, 1); + $rw->{qp_flags} = 0; # quiet a warning $rw->begin_txn_lazy; }; -- EW