From d3c2bfcdf1069a8c45a38ddb7c07cfcac16db2ea Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Wed, 20 Sep 2023 16:17:15 +0200 Subject: Posting list search contexts: Rename useThis() to use_dictionary_entry() and step iterator one or more steps when not using dictionary entry. --- .../searchlib/attribute/postinglistsearchcontext.h | 34 ++++++++++++++++------ .../attribute/postinglistsearchcontext.hpp | 15 ++++++---- 2 files changed, 34 insertions(+), 15 deletions(-) (limited to 'searchlib') diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h index 107abd24069..05ccedb39ec 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h +++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h @@ -57,7 +57,7 @@ protected: void lookupTerm(const vespalib::datastore::EntryComparator &comp); void lookupRange(const vespalib::datastore::EntryComparator &low, const vespalib::datastore::EntryComparator &high); void lookupSingle(); - virtual bool useThis(const DictionaryConstIterator & it) const { + virtual bool use_dictionary_entry(DictionaryConstIterator& it) const { (void) it; return true; } @@ -182,7 +182,12 @@ private: using Parent = PostingSearchContext, AttrT>; using RegexpUtil = vespalib::RegexpUtil; using Parent::_enumStore; - bool useThis(const PostingListSearchContext::DictionaryConstIterator & it) const override; + // Note: steps iterator one ore more steps when not using dictionary entry + bool use_dictionary_entry(PostingListSearchContext::DictionaryConstIterator& it) const override; + // Note: Uses copy of dictionary iterator to avoid stepping original. + bool use_single_dictionary_entry(PostingListSearchContext::DictionaryConstIterator it) const { + return use_dictionary_entry(it); + } public: StringPostingSearchContext(BaseSC&& base_sc, bool useBitVector, const AttrT &toBeSearched); }; @@ -289,7 +294,7 @@ StringPostingSearchContext(BaseSC&& base_sc, bool useBitVector, const AttrT &toB * A single dictionary entry from lookupRange() might not be * a match if this is a regex search or a fuzzy search. */ - if (!this->_lowerDictItr.valid() || useThis(this->_lowerDictItr)) { + if (!this->_lowerDictItr.valid() || use_single_dictionary_entry(this->_lowerDictItr)) { this->lookupSingle(); } else { this->_uniqueValues = 0; @@ -300,15 +305,26 @@ StringPostingSearchContext(BaseSC&& base_sc, bool useBitVector, const AttrT &toB template bool -StringPostingSearchContext::useThis(const PostingListSearchContext::DictionaryConstIterator & it) const { +StringPostingSearchContext::use_dictionary_entry(PostingListSearchContext::DictionaryConstIterator& it) const { if ( this->isRegex() ) { - return this->getRegex().valid() - ? this->getRegex().partial_match(_enumStore.get_value(it.getKey().load_acquire())) - : false; + if (this->getRegex().valid() && + this->getRegex().partial_match(_enumStore.get_value(it.getKey().load_acquire()))) { + return true; + } + ++it; + return false; } else if ( this->isCased() ) { - return this->match(_enumStore.get_value(it.getKey().load_acquire())); + if (this->match(_enumStore.get_value(it.getKey().load_acquire()))) { + return true; + } + ++it; + return false; } else if (this->isFuzzy()) { - return this->getFuzzyMatcher().isMatch(_enumStore.get_value(it.getKey().load_acquire())); + if (this->getFuzzyMatcher().isMatch(_enumStore.get_value(it.getKey().load_acquire()))) { + return true; + } + ++it; + return false; } return true; } diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp index 725491c4702..bd1cc1191a7 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp +++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp @@ -64,9 +64,10 @@ size_t PostingListSearchContextT::countHits() const { size_t sum(0); - for (auto it(_lowerDictItr); it != _upperDictItr; ++it) { - if (useThis(it)) { + for (auto it(_lowerDictItr); it != _upperDictItr;) { + if (use_dictionary_entry(it)) { sum += _postingList.frozenSize(it.getData().load_acquire()); + ++it; } } return sum; @@ -77,10 +78,11 @@ template void PostingListSearchContextT::fillArray() { - for (auto it(_lowerDictItr); it != _upperDictItr; ++it) { - if (useThis(it)) { + for (auto it(_lowerDictItr); it != _upperDictItr;) { + if (use_dictionary_entry(it)) { _merger.addToArray(PostingListTraverser(_postingList, it.getData().load_acquire())); + ++it; } } _merger.merge(); @@ -91,10 +93,11 @@ template void PostingListSearchContextT::fillBitVector() { - for (auto it(_lowerDictItr); it != _upperDictItr; ++it) { - if (useThis(it)) { + for (auto it(_lowerDictItr); it != _upperDictItr;) { + if (use_dictionary_entry(it)) { _merger.addToBitVector(PostingListTraverser(_postingList, it.getData().load_acquire())); + ++it; } } } -- cgit v1.2.3