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 # Read-only external (detached) index for cross inbox search.
5 # This is a read-only counterpart to PublicInbox::ExtSearchIdx
6 # and behaves like PublicInbox::Inbox AND PublicInbox::Search
7 package PublicInbox::ExtSearch;
10 use PublicInbox::Over;
11 use PublicInbox::Inbox;
13 use PublicInbox::MiscSearch;
14 use DBI qw(:sql_types); # SQL_BLOB
16 # for ->reopen, ->mset, ->mset_to_artnums
17 use parent qw(PublicInbox::Search);
20 my (undef, $topdir) = @_;
21 $topdir = File::Spec->canonpath($topdir);
25 xpfx => "$topdir/ei".PublicInbox::Search::SCHEMA_VERSION
31 $self->{misc} //= PublicInbox::MiscSearch->new("$self->{xpfx}/misc");
34 sub search { $_[0] } # self
36 # overrides PublicInbox::Search::_xdb
42 # same as per-inbox ->over, for now...
45 $self->{over} //= PublicInbox::Over->new("$self->{xpfx}/over.sqlite3");
50 $self->{git} //= PublicInbox::Git->new("$self->{topdir}/ALL.git");
53 # returns a hashref of { $NEWSGROUP_NAME => $ART_NO } using the `xref3' table
54 sub nntp_xref_for { # NNTP only
55 my ($self, $xibx, $xsmsg) = @_;
56 my $dbh = over($self)->dbh;
58 my $sth = $dbh->prepare_cached(<<'', undef, 1);
59 SELECT ibx_id FROM inboxes WHERE eidx_key = ? LIMIT 1
61 $sth->execute($xibx->{newsgroup});
62 my $xibx_id = $sth->fetchrow_array // do {
63 warn "W: `$xibx->{newsgroup}' not found in $self->{topdir}\n";
67 $sth = $dbh->prepare_cached(<<'', undef, 1);
68 SELECT docid FROM xref3 WHERE oidbin = ? AND xnum = ? AND ibx_id = ? LIMIT 1
70 $sth->bind_param(1, pack('H*', $xsmsg->{blob}), SQL_BLOB);
72 # NNTP::cmd_over can set {num} to zero according to RFC 3977 8.3.2
73 $sth->bind_param(2, $xsmsg->{num} || $xsmsg->{-orig_num});
74 $sth->bind_param(3, $xibx_id);
76 my $docid = $sth->fetchrow_array // do {
78 W: `$xibx->{newsgroup}:$xsmsg->{num}' not found in $self->{topdir}"
83 # LIMIT is number of newsgroups on server:
84 $sth = $dbh->prepare_cached(<<'', undef, 1);
85 SELECT ibx_id,xnum FROM xref3 WHERE docid = ? AND ibx_id != ?
87 $sth->execute($docid, $xibx_id);
88 my $rows = $sth->fetchall_arrayref;
90 my $eidx_key_sth = $dbh->prepare_cached(<<'', undef, 1);
91 SELECT eidx_key FROM inboxes WHERE ibx_id = ? LIMIT 1
94 my ($ibx_id, $xnum) = @$_;
96 $eidx_key_sth->execute($ibx_id);
97 my $eidx_key = $eidx_key_sth->fetchrow_array;
99 # only include if there's a newsgroup name
100 $eidx_key && index($eidx_key, '/') >= 0 ?
101 () : ($eidx_key => $xnum)
103 $xref{$xibx->{newsgroup}} = $xsmsg->{num};
113 ($self->{description} //=
114 PublicInbox::Inbox::cat_desc("$self->{topdir}/description")) //
115 '$EXTINDEX_DIR/description missing';
118 sub cloneurl { [] } # TODO
120 sub base_url { 'https://example.com/TODO/' }
124 *smsg_eml = \&PublicInbox::Inbox::smsg_eml;
125 *smsg_by_mid = \&PublicInbox::Inbox::smsg_by_mid;
126 *msg_by_mid = \&PublicInbox::Inbox::msg_by_mid;
127 *modified = \&PublicInbox::Inbox::modified;
128 *recent = \&PublicInbox::Inbox::recent;
130 *max_git_epoch = *nntp_usable = *msg_by_path = \&mm; # undef