]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Search.pm
search: support alt-ID for mapping legacy serial numbers
[public-inbox.git] / lib / PublicInbox / Search.pm
index 3a908ac6caba8124a8c7ce4071ee3692e4cb063b..018fcb5537676ba6d9548f2c238451d317f8c1cd 100644 (file)
@@ -79,10 +79,10 @@ sub xdir {
 }
 
 sub new {
-       my ($class, $git_dir) = @_;
+       my ($class, $git_dir, $altid) = @_;
        my $dir = $class->xdir($git_dir);
        my $db = Search::Xapian::Database->new($dir);
-       bless { xdb => $db, git_dir => $git_dir }, $class;
+       bless { xdb => $db, git_dir => $git_dir, altid => $altid }, $class;
 }
 
 sub reopen { $_[0]->{xdb}->reopen }
@@ -186,6 +186,18 @@ sub qp {
                $qp->add_boolean_prefix($name, $prefix);
        }
 
+       # we do not actually create AltId objects,
+       # just parse the spec to avoid the extra DB handles for now.
+       if (my $altid = $self->{altid}) {
+               for (@$altid) {
+                       # $_ = 'serial:gmane:/path/to/gmane.msgmap.sqlite3'
+                       /\Aserial:(\w+):/ or next;
+                       my $pfx = $1;
+                       # gmane => XGMANE
+                       $qp->add_boolean_prefix($pfx, 'X'.uc($pfx));
+               }
+       }
+
        while (my ($name, $prefix) = each %prob_prefix) {
                $qp->add_prefix($name, $prefix);
        }