diff options
author | Eric Wong <e@80x24.org> | 2021-03-23 11:02:17 +0600 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-03-24 01:33:26 +0000 |
commit | 5be0cb101bab44167a78af7a2d167f254c95bdb3 (patch) | |
tree | 133ed291d5caca9819d95217b0b512990257d225 /lib/PublicInbox/SearchIdx.pm | |
parent | e7d13d7bc4a7b1e990602e796b7c2acbddb99a7b (diff) | |
download | public-inbox-5be0cb101bab44167a78af7a2d167f254c95bdb3.tar.gz |
Only tested for keywords and labels with file inputs, so far; but it seems to do what it needs to do. There's a bit more redundant code than I'd like, and more opportunities for code sharing in the future "lei import" will be expanded to support +kw:$KEYWORD and +L:$LABEL in the future.
Diffstat (limited to 'lib/PublicInbox/SearchIdx.pm')
-rw-r--r-- | lib/PublicInbox/SearchIdx.pm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 3f933121..7d46489c 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -597,6 +597,29 @@ sub remove_vmd { $self->{xdb}->replace_document($docid, $doc) if $replace; } +sub update_vmd { + my ($self, $docid, $vmd_mod) = @_; + begin_txn_lazy($self); + my $doc = _get_doc($self, $docid) or return; + my $updated = 0; + my @x = @VMD_MAP; + while (my ($field, $pfx) = splice(@x, 0, 2)) { + # field: "label" or "kw" + for my $val (@{$vmd_mod->{"-$field"} // []}) { + eval { + $doc->remove_term($pfx . $val); + ++$updated; + }; + } + for my $val (@{$vmd_mod->{"+$field"} // []}) { + $doc->add_boolean_term($pfx . $val); + ++$updated; + } + } + $self->{xdb}->replace_document($docid, $doc) if $updated; + $updated; +} + sub xdb_remove { my ($self, @docids) = @_; $self->begin_txn_lazy; |