]> Sergey Matveev's repositories - public-inbox.git/commitdiff
extsearch: start mocking out
authorEric Wong <e@80x24.org>
Tue, 27 Oct 2020 07:54:04 +0000 (07:54 +0000)
committerEric Wong <e@80x24.org>
Sat, 7 Nov 2020 09:55:05 +0000 (09:55 +0000)
This will provide a similar API to PublicInbox::Inbox for
read-only WWW, -imapd, and -nntpd interfaces.

MANIFEST
lib/PublicInbox/ExtSearch.pm [new file with mode: 0644]
lib/PublicInbox/Search.pm
t/extsearch.t [new file with mode: 0644]

index b6a681e9b533e50971ae416a25ef7f9d94a6eb10..60055d2b10b1d61b9cd5a2018a5acc34f2fc0979 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -121,6 +121,7 @@ lib/PublicInbox/Emergency.pm
 lib/PublicInbox/Eml.pm
 lib/PublicInbox/EmlContentFoo.pm
 lib/PublicInbox/ExtMsg.pm
+lib/PublicInbox/ExtSearch.pm
 lib/PublicInbox/FakeInotify.pm
 lib/PublicInbox/Feed.pm
 lib/PublicInbox/Filter/Base.pm
@@ -269,6 +270,7 @@ t/eml.t
 t/eml_content_disposition.t
 t/eml_content_type.t
 t/epoll.t
+t/extsearch.t
 t/fail-bin/spamc
 t/fake_inotify.t
 t/feed.t
diff --git a/lib/PublicInbox/ExtSearch.pm b/lib/PublicInbox/ExtSearch.pm
new file mode 100644 (file)
index 0000000..9bbe785
--- /dev/null
@@ -0,0 +1,40 @@
+# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# Read-only external (detached) index for cross inbox search.
+# This is a read-only counterpart to PublicInbox::ExtSearchIdx
+package PublicInbox::ExtSearch;
+use strict;
+use v5.10.1;
+use PublicInbox::Over;
+
+# for ->reopen, ->mset, ->mset_to_artnums
+use parent qw(PublicInbox::Search);
+
+sub new {
+       my (undef, $topdir) = @_;
+       bless {
+               topdir => $topdir,
+               # xpfx => 'ei15'
+               xpfx => "$topdir/ei".PublicInbox::Search::SCHEMA_VERSION
+       }, __PACKAGE__;
+}
+
+# overrides PublicInbox::Search::_xdb
+sub _xdb {
+       my ($self) = @_;
+       $self->_xdb_sharded($self->{xpfx});
+}
+
+# same as per-inbox ->over, for now...
+sub over {
+       my ($self) = @_;
+       $self->{over} //= PublicInbox::Over->new("$self->{xpfx}/over.sqlite3");
+}
+
+sub git {
+       my ($self) = @_;
+       $self->{git} //= PublicInbox::Git->new("$self->{topdir}/ALL.git");
+}
+
+1;
index 6346d78838e38301e7306e6b5222a35ca5b8a365..5a57657ff4da5b1332afe8db5ed39b35c06f7d4e 100644 (file)
@@ -245,9 +245,9 @@ sub mset_to_artnums {
 
 sub xdb ($) {
        my ($self) = @_;
-       $self->{xdb} ||= do {
+       $self->{xdb} //= do {
                load_xapian();
-               _xdb($self);
+               $self->_xdb;
        };
 }
 
diff --git a/t/extsearch.t b/t/extsearch.t
new file mode 100644 (file)
index 0000000..7687f5f
--- /dev/null
@@ -0,0 +1,11 @@
+#!perl -w
+# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict;
+use Test::More;
+use PublicInbox::TestCommon;
+require_git(2.6);
+require_mods(qw(DBD::SQLite Search::Xapian));
+use_ok 'PublicInbox::ExtSearch';
+
+done_testing;