// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "i_docid_with_weight_posting_store.h" #include "multistringattribute.h" #include "postinglistattribute.h" #include "string_direct_posting_store_adapter.h" namespace search { /** * Implementation of multi value string attribute that in addition to enum store and * multi value mapping uses an underlying posting list to provide faster search. * This class is used for both array and weighted set types. * * B: EnumAttribute * T: IEnumStore::Index (array) or * multivalue::WeightedValue (weighted set) */ template class MultiValueStringPostingAttributeT : public MultiValueStringAttributeT, protected PostingListAttributeSubBase { public: using EnumStore = typename MultiValueStringAttributeT::EnumStore; using EnumStoreBatchUpdater = typename EnumStore::BatchUpdater; private: using LoadedVector = typename B::LoadedVector; using PostingParent = PostingListAttributeSubBase; using ComparatorType = typename EnumStore::ComparatorType; using DocId = typename MultiValueStringAttributeT::DocId; using DocIndices = typename MultiValueStringAttributeT::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; using PostingParent::handle_load_posting_lists_and_update_enum_store; using PostingParent::forwardedOnAddDoc; void freezeEnumDictionary() override; void mergeMemoryStats(vespalib::MemoryUsage & total) override; void applyValueChanges(const DocIndices& docIndices, EnumStoreBatchUpdater& updater) override ; public: using PostingParent::get_posting_store; using Dictionary = EnumPostingTree; MultiValueStringPostingAttributeT(const vespalib::string & name, const AttributeVector::Config & c); MultiValueStringPostingAttributeT(const vespalib::string & name); ~MultiValueStringPostingAttributeT(); 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 IDocidWithWeightPostingStore *as_docid_with_weight_posting_store() const override; bool onAddDoc(DocId doc) override { return forwardedOnAddDoc(doc, this->_mvMapping.getNumKeys(), this->_mvMapping.getCapacityKeys()); } 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 ArrayStringPostingAttribute = MultiValueStringPostingAttributeT, vespalib::datastore::AtomicEntryRef>; using WeightedSetStringPostingAttribute = MultiValueStringPostingAttributeT, multivalue::WeightedValue >; } // namespace search