From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] wip
Date: Sun, 3 Jan 2021 22:57:56 +0000 [thread overview]
Message-ID: <20210103225756.30660-1-e@80x24.org> (raw)
---
lib/PublicInbox/LEI.pm | 7 ++-----
lib/PublicInbox/LeiExternal.pm | 33 ++++++++++++++++++++++-----------
lib/PublicInbox/LeiStore.pm | 2 +-
lib/PublicInbox/LeiXSearch.pm | 16 ++++++++++++++++
t/lei.t | 12 +++++++++---
5 files changed, 50 insertions(+), 20 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index a0ea793b..6b141a37 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -8,7 +8,8 @@
package PublicInbox::LEI;
use strict;
use v5.10.1;
-use parent qw(PublicInbox::DS PublicInbox::LeiExternal);
+use parent qw(PublicInbox::DS PublicInbox::LeiExternal
+ PublicInbox::LeiQuery);
use Getopt::Long ();
use Socket qw(AF_UNIX SOCK_STREAM pack_sockaddr_un);
use Errno qw(EAGAIN ECONNREFUSED ENOENT);
@@ -475,10 +476,6 @@ sub lei_show {
my ($self, @argv) = @_;
}
-sub lei_query {
- my ($self, @argv) = @_;
-}
-
sub lei_mark {
my ($self, @argv) = @_;
}
diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm
index 4facd451..64faf5a0 100644
--- a/lib/PublicInbox/LeiExternal.pm
+++ b/lib/PublicInbox/LeiExternal.pm
@@ -8,24 +8,35 @@ use v5.10.1;
use parent qw(Exporter);
our @EXPORT = qw(lei_ls_external lei_add_external lei_forget_external);
-sub lei_ls_external {
- my ($self, @argv) = @_;
- my $stor = $self->_lei_store(0);
+sub _externals_each {
+ my ($self, $cb, @arg) = @_;
my $cfg = $self->_lei_cfg(0);
- my $out = $self->{1};
- my ($OFS, $ORS) = $self->{opt}->{z} ? ("\0", "\0\0") : (" ", "\n");
- my (%boost, @loc);
+ my %boost;
for my $sec (grep(/\Aexternal\./, @{$cfg->{-section_order}})) {
my $loc = substr($sec, length('external.'));
$boost{$loc} = $cfg->{"$sec.boost"};
- push @loc, $loc;
}
- use sort 'stable';
+ return \%boost if !wantarray && !$cb;
+
# highest boost first, but stable for alphabetic tie break
- for (sort { $boost{$b} <=> $boost{$a} } sort keys %boost) {
- # TODO: use miscidx and show docid so forget/set is easier
- print $out $_, $OFS, 'boost=', $boost{$_}, $ORS;
+ use sort 'stable';
+ my @order = sort { $boost{$b} <=> $boost{$a} } sort keys %boost;
+ return @order if !$cb;
+ for my $loc (@order) {
+ $cb->(@arg, $loc, $boost{$loc});
}
+ @order; # scalar or array
+}
+
+sub lei_ls_external {
+ my ($self, @argv) = @_;
+ my $stor = $self->_lei_store(0);
+ my $out = $self->{1};
+ my ($OFS, $ORS) = $self->{opt}->{z} ? ("\0", "\0\0") : (" ", "\n");
+ $self->_externals_each(sub {
+ my ($loc, $boost_val) = @_;
+ print $out $loc, $OFS, 'boost=', $boost_val, $ORS;
+ });
}
sub lei_add_external {
diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm
index 07a3198a..a7267a64 100644
--- a/lib/PublicInbox/LeiStore.pm
+++ b/lib/PublicInbox/LeiStore.pm
@@ -24,7 +24,7 @@ sub new {
my (undef, $dir, $opt) = @_;
my $eidx = PublicInbox::ExtSearchIdx->new($dir, $opt);
my $self = bless { priv_eidx => $eidx }, __PACKAGE__;
- eidx_init($self) if $opt->{creat};
+ eidx_init($self)->done if $opt->{creat};
$self;
}
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index 33e9c413..68be0c97 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -20,6 +20,21 @@ sub new {
sub attach_external {
my ($self, $ibxish) = @_; # ibxish = ExtSearch or Inbox
+ if (!ref($ibxish) && -d $ibxish) {
+ if (-f "$ibxish/ei.lock") {
+ require PublicInbox::ExtSearch;
+ $ibxish = PublicInbox::ExtSearch->new($ibxish);
+ } elsif (-f "$ibxish/inbox.lock" || # v2
+ -f "$ibxish/public-inbox") { # v1 indexed
+ require PublicInbox::Inbox;
+ $ibxish = bless { inboxdir => $ibxish },
+ 'PublicInbox::Inbox';
+ } else {
+ warn "W: ignoring $ibxish, unable to determine type\n";
+ return;
+ }
+ }
+
if (!$ibxish->can('over')) {
push @{$self->{remotes}}, $ibxish
}
@@ -44,6 +59,7 @@ sub attach_external {
my @shards = $ibxish->search->xdb_shards_flat;
push @{$self->{shards_flat}}, @shards;
push(@{$self->{shard2ibx}}, $ibxish) for (@shards);
+ $ibxish;
}
# called by PublicInbox::Search::xdb
diff --git a/t/lei.t b/t/lei.t
index 41638950..befbe723 100644
--- a/t/lei.t
+++ b/t/lei.t
@@ -177,12 +177,18 @@ my $test_external = sub {
});
$lei->('ls-external');
like($out, qr/boost=0\n/s, 'ls-external has output');
+ diag 'ls-external '.$out;
+
+ $lei->('q', 's:"use boolean prefix"', '-o', "mboxrd:$home/rd.mbox",
+ '--external');
+ diag $out;
+ diag $err;
};
my $test_lei_common = sub {
- $test_help->();
- $test_config->();
- $test_init->();
+ # $test_help->();
+ # $test_config->();
+ # $test_init->();
$test_external->();
};
next reply other threads:[~2021-01-03 22:57 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-03 22:57 Eric Wong [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-10-27 20:16 [PATCH] wip Eric Wong
2021-06-05 19:58 Eric Wong
2021-04-05 7:42 Eric Wong
2021-03-08 7:11 Eric Wong
2021-01-21 4:24 [PATCH] WIP Eric Wong
2020-12-27 11:36 Eric Wong
2020-11-15 7:35 [PATCH] wip Eric Wong
2020-04-23 4:27 Eric Wong
2020-04-20 7:14 Eric Wong
2020-01-13 9:24 [PATCH] WIP Eric Wong
2019-05-11 22:55 Eric Wong
2019-01-02 9:21 [PATCH] wip Eric Wong
2018-07-06 21:31 Eric Wong
2018-06-24 11:55 Eric Wong
2018-06-24 8:39 Eric Wong
2017-07-15 1:42 [PATCH] WIP Eric Wong
2017-04-12 20:17 [PATCH] wip Eric Wong
2017-04-05 18:40 Eric Wong
2016-08-23 20:07 Eric Wong
2016-08-18 2:16 Eric Wong
2016-06-26 3:46 Eric Wong
2015-12-22 0:15 Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210103225756.30660-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).