]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
lei mark: command for (un)setting keywords and labels
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index 3f9331211ad8e5388ab175979d4b2ec3eaa12368..7d46489c00202d19cde1d203e18c5c34f26559b6 100644 (file)
@@ -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;