diff options
author | Eric Wong <e@80x24.org> | 2020-12-31 13:51:35 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-01 05:00:39 +0000 |
commit | 0d649fc15eab07976344a6ae32a946b2b1c32f4f (patch) | |
tree | 52e6637f5395ad65af8733d869d6fef5111f2ee5 /lib/PublicInbox/LeiExternal.pm | |
parent | 73b40ff62a7ab305443a9fb81b16d2b10b15bf60 (diff) | |
download | public-inbox-0d649fc15eab07976344a6ae32a946b2b1c32f4f.tar.gz |
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/
Diffstat (limited to 'lib/PublicInbox/LeiExternal.pm')
-rw-r--r-- | lib/PublicInbox/LeiExternal.pm | 51 |
1 files changed, 51 insertions, 0 deletions
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 <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> + +# *-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; |