about summary refs log tree commit homepage
path: root/lib/PublicInbox/Search.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox/Search.pm')
-rw-r--r--lib/PublicInbox/Search.pm36
1 files changed, 31 insertions, 5 deletions
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index fbdb48a3..eb5e67ba 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -54,6 +54,9 @@ use constant {
         #
         #      v1.6.0 adds BYTES, UID and THREADID values
         SCHEMA_VERSION => 15,
+
+        # we may have up to 8 FDs per shard (depends on Xapian *shrug*)
+        SHARD_COST => 8,
 };
 
 use PublicInbox::Smsg;
@@ -92,6 +95,7 @@ our @XH_SPEC = (
         'K=i', # timeout kill after i seconds
         'O=s', # eidx_key
         'T=i', # threadid
+        'Q=s@', # query prefixes "$user_prefix[:=]$XPREFIX"
 );
 
 sub load_xapian () {
@@ -435,8 +439,8 @@ sub xhc_start_maybe (@) {
         $xhc;
 }
 
-sub xh_opt ($) {
-        my ($opt) = @_;
+sub xh_opt ($$) {
+        my ($self, $opt) = @_;
         my $lim = $opt->{limit} || 50;
         my @ret;
         push @ret, '-o', $opt->{offset} if $opt->{offset};
@@ -458,7 +462,16 @@ sub xh_opt ($) {
         push @ret, '-t' if $opt->{threads};
         push @ret, '-T', $opt->{threadid} if defined $opt->{threadid};
         push @ret, '-O', $opt->{eidx_key} if defined $opt->{eidx_key};
-        @ret;
+        my $apfx = $self->{-alt_pfx} //= do {
+                my @tmp;
+                for (grep /\Aserial:/, @{$self->{altid} // []}) {
+                        my (undef, $pfx) = split /:/, $_;
+                        push @tmp, '-Q', "$pfx=X\U$pfx";
+                }
+                # TODO: arbitrary header indexing goes here
+                \@tmp;
+        };
+        (@ret, @$apfx);
 }
 
 # returns a true value if actually handled asynchronously,
@@ -467,7 +480,7 @@ sub async_mset {
         my ($self, $qry_str, $opt, $cb, @args) = @_;
         if ($XHC) { # unconditionally retrieving pct + rank for now
                 xdb($self); # populate {nshards}
-                my @margs = ($self->xh_args, xh_opt($opt));
+                my @margs = ($self->xh_args, xh_opt($self, $opt), '--');
                 my $ret = eval {
                         my $rd = $XHC->mkreq(undef, 'mset', @margs, $qry_str);
                         PublicInbox::XhcMset->maybe_new($rd, $self, $cb, @args);
@@ -630,7 +643,7 @@ EOM
                         $ret .= qq{\tqp->add_boolean_prefix("$name", "$_");\n}
                 }
         }
-        # TODO: altid support
+        # altid support is handled in xh_opt and srch_init_extra in XH
         for my $name (sort keys %prob_prefix) {
                 for (split(/ /, $prob_prefix{$name})) {
                         $ret .= qq{\tqp->add_prefix("$name", "$_");\n}
@@ -719,4 +732,17 @@ sub get_doc ($$) {
         }
 }
 
+# not sure where best to put this...
+sub ulimit_n () {
+        my $n;
+        if (eval { require BSD::Resource; 1 }) {
+                my $NOFILE = BSD::Resource::RLIMIT_NOFILE();
+                ($n, undef) = BSD::Resource::getrlimit($NOFILE);
+        } else {
+                require PublicInbox::Spawn;
+                $n = PublicInbox::Spawn::run_qx([qw(/bin/sh -c), 'ulimit -n']);
+        }
+        $n;
+}
+
 1;