// 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 "numeric_direct_posting_store_adapter.h" #include "postinglistattribute.h" #include "postinglistsearchcontext.h" #include "singlenumericenumattribute.h" namespace search { /** * Implementation of single value numeric attribute that in addition to enum store * uses an underlying posting list to provide faster search. * * B: EnumAttribute */ template class SingleValueNumericPostingAttribute : public SingleValueNumericEnumAttribute, protected PostingListAttributeSubBase { public: using T = typename SingleValueNumericEnumAttribute::T; using Dictionary = EnumPostingTree; using EnumStore = typename SingleValueNumericEnumAttribute::EnumStore; using EnumStoreBatchUpdater = typename EnumStore::BatchUpdater; private: friend class PostingListAttributeTest; template friend class attribute::PostingSearchContext; // getEnumStore() using LoadedVector = typename B::LoadedVector; using PostingParent = PostingListAttributeSubBase; using Change = typename B::BaseClass::Change; using ComparatorType = typename EnumStore::ComparatorType; using DocId = typename B::BaseClass::DocId; using EnumIndex = typename SingleValueEnumAttributeBase::EnumIndex; using PostingMap = typename PostingParent::PostingMap; using PostingStore = typename PostingParent::PostingStore; using QueryTermSimpleUP = AttributeVector::QueryTermSimpleUP; using SelfType = SingleValueNumericPostingAttribute; using ValueModifier = typename B::BaseClass::ValueModifier; using generation_t = typename SingleValueNumericEnumAttribute::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; using DirectPostingStoreAdapterType = attribute::NumericDirectPostingStoreAdapter; 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, const std::map &currEnumIndices, PostingMap &changePost); void applyValueChanges(EnumStoreBatchUpdater& updater) override; public: SingleValueNumericPostingAttribute(const vespalib::string & name, const AttributeVector::Config & cfg); ~SingleValueNumericPostingAttribute(); 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; bool onAddDoc(DocId doc) override { return forwardedOnAddDoc(doc, this->_enumIndices.size(), this->_enumIndices.capacity()); } void onAddDocs(DocId docIdLimit) override { forwardedOnAddDoc(docIdLimit, 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); } }; } // namespace search