From 0d649fc15eab07976344a6ae32a946b2b1c32f4f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 31 Dec 2020 13:51:35 +0000 Subject: lei: rename "extinbox" => "external" The words "extinbox" and "extindex" are too close and easy to confuse with the other. Rename "extinbox" to "external", since these could be IMAP, JMAP or other non-public-inbox search APIs. Link: https://public-inbox.org/meta/20201226112649.GB6226@dcvr/ --- lib/PublicInbox/LEI.pm | 12 +++++----- lib/PublicInbox/LeiExternal.pm | 51 ++++++++++++++++++++++++++++++++++++++++++ lib/PublicInbox/LeiExtinbox.pm | 51 ------------------------------------------ lib/PublicInbox/LeiXSearch.pm | 2 +- 4 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 lib/PublicInbox/LeiExternal.pm delete mode 100644 lib/PublicInbox/LeiExtinbox.pm (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 9aa4d95a..f960aa72 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -8,7 +8,7 @@ package PublicInbox::LEI; use strict; use v5.10.1; -use parent qw(PublicInbox::DS PublicInbox::LeiExtinbox); +use parent qw(PublicInbox::DS PublicInbox::LeiExternal); use Getopt::Long (); use Socket qw(AF_UNIX SOCK_STREAM pack_sockaddr_un); use Errno qw(EAGAIN ECONNREFUSED ENOENT); @@ -70,19 +70,19 @@ sub _config_path ($) { our %CMD = ( # sorted in order of importance/use: 'q' => [ 'SEARCH_TERMS...', 'search for messages matching terms', qw( save-as=s output|o=s format|f=s dedupe|d=s thread|t augment|a - sort|s=s@ reverse|r offset=i remote local! extinbox! + sort|s=s@ reverse|r offset=i remote local! external! since|after=s until|before=s), opt_dash('limit|n=i', '[0-9]+') ], 'show' => [ 'MID|OID', 'show a given object (Message-ID or object ID)', qw(type=s solve! format|f=s dedupe|d=s thread|t remote local!), pass_through('git show') ], -'add-extinbox' => [ 'URL_OR_PATHNAME', +'add-external' => [ 'URL_OR_PATHNAME', 'add/set priority of a publicinbox|extindex for extra matches', qw(boost=i quiet|q) ], -'ls-extinbox' => [ '[FILTER...]', 'list publicinbox|extindex locations', +'ls-external' => [ '[FILTER...]', 'list publicinbox|extindex locations', qw(format|f=s z|0 local remote quiet|q) ], -'forget-extinbox' => [ '{URL_OR_PATHNAME|--prune}', +'forget-external' => [ '{URL_OR_PATHNAME|--prune}', 'exclude further results from a publicinbox|extindex', qw(prune quiet|q) ], @@ -189,7 +189,7 @@ my %OPTDESC = ( 'q format|f=s' => [ 'OUT|maildir|mboxrd|mboxcl2|mboxcl|html|oid|json', 'specify output format, default depends on --output'], 'ls-query format|f=s' => $ls_format, -'ls-extinbox format|f=s' => $ls_format, +'ls-external format|f=s' => $ls_format, 'limit|n=i@' => ['NUM', 'limit on number of matches (default: 10000)' ], 'offset=i' => ['OFF', 'search result offset (default: 0)'], diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm new file mode 100644 index 00000000..0378551a --- /dev/null +++ b/lib/PublicInbox/LeiExternal.pm @@ -0,0 +1,51 @@ +# Copyright (C) 2020 all contributors +# License: AGPL-3.0+ + +# *-external commands of lei +package PublicInbox::LeiExternal; +use strict; +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); + my $cfg = $self->_lei_cfg(0); + my $out = $self->{1}; + my ($OFS, $ORS) = $self->{opt}->{z} ? ("\0", "\0\0") : (" ", "\n"); + my (%boost, @loc); + 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'; + # 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; + } +} + +sub lei_add_external { + my ($self, $url_or_dir) = @_; + my $cfg = $self->_lei_cfg(1); + if ($url_or_dir !~ m!\Ahttps?://!) { + $url_or_dir = File::Spec->canonpath($url_or_dir); + } + my $new_boost = $self->{opt}->{boost} // 0; + my $key = "external.$url_or_dir.boost"; + my $cur_boost = $cfg->{$key}; + return if defined($cur_boost) && $cur_boost == $new_boost; # idempotent + $self->lei_config($key, $new_boost); + my $stor = $self->_lei_store(1); + # TODO: add to MiscIdx + $stor->done; +} + +sub lei_forget_external { + # TODO +} + +1; diff --git a/lib/PublicInbox/LeiExtinbox.pm b/lib/PublicInbox/LeiExtinbox.pm deleted file mode 100644 index c2de7735..00000000 --- a/lib/PublicInbox/LeiExtinbox.pm +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright (C) 2020 all contributors -# License: AGPL-3.0+ - -# *-extinbox commands of lei -package PublicInbox::LeiExtinbox; -use strict; -use v5.10.1; -use parent qw(Exporter); -our @EXPORT = qw(lei_ls_extinbox lei_add_extinbox lei_forget_extinbox); - -sub lei_ls_extinbox { - my ($self, @argv) = @_; - my $stor = $self->_lei_store(0); - my $cfg = $self->_lei_cfg(0); - my $out = $self->{1}; - my ($OFS, $ORS) = $self->{opt}->{z} ? ("\0", "\0\0") : (" ", "\n"); - my (%boost, @loc); - for my $sec (grep(/\Aextinbox\./, @{$cfg->{-section_order}})) { - my $loc = substr($sec, length('extinbox.')); - $boost{$loc} = $cfg->{"$sec.boost"}; - push @loc, $loc; - } - use sort 'stable'; - # 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; - } -} - -sub lei_add_extinbox { - my ($self, $url_or_dir) = @_; - my $cfg = $self->_lei_cfg(1); - if ($url_or_dir !~ m!\Ahttps?://!) { - $url_or_dir = File::Spec->canonpath($url_or_dir); - } - my $new_boost = $self->{opt}->{boost} // 0; - my $key = "extinbox.$url_or_dir.boost"; - my $cur_boost = $cfg->{$key}; - return if defined($cur_boost) && $cur_boost == $new_boost; # idempotent - $self->lei_config($key, $new_boost); - my $stor = $self->_lei_store(1); - # TODO: add to MiscIdx - $stor->done; -} - -sub lei_forget_extinbox { - # TODO -} - -1; diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index 1a81b14a..7d251afd 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -18,7 +18,7 @@ sub new { }, $class } -sub attach_extinbox { +sub attach_external { my ($self, $ibxish) = @_; # ibxish = ExtSearch or Inbox if (!$ibxish->can('over')) { push @{$self->{remotes}}, $ibxish -- cgit v1.2.3-24-ge0c7