// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "i_docid_posting_store.h" #include "postinglistattribute.h" #include "singlestringattribute.h" #include "string_direct_posting_store_adapter.h" namespace search { /** * Implementation of single value string attribute that in addition to enum store * uses an underlying posting list to provide faster search. * * B: EnumAttribute */ template class SingleValueStringPostingAttributeT : public SingleValueStringAttributeT, protected PostingListAttributeSubBase { public: using EnumStore = typename SingleValueStringAttributeT::EnumStore; using EnumStoreBatchUpdater = typename EnumStore::BatchUpdater; private: using LoadedVector = typename B::LoadedVector; using PostingParent = PostingListAttributeSubBase; using Change = StringAttribute::Change; using ChangeVector = StringAttribute::ChangeVector; using ComparatorType = typename EnumStore::ComparatorType; using DocId = typename SingleValueStringAttributeT::DocId; using EnumIndex = typename SingleValueStringAttributeT::EnumIndex; using PostingMap = typename PostingParent::PostingMap; using QueryTermSimpleUP = AttributeVector::QueryTermSimpleUP; using SelfType = SingleValueStringPostingAttributeT; using ValueModifier = typename SingleValueStringAttributeT::ValueModifier; using generation_t = typename SingleValueStringAttributeT::generation_t; using PostingParent::_posting_store; using PostingParent::clearAllPostings; using PostingParent::handle_load_posting_lists; using PostingParent::handle_load_posting_lists_and_update_enum_store; using PostingParent::forwardedOnAddDoc; public: using PostingStore = typename PostingParent::PostingStore; using Dictionary = EnumPostingTree; using PostingParent::get_posting_store; private: using DirectPostingStoreAdapterType = attribute::StringDirectPostingStoreAdapter; DirectPostingStoreAdapterType _posting_store_adapter; void freezeEnumDictionary() override; void mergeMemoryStats(vespalib::MemoryUsage & total) override; void applyUpdateValueChange(const Change & c, EnumStore & enumStore, std::map &currEnumIndices); void makePostingChange(const vespalib::datastore::EntryComparator &cmp, IEnumStoreDictionary& dictionary, const std::map &currEnumIndices, PostingMap &changePost); void applyValueChanges(EnumStoreBatchUpdater& updater) override; public: SingleValueStringPostingAttributeT(const vespalib::string & name, const AttributeVector::Config & c); SingleValueStringPostingAttributeT(const vespalib::string & name); ~SingleValueStringPostingAttributeT(); void reclaim_memory(generation_t oldest_used_gen) override; void before_inc_generation(generation_t current_gen) override; std::unique_ptr getSearch(QueryTermSimpleUP term, const attribute::SearchContextParams & params) const override; const IDocidPostingStore* as_docid_posting_store() const override { return &_posting_store_adapter; } bool onAddDoc(DocId doc) override { return forwardedOnAddDoc(doc, this->_enumIndices.size(), this->_enumIndices.capacity()); } void onAddDocs(DocId lidLimit) override { forwardedOnAddDoc(lidLimit, this->_enumIndices.size(), this->_enumIndices.capacity()); } void load_posting_lists(LoadedVector& loaded) override { handle_load_posting_lists(loaded); } attribute::IPostingListAttributeBase * getIPostingListAttributeBase() override { return this; } const attribute::IPostingListAttributeBase * getIPostingListAttributeBase() const override { return this; } void load_posting_lists_and_update_enum_store(enumstore::EnumeratedPostingsLoader& loader) override { handle_load_posting_lists_and_update_enum_store(loader); } }; using SingleValueStringPostingAttribute = SingleValueStringPostingAttributeT >; } // namespace search