From 82efe24f7af8ee3c51195bcd46ce6d407ded4d1f Mon Sep 17 00:00:00 2001 From: Geir Storli Date: Tue, 12 Dec 2023 16:18:09 +0000 Subject: Prepare for direct posting store integration for single value attributes. --- .../attribute/direct_posting_store_adapter.h | 44 +++++++++++ .../attribute/direct_posting_store_adapter.hpp | 74 ++++++++++++++++++ .../attribute/i_docid_with_weight_posting_store.h | 4 + .../attribute/multinumericpostattribute.h | 24 ++---- .../attribute/multinumericpostattribute.hpp | 85 +-------------------- .../searchlib/attribute/multistringpostattribute.h | 30 +++----- .../attribute/multistringpostattribute.hpp | 87 +--------------------- .../numeric_direct_posting_store_adapter.h | 31 ++++++++ .../numeric_direct_posting_store_adapter.hpp | 58 +++++++++++++++ .../string_direct_posting_store_adapter.h | 31 ++++++++ .../string_direct_posting_store_adapter.hpp | 58 +++++++++++++++ 11 files changed, 318 insertions(+), 208 deletions(-) create mode 100644 searchlib/src/vespa/searchlib/attribute/direct_posting_store_adapter.h create mode 100644 searchlib/src/vespa/searchlib/attribute/direct_posting_store_adapter.hpp create mode 100644 searchlib/src/vespa/searchlib/attribute/numeric_direct_posting_store_adapter.h create mode 100644 searchlib/src/vespa/searchlib/attribute/numeric_direct_posting_store_adapter.hpp create mode 100644 searchlib/src/vespa/searchlib/attribute/string_direct_posting_store_adapter.h create mode 100644 searchlib/src/vespa/searchlib/attribute/string_direct_posting_store_adapter.hpp (limited to 'searchlib') diff --git a/searchlib/src/vespa/searchlib/attribute/direct_posting_store_adapter.h b/searchlib/src/vespa/searchlib/attribute/direct_posting_store_adapter.h new file mode 100644 index 00000000000..125c265afcf --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/direct_posting_store_adapter.h @@ -0,0 +1,44 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "i_direct_posting_store.h" +#include +#include + +namespace search { class IEnumStoreDictionary; } + +namespace search::attribute { + +/** + * Base adapter class used to implement a specific IDirectPostingStore interface for + * an attribute vector with underlying posting lists (fast-search). + */ +template +class DirectPostingStoreAdapter : public ParentType { +protected: + const PostingStoreType& _posting_store; + const EnumStoreType& _enum_store; + const IEnumStoreDictionary& _dict; + bool _attr_is_filter; + +public: + using IteratorType = typename ParentType::IteratorType; + + DirectPostingStoreAdapter(const PostingStoreType& posting_store, + const EnumStoreType& enum_store, + bool attr_is_filter); + + vespalib::datastore::EntryRef get_dictionary_snapshot() const override; + bool has_weight_iterator(vespalib::datastore::EntryRef posting_idx) const noexcept override; + std::unique_ptr make_bitvector_iterator(vespalib::datastore::EntryRef posting_idx, uint32_t doc_id_limit, + fef::TermFieldMatchData& match_data, bool strict) const override; + bool has_bitvector(vespalib::datastore::EntryRef posting_idx) const noexcept override; + int64_t get_integer_value(vespalib::datastore::EntryRef enum_idx) const noexcept override; + + void create(vespalib::datastore::EntryRef idx, std::vector& dst) const override; + IteratorType create(vespalib::datastore::EntryRef idx) const override; + bool has_always_weight_iterator() const noexcept override { return !_attr_is_filter; } +}; + +} diff --git a/searchlib/src/vespa/searchlib/attribute/direct_posting_store_adapter.hpp b/searchlib/src/vespa/searchlib/attribute/direct_posting_store_adapter.hpp new file mode 100644 index 00000000000..02fc1a84ec6 --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/direct_posting_store_adapter.hpp @@ -0,0 +1,74 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "i_enum_store_dictionary.h" +#include "direct_posting_store_adapter.h" +#include + +namespace search::attribute { + +template +DirectPostingStoreAdapter:: +DirectPostingStoreAdapter(const PostingStoreType& posting_store, + const EnumStoreType& enum_store, + bool attr_is_filter) + : _posting_store(posting_store), + _enum_store(enum_store), + _dict(enum_store.get_dictionary()), + _attr_is_filter(attr_is_filter) +{ +} + +template +vespalib::datastore::EntryRef +DirectPostingStoreAdapter:: +get_dictionary_snapshot() const +{ + return _dict.get_frozen_root(); +} + +template +std::unique_ptr +DirectPostingStoreAdapter:: +make_bitvector_iterator(vespalib::datastore::EntryRef posting_idx, uint32_t doc_id_limit, + fef::TermFieldMatchData& match_data, bool strict) const +{ + return _posting_store.make_bitvector_iterator(posting_idx, doc_id_limit, match_data, strict); +} + +template +bool +DirectPostingStoreAdapter:: +has_weight_iterator(vespalib::datastore::EntryRef posting_idx) const noexcept +{ + return _posting_store.has_btree(posting_idx); +} + +template +bool +DirectPostingStoreAdapter:: +has_bitvector(vespalib::datastore::EntryRef posting_idx) const noexcept +{ + return _posting_store.has_bitvector(posting_idx); +} + +template +void +DirectPostingStoreAdapter:: +create(vespalib::datastore::EntryRef posting_idx, std::vector& dst) const +{ + assert(posting_idx.valid()); + _posting_store.beginFrozen(posting_idx, dst); +} + +template +DirectPostingStoreAdapter::IteratorType +DirectPostingStoreAdapter:: +create(vespalib::datastore::EntryRef posting_idx) const +{ + assert(posting_idx.valid()); + return _posting_store.beginFrozen(posting_idx); +} + +} diff --git a/searchlib/src/vespa/searchlib/attribute/i_docid_with_weight_posting_store.h b/searchlib/src/vespa/searchlib/attribute/i_docid_with_weight_posting_store.h index 1907279b39d..bdb4054b2d7 100644 --- a/searchlib/src/vespa/searchlib/attribute/i_docid_with_weight_posting_store.h +++ b/searchlib/src/vespa/searchlib/attribute/i_docid_with_weight_posting_store.h @@ -13,6 +13,8 @@ namespace search { */ class IDocidWithWeightPostingStore : public IDirectPostingStore { public: + using IteratorType = DocidWithWeightIterator; + virtual void create(vespalib::datastore::EntryRef idx, std::vector &dst) const = 0; virtual DocidWithWeightIterator create(vespalib::datastore::EntryRef idx) const = 0; @@ -24,5 +26,7 @@ public: virtual bool has_always_weight_iterator() const noexcept = 0; }; + + } diff --git a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.h b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.h index 38cf12ca909..3e7ff01d484 100644 --- a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.h +++ b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.h @@ -2,6 +2,7 @@ #pragma once +#include "numeric_direct_posting_store_adapter.h" #include "multinumericenumattribute.h" #include "postinglistattribute.h" #include "i_docid_with_weight_posting_store.h" @@ -32,25 +33,6 @@ public: using EnumStoreBatchUpdater = typename EnumStore::BatchUpdater; private: - class DocidWithWeightPostingStoreAdapter final : public IDocidWithWeightPostingStore { - public: - const MultiValueNumericPostingAttribute &self; - bool _is_filter; - DocidWithWeightPostingStoreAdapter(const MultiValueNumericPostingAttribute &self_in) - : self(self_in), _is_filter(self_in.getIsFilter()) {} - vespalib::datastore::EntryRef get_dictionary_snapshot() const override; - LookupResult lookup(const LookupKey & key, vespalib::datastore::EntryRef dictionary_snapshot) const override; - void collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, const std::function& callback) const override; - void create(vespalib::datastore::EntryRef posting_idx, std::vector &dst) const override; - DocidWithWeightIterator create(vespalib::datastore::EntryRef posting_idx) const override; - std::unique_ptr make_bitvector_iterator(vespalib::datastore::EntryRef posting_idx, uint32_t doc_id_limit, fef::TermFieldMatchData &match_data, bool strict) const override; - bool has_weight_iterator(vespalib::datastore::EntryRef posting_idx) const noexcept override; - bool has_bitvector(vespalib::datastore::EntryRef posting_idx) const noexcept override; - int64_t get_integer_value(vespalib::datastore::EntryRef enum_idx) const noexcept override; - bool has_always_weight_iterator() const noexcept override { return !_is_filter; } - }; - DocidWithWeightPostingStoreAdapter _posting_store_adapter; - friend class PostingListAttributeTest; template friend class attribute::PostingSearchContext; // getEnumStore() @@ -73,6 +55,10 @@ private: using WeightedIndex = typename MultiValueNumericEnumAttribute::WeightedIndex; using generation_t = typename MultiValueNumericEnumAttribute::generation_t; + using DirectPostingStoreAdapterType = attribute::NumericDirectPostingStoreAdapter; + DirectPostingStoreAdapterType _posting_store_adapter; + using PostingParent::_posting_store; using PostingParent::clearAllPostings; using PostingParent::handle_load_posting_lists; diff --git a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp index e90940f6ca0..ea1058d88fb 100644 --- a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp @@ -4,6 +4,7 @@ #include "multinumericpostattribute.h" #include "multi_numeric_enum_search_context.h" +#include "numeric_direct_posting_store_adapter.hpp" #include #include @@ -43,7 +44,7 @@ MultiValueNumericPostingAttribute::MultiValueNumericPostingAttribute(const const AttributeVector::Config & cfg) : MultiValueNumericEnumAttribute(name, cfg), PostingParent(*this, this->getEnumStore()), - _posting_store_adapter(*this) + _posting_store_adapter(this->get_posting_store(), this->_enumStore, this->getIsFilter()) { } @@ -84,88 +85,6 @@ MultiValueNumericPostingAttribute::getSearch(QueryTermSimpleUP qTerm, return std::make_unique(std::move(base_sc), params, *this); } -template -vespalib::datastore::EntryRef -MultiValueNumericPostingAttribute::DocidWithWeightPostingStoreAdapter::get_dictionary_snapshot() const -{ - const IEnumStoreDictionary& dictionary = self._enumStore.get_dictionary(); - return dictionary.get_frozen_root(); -} - -template -IDirectPostingStore::LookupResult -MultiValueNumericPostingAttribute::DocidWithWeightPostingStoreAdapter::lookup(const LookupKey & key, vespalib::datastore::EntryRef dictionary_snapshot) const -{ - const IEnumStoreDictionary& dictionary = self._enumStore.get_dictionary(); - int64_t int_term; - if ( !key.asInteger(int_term)) { - return LookupResult(); - } - auto comp = self._enumStore.make_comparator(int_term); - auto find_result = dictionary.find_posting_list(comp, dictionary_snapshot); - if (find_result.first.valid()) { - auto pidx = find_result.second; - if (pidx.valid()) { - const auto& store = self.get_posting_store(); - auto minmax = store.getAggregated(pidx); - return LookupResult(pidx, store.frozenSize(pidx), minmax.getMin(), minmax.getMax(), find_result.first); - } - } - return LookupResult(); -} - -template -void -MultiValueNumericPostingAttribute::DocidWithWeightPostingStoreAdapter::collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, const std::function& callback)const -{ - (void) dictionary_snapshot; - callback(enum_idx); -} - -template -void -MultiValueNumericPostingAttribute::DocidWithWeightPostingStoreAdapter::create(vespalib::datastore::EntryRef posting_idx, std::vector &dst) const -{ - assert(posting_idx.valid()); - self.get_posting_store().beginFrozen(posting_idx, dst); -} - -template -DocidWithWeightIterator -MultiValueNumericPostingAttribute::DocidWithWeightPostingStoreAdapter::create(vespalib::datastore::EntryRef posting_idx) const -{ - assert(posting_idx.valid()); - return self.get_posting_store().beginFrozen(posting_idx); -} - -template -std::unique_ptr -MultiValueNumericPostingAttribute::DocidWithWeightPostingStoreAdapter::make_bitvector_iterator(vespalib::datastore::EntryRef posting_idx, uint32_t doc_id_limit, fef::TermFieldMatchData &match_data, bool strict) const -{ - return self.get_posting_store().make_bitvector_iterator(posting_idx, doc_id_limit, match_data, strict); -} - -template -bool -MultiValueNumericPostingAttribute::DocidWithWeightPostingStoreAdapter::has_weight_iterator(vespalib::datastore::EntryRef posting_idx) const noexcept -{ - return self.get_posting_store().has_btree(posting_idx); -} - -template -bool -MultiValueNumericPostingAttribute::DocidWithWeightPostingStoreAdapter::has_bitvector(vespalib::datastore::EntryRef posting_idx) const noexcept -{ - return self.get_posting_store().has_bitvector(posting_idx); -} - -template -int64_t -MultiValueNumericPostingAttribute::DocidWithWeightPostingStoreAdapter::get_integer_value(vespalib::datastore::EntryRef enum_idx) const noexcept -{ - return self._enumStore.get_value(enum_idx); -} - template const IDocidWithWeightPostingStore* MultiValueNumericPostingAttribute::as_docid_with_weight_posting_store() const diff --git a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.h b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.h index a8b93a93a34..63a445f0476 100644 --- a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.h +++ b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.h @@ -2,9 +2,10 @@ #pragma once +#include "i_docid_with_weight_posting_store.h" #include "multistringattribute.h" #include "postinglistattribute.h" -#include "i_docid_with_weight_posting_store.h" +#include "string_direct_posting_store_adapter.h" namespace search { @@ -30,25 +31,6 @@ public: using EnumStoreBatchUpdater = typename EnumStore::BatchUpdater; private: - class DocidWithWeightPostingStoreAdapter final : public IDocidWithWeightPostingStore { - public: - const MultiValueStringPostingAttributeT &self; - bool _is_filter; - DocidWithWeightPostingStoreAdapter(const MultiValueStringPostingAttributeT &self_in) - : self(self_in), _is_filter(self_in.getIsFilter()) {} - vespalib::datastore::EntryRef get_dictionary_snapshot() const override; - LookupResult lookup(const LookupKey & key, vespalib::datastore::EntryRef dictionary_snapshot) const override; - void collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, const std::function& callback) const override; - void create(vespalib::datastore::EntryRef posting_idx, std::vector &dst) const override; - DocidWithWeightIterator create(vespalib::datastore::EntryRef posting_idx) const override; - std::unique_ptr make_bitvector_iterator(vespalib::datastore::EntryRef posting_idx, uint32_t doc_id_limit, fef::TermFieldMatchData &match_data, bool strict) const override; - bool has_weight_iterator(vespalib::datastore::EntryRef posting_idx) const noexcept override; - bool has_bitvector(vespalib::datastore::EntryRef posting_idx) const noexcept override; - int64_t get_integer_value(vespalib::datastore::EntryRef enum_idx) const noexcept override; - bool has_always_weight_iterator() const noexcept override { return !_is_filter; } - }; - DocidWithWeightPostingStoreAdapter _posting_store_adapter; - using LoadedVector = typename B::LoadedVector; using PostingParent = PostingListAttributeSubBase::DocIndices; using Posting = typename PostingParent::Posting; using PostingMap = typename PostingParent::PostingMap; +public: + using PostingStore = typename PostingParent::PostingStore; +private: using QueryTermSimpleUP = AttributeVector::QueryTermSimpleUP; using SelfType = MultiValueStringPostingAttributeT; using WeightedIndex = typename MultiValueStringAttributeT::WeightedIndex; using generation_t = typename MultiValueStringAttributeT::generation_t; + using DirectPostingStoreAdapterType = attribute::StringDirectPostingStoreAdapter; + DirectPostingStoreAdapterType _posting_store_adapter; + using PostingParent::_posting_store; using PostingParent::clearAllPostings; using PostingParent::handle_load_posting_lists; @@ -78,7 +67,6 @@ private: public: using PostingParent::get_posting_store; using Dictionary = EnumPostingTree; - using PostingStore = typename PostingParent::PostingStore; MultiValueStringPostingAttributeT(const vespalib::string & name, const AttributeVector::Config & c); MultiValueStringPostingAttributeT(const vespalib::string & name); diff --git a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp index 2909a6e0ea7..b6e9b69a81d 100644 --- a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp @@ -4,6 +4,7 @@ #include "multistringpostattribute.h" #include "multi_string_enum_search_context.h" +#include "string_direct_posting_store_adapter.hpp" #include #include @@ -13,7 +14,7 @@ template MultiValueStringPostingAttributeT::MultiValueStringPostingAttributeT(const vespalib::string & name, const AttributeVector::Config & c) : MultiValueStringAttributeT(name, c), PostingParent(*this, this->getEnumStore()), - _posting_store_adapter(*this) + _posting_store_adapter(this->get_posting_store(), this->_enumStore, this->getIsFilter()) { } @@ -103,90 +104,6 @@ MultiValueStringPostingAttributeT::getSearch(QueryTermSimpleUP qTerm, return std::make_unique(std::move(base_sc), params.useBitVector(), *this); } - -template -vespalib::datastore::EntryRef -MultiValueStringPostingAttributeT::DocidWithWeightPostingStoreAdapter::get_dictionary_snapshot() const -{ - const IEnumStoreDictionary& dictionary = self._enumStore.get_dictionary(); - return dictionary.get_frozen_root(); -} - -template -IDirectPostingStore::LookupResult -MultiValueStringPostingAttributeT::DocidWithWeightPostingStoreAdapter::lookup(const LookupKey & key, vespalib::datastore::EntryRef dictionary_snapshot) const -{ - const IEnumStoreDictionary& dictionary = self._enumStore.get_dictionary(); - vespalib::stringref keyAsString = key.asString(); - // Assert the unfortunate assumption of the comparators. - // Should be lifted once they take the length too. - assert(keyAsString.data()[keyAsString.size()] == '\0'); - auto comp = self._enumStore.make_folded_comparator(keyAsString.data()); - auto find_result = dictionary.find_posting_list(comp, dictionary_snapshot); - if (find_result.first.valid()) { - auto pidx = find_result.second; - if (pidx.valid()) { - const auto& store = self.get_posting_store(); - auto minmax = store.getAggregated(pidx); - return LookupResult(pidx, store.frozenSize(pidx), minmax.getMin(), minmax.getMax(), find_result.first); - } - } - return LookupResult(); -} - -template -void -MultiValueStringPostingAttributeT::DocidWithWeightPostingStoreAdapter::collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, const std::function& callback) const -{ - const IEnumStoreDictionary &dictionary = self._enumStore.get_dictionary(); - dictionary.collect_folded(enum_idx, dictionary_snapshot, callback); -} - -template -void -MultiValueStringPostingAttributeT::DocidWithWeightPostingStoreAdapter::create(vespalib::datastore::EntryRef posting_idx, std::vector &dst) const -{ - assert(posting_idx.valid()); - self.get_posting_store().beginFrozen(posting_idx, dst); -} - -template -DocidWithWeightIterator -MultiValueStringPostingAttributeT::DocidWithWeightPostingStoreAdapter::create(vespalib::datastore::EntryRef posting_idx) const -{ - assert(posting_idx.valid()); - return self.get_posting_store().beginFrozen(posting_idx); -} - -template -bool -MultiValueStringPostingAttributeT::DocidWithWeightPostingStoreAdapter::has_weight_iterator(vespalib::datastore::EntryRef posting_idx) const noexcept -{ - return self.get_posting_store().has_btree(posting_idx); -} - -template -bool -MultiValueStringPostingAttributeT::DocidWithWeightPostingStoreAdapter::has_bitvector(vespalib::datastore::EntryRef posting_idx) const noexcept -{ - return self.get_posting_store().has_bitvector(posting_idx); -} - -template -int64_t -MultiValueStringPostingAttributeT::DocidWithWeightPostingStoreAdapter::get_integer_value(vespalib::datastore::EntryRef) const noexcept -{ - // This is not supported for string attributes and is never called. - abort(); -} - -template -std::unique_ptr -MultiValueStringPostingAttributeT::DocidWithWeightPostingStoreAdapter::make_bitvector_iterator(vespalib::datastore::EntryRef posting_idx, uint32_t doc_id_limit, fef::TermFieldMatchData &match_data, bool strict) const -{ - return self.get_posting_store().make_bitvector_iterator(posting_idx, doc_id_limit, match_data, strict); -} - template const IDocidWithWeightPostingStore* MultiValueStringPostingAttributeT::as_docid_with_weight_posting_store() const diff --git a/searchlib/src/vespa/searchlib/attribute/numeric_direct_posting_store_adapter.h b/searchlib/src/vespa/searchlib/attribute/numeric_direct_posting_store_adapter.h new file mode 100644 index 00000000000..16416df61e9 --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/numeric_direct_posting_store_adapter.h @@ -0,0 +1,31 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "direct_posting_store_adapter.h" +#include + +namespace search::attribute { + +/** + * Adapter used to implement a specific IDirectPostingStore interface for + * a numeric attribute vector with underlying posting lists (fast-search). + */ +template +class NumericDirectPostingStoreAdapter : public DirectPostingStoreAdapter { +public: + using LookupKey = typename ParentType::LookupKey; + using LookupResult = typename ParentType::LookupResult; + + NumericDirectPostingStoreAdapter(const PostingStoreType& posting_store, + const EnumStoreType& enum_store, + bool attr_is_filter); + + LookupResult lookup(const LookupKey& key, + vespalib::datastore::EntryRef dictionary_snapshot) const override; + void collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, + const std::function& callback) const override; + int64_t get_integer_value(vespalib::datastore::EntryRef enum_idx) const noexcept override; +}; + +} diff --git a/searchlib/src/vespa/searchlib/attribute/numeric_direct_posting_store_adapter.hpp b/searchlib/src/vespa/searchlib/attribute/numeric_direct_posting_store_adapter.hpp new file mode 100644 index 00000000000..b5a1282d09c --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/numeric_direct_posting_store_adapter.hpp @@ -0,0 +1,58 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "numeric_direct_posting_store_adapter.h" +#include "direct_posting_store_adapter.hpp" + +namespace search::attribute { + +template +NumericDirectPostingStoreAdapter:: +NumericDirectPostingStoreAdapter(const PostingStoreType& posting_store, + const EnumStoreType& enum_store, + bool attr_is_filter) + : DirectPostingStoreAdapter(posting_store, enum_store, attr_is_filter) +{ +} + +template +NumericDirectPostingStoreAdapter::LookupResult +NumericDirectPostingStoreAdapter:: +lookup(const LookupKey& key, vespalib::datastore::EntryRef dictionary_snapshot) const +{ + int64_t int_term; + if (!key.asInteger(int_term)) { + return LookupResult(); + } + auto comp = this->_enum_store.make_comparator(int_term); + auto find_result = this->_dict.find_posting_list(comp, dictionary_snapshot); + if (find_result.first.valid()) { + auto pidx = find_result.second; + if (pidx.valid()) { + auto minmax = this->_posting_store.getAggregated(pidx); + return LookupResult(pidx, this->_posting_store.frozenSize(pidx), minmax.getMin(), minmax.getMax(), find_result.first); + } + } + return LookupResult(); +} + +template +void +NumericDirectPostingStoreAdapter:: +collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, + const std::function& callback) const +{ + (void) dictionary_snapshot; + callback(enum_idx); +} + +template +int64_t +NumericDirectPostingStoreAdapter:: +get_integer_value(vespalib::datastore::EntryRef enum_idx) const noexcept +{ + return this->_enum_store.get_value(enum_idx); +} + +} diff --git a/searchlib/src/vespa/searchlib/attribute/string_direct_posting_store_adapter.h b/searchlib/src/vespa/searchlib/attribute/string_direct_posting_store_adapter.h new file mode 100644 index 00000000000..ca345c60d64 --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/string_direct_posting_store_adapter.h @@ -0,0 +1,31 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "direct_posting_store_adapter.h" +#include + +namespace search::attribute { + +/** + * Adapter used to implement a specific IDirectPostingStore interface for + * a string attribute vector with underlying posting lists (fast-search). + */ +template +class StringDirectPostingStoreAdapter : public DirectPostingStoreAdapter { +public: + using LookupKey = typename ParentType::LookupKey; + using LookupResult = typename ParentType::LookupResult; + + StringDirectPostingStoreAdapter(const PostingStoreType& posting_store, + const EnumStoreType& enum_store, + bool attr_is_filter); + + LookupResult lookup(const LookupKey& key, + vespalib::datastore::EntryRef dictionary_snapshot) const override; + void collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, + const std::function& callback) const override; + int64_t get_integer_value(vespalib::datastore::EntryRef enum_idx) const noexcept override; +}; + +} diff --git a/searchlib/src/vespa/searchlib/attribute/string_direct_posting_store_adapter.hpp b/searchlib/src/vespa/searchlib/attribute/string_direct_posting_store_adapter.hpp new file mode 100644 index 00000000000..9f29fe0ef46 --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/string_direct_posting_store_adapter.hpp @@ -0,0 +1,58 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "string_direct_posting_store_adapter.h" +#include "direct_posting_store_adapter.hpp" + +namespace search::attribute { + +template +StringDirectPostingStoreAdapter:: +StringDirectPostingStoreAdapter(const PostingStoreType& posting_store, + const EnumStoreType& enum_store, + bool attr_is_filter) + : DirectPostingStoreAdapter(posting_store, enum_store, attr_is_filter) +{ +} + +template +StringDirectPostingStoreAdapter::LookupResult +StringDirectPostingStoreAdapter:: +lookup(const LookupKey& key, vespalib::datastore::EntryRef dictionary_snapshot) const +{ + vespalib::stringref keyAsString = key.asString(); + // Assert the unfortunate assumption of the comparators. + // Should be lifted once they take the length too. + assert(keyAsString.data()[keyAsString.size()] == '\0'); + auto comp = this->_enum_store.make_folded_comparator(keyAsString.data()); + auto find_result = this->_dict.find_posting_list(comp, dictionary_snapshot); + if (find_result.first.valid()) { + auto pidx = find_result.second; + if (pidx.valid()) { + auto minmax = this->_posting_store.getAggregated(pidx); + return LookupResult(pidx, this->_posting_store.frozenSize(pidx), minmax.getMin(), minmax.getMax(), find_result.first); + } + } + return LookupResult(); +} + +template +void +StringDirectPostingStoreAdapter:: +collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, + const std::function& callback) const +{ + this->_dict.collect_folded(enum_idx, dictionary_snapshot, callback); +} + +template +int64_t +StringDirectPostingStoreAdapter:: +get_integer_value(vespalib::datastore::EntryRef) const noexcept +{ + // This is not supported for string attributes and is never called. + abort(); +} + +} -- cgit v1.2.3