]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiSearch.pm
update copyrights for 2021
[public-inbox.git] / lib / PublicInbox / LeiSearch.pm
1 # Copyright (C) 2020-2021 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 # get combined docid from over.num:
11 # (not generic Xapian, only works with our sharding scheme)
12 sub num2docid ($$) {
13         my ($self, $num) = @_;
14         my $nshard = $self->{nshard};
15         ($num - 1) * $nshard + $num % $nshard + 1;
16 }
17
18 sub msg_keywords {
19         my ($self, $num) = @_; # num_or_mitem
20         my $xdb = $self->xdb; # set {nshard};
21         my $docid = ref($num) ? $num->get_docid : num2docid($self, $num);
22         my %kw;
23         eval {
24                 my $end = $xdb->termlist_end($docid);
25                 my $cur = $xdb->termlist_begin($docid);
26                 for (; $cur != $end; $cur++) {
27                         $cur->skip_to('K');
28                         last if $cur == $end;
29                         my $kw = $cur->get_termname;
30                         $kw =~ s/\AK//s and $kw{$kw} = undef;
31                 }
32         };
33         warn "E: #$docid ($num): $@\n" if $@;
34         wantarray ? sort(keys(%kw)) : \%kw;
35 }
36
37 1;