]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiSearch.pm
lei_store: local storage for Local Email Interface
[public-inbox.git] / lib / PublicInbox / LeiSearch.pm
1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 package PublicInbox::LeiSearch;
5 use strict;
6 use v5.10.1;
7 use parent qw(PublicInbox::ExtSearch);
8 use PublicInbox::Search;
9
10 sub combined_docid ($$) {
11         my ($self, $num) = @_;
12         my $nshard = ($self->{nshard} // 1);
13         ($num - 1) * $nshard  + 1;
14 }
15
16 sub msg_keywords {
17         my ($self, $num) = @_; # num_or_mitem
18         my $xdb = $self->xdb; # set {nshard};
19         my $docid = ref($num) ? $num->get_docid : do {
20                 # get combined docid from over.num:
21                 # (not generic Xapian, only works with our sharding scheme)
22                 my $nshard = $self->{nshard} // 1;
23                 ($num - 1) * $nshard + $num % $nshard + 1;
24         };
25         my %kw;
26         eval {
27                 my $end = $xdb->termlist_end($docid);
28                 my $cur = $xdb->termlist_begin($docid);
29                 for (; $cur != $end; $cur++) {
30                         $cur->skip_to('K');
31                         last if $cur == $end;
32                         my $kw = $cur->get_termname;
33                         $kw =~ s/\AK//s and $kw{$kw} = undef;
34                 }
35         };
36         warn "E: #$docid ($num): $@\n" if $@;
37         wantarray ? sort(keys(%kw)) : \%kw;
38 }
39
40 1;