From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/5] extmsg: wire up to use msgmap for prefixes
Date: Tue, 15 Sep 2015 01:08:03 +0000 [thread overview]
Message-ID: <20150915010804.20084-5-e@80x24.org> (raw)
In-Reply-To: <20150915010804.20084-1-e@80x24.org>
DBI + DBD::SQLite has much better handling of prefix lookups
than Xapian. While we're at it, avoid linking blatantly wrong
Message-IDs to external services.
---
lib/PublicInbox/ExtMsg.pm | 29 +++++++++++++++++------------
lib/PublicInbox/Search.pm | 9 ---------
2 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm
index 77537c2..0cba49d 100644
--- a/lib/PublicInbox/ExtMsg.pm
+++ b/lib/PublicInbox/ExtMsg.pm
@@ -54,7 +54,7 @@ sub ext_msg {
# no point in trying the fork fallback if we
# know Xapian is up-to-date but missing the
# message in the current repo
- push @pfx, { srch => $s, url => $url };
+ push @pfx, { git_dir => $git_dir, url => $url };
next;
}
}
@@ -87,17 +87,21 @@ sub ext_msg {
# fall back to partial MID matching
my $n_partial = 0;
my @partial;
- if ($have_xap) {
+
+ eval { require PublicInbox::Msgmap };
+ my $have_mm = $@ ? 0 : 1;
+ if ($have_mm) {
my $cgi = $ctx->{cgi};
my $url = ref($cgi) eq 'CGI' ? $cgi->url(-base) . '/'
: $cgi->base->as_string;
$url .= $listname;
- unshift @pfx, { srch => $ctx->{srch}, url => $url };
+ unshift @pfx, { git_dir => $ctx->{git_dir}, url => $url };
foreach my $pfx (@pfx) {
- my $srch = delete $pfx->{srch} or next;
+ my $git_dir = delete $pfx->{git_dir} or next;
+ my $mm = eval { PublicInbox::Msgmap->new($git_dir) };
- # FIXME we may need a proper prefix trie here...
- if (my $res = $srch->mid_prefix($mid)) {
+ $mm or next;
+ if (my $res = $mm->mid_prefixes($mid)) {
$n_partial += scalar(@$res);
$pfx->{res} = $res;
push @partial, $pfx;
@@ -114,20 +118,21 @@ sub ext_msg {
if ($n_partial) {
$code = 300;
- $s.= "\nPartial matches found:\n\n";
+ my $es = $n_partial == 1 ? '' : 'es';
+ $s.= "\n$n_partial partial match$es found:\n\n";
foreach my $pfx (@partial) {
my $u = $pfx->{url};
foreach my $m (@{$pfx->{res}}) {
- $h = PublicInbox::Hval->new($m);
- $href = $h->as_href;
- $html = $h->as_html;
- $s .= qq{<a\nhref="$u/$href/">$u/$html/</a>\n};
+ my $p = PublicInbox::Hval->new($m);
+ my $r = $p->as_href;
+ my $t = $p->as_html;
+ $s .= qq{<a\nhref="$u/$r/">$u/$t/</a>\n};
}
}
}
# Fall back to external repos if configured
- if (@EXT_URL) {
+ if (@EXT_URL && index($mid, '@') >= 0) {
$code = 300;
$s .= "\nPerhaps try an external site:\n\n";
foreach my $u (@EXT_URL) {
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index 2b33b39..a588af4 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -269,13 +269,4 @@ sub enquire {
$self->{enquire} ||= Search::Xapian::Enquire->new($self->{xdb});
}
-sub mid_prefix {
- my ($self, $mpfx) = @_;
- my $query = eval { $self->qp->parse_query("m:$mpfx", FLAG_PARTIAL) };
- return if $@;
- my $res = $self->do_enquire($query, { relevance => 1 });
- return unless $res->{total};
- [ map { $_->mid } @{$res->{msgs}} ];
-}
-
1;
--
EW
next prev parent reply other threads:[~2015-09-15 1:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-15 1:07 [PATCH 0/5] introduce SQLite message map Eric Wong
2015-09-15 1:08 ` [PATCH 1/5] msgmap: add message mapping via SQLite Eric Wong
2015-09-15 1:08 ` [PATCH 2/5] searchidx: hoist out rlog code Eric Wong
2015-09-15 1:08 ` [PATCH 3/5] searchidx: sync Msgmap database along with Xapian Eric Wong
2015-09-15 1:08 ` Eric Wong [this message]
2015-09-15 1:08 ` [PATCH 5/5] INSTALL: document DBD::SQLite and DBI dependencies Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150915010804.20084-5-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).