From 5be0cb101bab44167a78af7a2d167f254c95bdb3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 23 Mar 2021 11:02:17 +0600 Subject: lei mark: command for (un)setting keywords and labels 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. --- lib/PublicInbox/SearchIdx.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib/PublicInbox/SearchIdx.pm') 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; -- cgit v1.2.3-24-ge0c7