about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiSearch.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox/LeiSearch.pm')
-rw-r--r--lib/PublicInbox/LeiSearch.pm37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/PublicInbox/LeiSearch.pm b/lib/PublicInbox/LeiSearch.pm
new file mode 100644
index 00000000..0b962b11
--- /dev/null
+++ b/lib/PublicInbox/LeiSearch.pm
@@ -0,0 +1,37 @@
+# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+package PublicInbox::LeiSearch;
+use strict;
+use v5.10.1;
+use parent qw(PublicInbox::ExtSearch);
+use PublicInbox::Search;
+
+# get combined docid from over.num:
+# (not generic Xapian, only works with our sharding scheme)
+sub num2docid ($$) {
+        my ($self, $num) = @_;
+        my $nshard = $self->{nshard};
+        ($num - 1) * $nshard + $num % $nshard + 1;
+}
+
+sub msg_keywords {
+        my ($self, $num) = @_; # num_or_mitem
+        my $xdb = $self->xdb; # set {nshard};
+        my $docid = ref($num) ? $num->get_docid : num2docid($self, $num);
+        my %kw;
+        eval {
+                my $end = $xdb->termlist_end($docid);
+                my $cur = $xdb->termlist_begin($docid);
+                for (; $cur != $end; $cur++) {
+                        $cur->skip_to('K');
+                        last if $cur == $end;
+                        my $kw = $cur->get_termname;
+                        $kw =~ s/\AK//s and $kw{$kw} = undef;
+                }
+        };
+        warn "E: #$docid ($num): $@\n" if $@;
+        wantarray ? sort(keys(%kw)) : \%kw;
+}
+
+1;