From: Eric Wong Date: Thu, 31 Dec 2020 13:24:36 +0000 (+0000) Subject: Merge remote-tracking branch 'origin/master' into lorelei X-Git-Tag: v1.7.0~1471^2 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=0c8106d44f317175e122744b43407bf067183175 Merge remote-tracking branch 'origin/master' into lorelei * origin/master: (58 commits) ds: flatten + reuse @events, epoll_wait style fixes ds: simplify EventLoop implementation check defined return value for localized slurp errors import: check for git->qx errors, clearer return values git: qx: avoid extra "local" for scalar context case search: remove {mset} option for ->mset method search: remove pointless {relevance} setting miscsearch: take reopen from Search and use it extsearch: unconditionally reopen on access extindex: allow using --all without EXTINDEX_DIR extindex: add undocumented --no-scan switch extindex: enable autoflush on STDOUT/STDERR extindex: various --watch signal handling fixes extindex: --watch for inotify-based updates eml: fix undefined vars on canonpath($topdir); bless { topdir => $topdir, # xpfx => 'ei15' @@@ -31,8 -29,12 +29,6 @@@ sub misc $self->{misc} //= PublicInbox::MiscSearch->new("$self->{xpfx}/misc"); } - sub search { $_[0] } # self -# overrides PublicInbox::Search::_xdb -sub _xdb { - my ($self) = @_; - $self->xdb_sharded; -} -- # same as per-inbox ->over, for now... sub over { my ($self) = @_; diff --cc lib/PublicInbox/SearchIdx.pm index 7e2843e9,b3361e05..95f4234c --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@@ -498,52 -499,6 +496,47 @@@ sub remove_eidx_info $self->{xdb}->replace_document($docid, $doc); } +sub set_keywords { + my ($self, $docid, @kw) = @_; + begin_txn_lazy($self); + my $doc = _get_doc($self, $docid) or return; + my %keep = map { $_ => 1 } @kw; + my %add = %keep; + my @rm; + my $end = $doc->termlist_end; + for (my $cur = $doc->termlist_begin; $cur != $end; $cur++) { + $cur->skip_to('K'); + last if $cur == $end; + my $kw = $cur->get_termname; + $kw =~ s/\AK//s or next; + $keep{$kw} ? delete($add{$kw}) : push(@rm, $kw); + } + return unless (scalar(@rm) + scalar(keys %add)); + $doc->remove_term('K'.$_) for @rm; + $doc->add_boolean_term('K'.$_) for (keys %add); + $self->{xdb}->replace_document($docid, $doc); +} + +sub add_keywords { + my ($self, $docid, @kw) = @_; + begin_txn_lazy($self); + my $doc = _get_doc($self, $docid) or return; + $doc->add_boolean_term('K'.$_) for @kw; + $self->{xdb}->replace_document($docid, $doc); +} + +sub remove_keywords { + my ($self, $docid, @kw) = @_; + begin_txn_lazy($self); + my $doc = _get_doc($self, $docid) or return; + my $replace; + eval { + $doc->remove_term('K'.$_); + $replace = 1 + } for @kw; + $self->{xdb}->replace_document($docid, $doc) if $replace; +} + - sub get_val ($$) { - my ($doc, $col) = @_; - sortable_unserialise($doc->get_value($col)); - } - sub smsg_from_doc ($) { my ($doc) = @_; my $data = $doc->get_data or return;