diff options
author | Eric Wong <e@80x24.org> | 2021-01-21 19:46:14 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-22 16:18:01 -0400 |
commit | bf77d62faa571cdaf279df421aae85d2b447ceeb (patch) | |
tree | 9a342476340dcc9763443ceb8eb8b6010e6a584e /lib/PublicInbox/Search.pm | |
parent | 7e947c849e3ceeb89c3d27952abdb10f9252c038 (diff) | |
download | public-inbox-bf77d62faa571cdaf279df421aae85d2b447ceeb.tar.gz |
This isn't tested for now, so maybe it works.
Diffstat (limited to 'lib/PublicInbox/Search.pm')
-rw-r--r-- | lib/PublicInbox/Search.pm | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index a4b40f94..7c6a16be 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -6,7 +6,7 @@ package PublicInbox::Search; use strict; use parent qw(Exporter); -our @EXPORT_OK = qw(retry_reopen int_val get_pct); +our @EXPORT_OK = qw(retry_reopen int_val get_pct xap_terms); use List::Util qw(max); # values for searching, changing the numeric value breaks @@ -432,4 +432,22 @@ sub get_pct ($) { # mset item $n > 99 ? 99 : $n; } +sub xap_terms ($$;@) { + my ($pfx, $xdb_or_doc, @docid) = @_; # @docid may be empty () + my %ret; + eval { + my $end = $xdb_or_doc->termlist_end(@docid); + my $cur = $xdb_or_doc->termlist_begin(@docid); + for (; $cur != $end; $cur++) { + $cur->skip_to($pfx); + last if $cur == $end; + my $tn = $cur->get_termname; + if (index($tn, $pfx) == 0) { + $ret{substr($tn, length($pfx))} = undef; + } + } + }; + \%ret; +} + 1; |