diff options
author | Eric Wong <e@80x24.org> | 2021-01-10 12:14:58 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-12 03:51:42 +0000 |
commit | 4ff570e5c3cfb33aff3ca6ad674958d9dd2abda9 (patch) | |
tree | 66299a7b22bc523d230ca93f51b0eae3abca4c59 /lib/PublicInbox/LeiExternal.pm | |
parent | 392533147f50061d93cb9ed82abf98067dde5472 (diff) | |
download | public-inbox-4ff570e5c3cfb33aff3ca6ad674958d9dd2abda9.tar.gz |
Parallelism and interactivity with pager + SIGPIPE needs work; but results are shown and phrase search works without shell users having to apply Xapian quoting rules on top of standard shell quoting.
Diffstat (limited to 'lib/PublicInbox/LeiExternal.pm')
-rw-r--r-- | lib/PublicInbox/LeiExternal.pm | 33 |
1 files changed, 22 insertions, 11 deletions
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 { |