diff options
author | Eric Wong <e@80x24.org> | 2020-12-14 11:42:40 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2020-12-19 09:32:08 +0000 |
commit | 6cdb84af2c75b3c66a35c8c4973f455da15dd0a4 (patch) | |
tree | 3069edc4159050252f1a6d15295b01a566f367d2 /lib/PublicInbox/LeiSearch.pm | |
parent | 478a8d308d952af5ae957136c2ab09455f2a767c (diff) | |
download | public-inbox-6cdb84af2c75b3c66a35c8c4973f455da15dd0a4.tar.gz |
Still unstable, this builds off the equally unstable extindex :P This will be used for caching/memoization of traditional mail stores (IMAP, Maildir, etc) while providing indexing via Xapian, along with compression, and checksumming from git. Most notably, this adds the ability to add/remove per-message keywords (draft, seen, flagged, answered) as described in the JMAP specification (RFC 8621 section 4.1.1). We'll use `.' (a single period) as an $eidx_key since it's an invalid {inboxdir} or {newsgroup} name.
Diffstat (limited to 'lib/PublicInbox/LeiSearch.pm')
-rw-r--r-- | lib/PublicInbox/LeiSearch.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/PublicInbox/LeiSearch.pm b/lib/PublicInbox/LeiSearch.pm new file mode 100644 index 00000000..9cfd6ea2 --- /dev/null +++ b/lib/PublicInbox/LeiSearch.pm @@ -0,0 +1,40 @@ +# 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; + +sub combined_docid ($$) { + my ($self, $num) = @_; + my $nshard = ($self->{nshard} // 1); + ($num - 1) * $nshard + 1; +} + +sub msg_keywords { + my ($self, $num) = @_; # num_or_mitem + my $xdb = $self->xdb; # set {nshard}; + my $docid = ref($num) ? $num->get_docid : do { + # get combined docid from over.num: + # (not generic Xapian, only works with our sharding scheme) + my $nshard = $self->{nshard} // 1; + ($num - 1) * $nshard + $num % $nshard + 1; + }; + 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; |