From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E273F1FF9F for ; Tue, 27 Oct 2020 07:54:53 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 03/52] extsearch: start mocking out Date: Tue, 27 Oct 2020 07:54:04 +0000 Message-Id: <20201027075453.19163-4-e@80x24.org> In-Reply-To: <20201027075453.19163-1-e@80x24.org> References: <20201027075453.19163-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This will provide a similar API to PublicInbox::Inbox for read-only WWW, -imapd, and -nntpd interfaces. --- MANIFEST | 2 ++ lib/PublicInbox/ExtSearch.pm | 40 ++++++++++++++++++++++++++++++++++++ lib/PublicInbox/Search.pm | 4 ++-- t/extsearch.t | 11 ++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 lib/PublicInbox/ExtSearch.pm create mode 100644 t/extsearch.t diff --git a/MANIFEST b/MANIFEST index b6a681e9..60055d2b 100644 --- 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 index 00000000..9bbe7857 --- /dev/null +++ b/lib/PublicInbox/ExtSearch.pm @@ -0,0 +1,40 @@ +# Copyright (C) 2020 all contributors +# License: AGPL-3.0+ + +# 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; diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index 6346d788..5a57657f 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -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 index 00000000..7687f5f0 --- /dev/null +++ b/t/extsearch.t @@ -0,0 +1,11 @@ +#!perl -w +# Copyright (C) 2020 all contributors +# License: AGPL-3.0+ +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;