1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Combine any combination of PublicInbox::Search,
5 # PublicInbox::ExtSearch, and PublicInbox::LeiSearch objects
7 package PublicInbox::LeiXSearch;
10 use parent qw(PublicInbox::LeiSearch);
14 PublicInbox::Search::load_xapian();
16 qp_flags => $PublicInbox::Search::QP_FLAGS |
17 PublicInbox::Search::FLAG_PURE_NOT(),
22 my ($self, $ibxish) = @_; # ibxish = ExtSearch or Inbox
23 if (!$ibxish->can('over')) {
24 push @{$self->{remotes}}, $ibxish
26 if (delete $self->{xdb}) { # XXX: do we need this?
27 # clobber existing {xdb} if amending
28 my $expect = delete $self->{nshard};
29 my $shards = delete $self->{shards_flat};
30 scalar(@$shards) == $expect or die
31 "BUG: {nshard}$expect != shards=".scalar(@$shards);
34 for my $old_ibxish (@{$self->{shard2ibx}}) {
35 next if $prev == $old_ibxish;
37 my @shards = $old_ibxish->search->xdb_shards_flat;
38 push @{$self->{shards_flat}}, @shards;
40 my $nr = scalar(@{$self->{shards_flat}});
42 "BUG: reloaded $nr shards, expected $expect"
44 my @shards = $ibxish->search->xdb_shards_flat;
45 push @{$self->{shards_flat}}, @shards;
46 push(@{$self->{shard2ibx}}, $ibxish) for (@shards);
49 # called by PublicInbox::Search::xdb
50 sub xdb_shards_flat { @{$_[0]->{shards_flat}} }
54 my ($self, $mitem) = @_;
55 # cf. https://trac.xapian.org/wiki/FAQ/MultiDatabaseDocumentID
56 my $nshard = $self->{nshard};
57 my $docid = $mitem->get_docid;
58 my $shard = ($docid - 1) % $nshard;
59 my $num = int(($docid - 1) / $nshard) + 1;
60 my $smsg = $self->{shard2ibx}->[$shard]->over->get_art($num);
61 $smsg->{docid} = $docid;
66 my ($self, $qstr, $opt) = @_;
68 $opt->{relevance} //= -2;
69 $self->mset($qstr //= 'bytes:1..', $opt);