// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "postinglisttraits.h" #include namespace search::fef { class TermFieldMatchData; } namespace search::queryeval { class SearchIterator; } namespace search { /** * Direct (low-level) iterator over a btree posting list that contains only docids. */ using DocidIterator = attribute::PostingListTraits::const_iterator; /** * Direct (low-level) iterator over a btree posting list that contains {docid, weight} tuples. */ using DocidWithWeightIterator = attribute::PostingListTraits::const_iterator; /** * Baseline interface providing access to dictionary lookups and underlying posting lists for an attribute vector. * * This is used to speedup query execution for multi-term query operators as InTerm, WeightedSetTerm, DotProduct, Wand. */ class IDirectPostingStore { public: struct LookupKey { virtual ~LookupKey() = default; // It is required that the string is zero terminated virtual vespalib::stringref asString() const = 0; virtual bool asInteger(int64_t &value) const; }; struct LookupResult { const vespalib::datastore::EntryRef posting_idx; const uint32_t posting_size; const int32_t min_weight; const int32_t max_weight; const vespalib::datastore::EntryRef enum_idx; LookupResult() : posting_idx(), posting_size(0), min_weight(0), max_weight(0), enum_idx() {} LookupResult(vespalib::datastore::EntryRef posting_idx_in, uint32_t posting_size_in, int32_t min_weight_in, int32_t max_weight_in, vespalib::datastore::EntryRef enum_idx_in) : posting_idx(posting_idx_in), posting_size(posting_size_in), min_weight(min_weight_in), max_weight(max_weight_in), enum_idx(enum_idx_in) {} }; virtual vespalib::datastore::EntryRef get_dictionary_snapshot() const = 0; virtual LookupResult lookup(const LookupKey & key, vespalib::datastore::EntryRef dictionary_snapshot) const = 0; // Convenience only use by various tests. LookupResult lookup(vespalib::stringref term, vespalib::datastore::EntryRef dictionary_snapshot) const; /* * Collect enum indexes (via callback) where folded * (e.g. lowercased) value equals the folded value for enum_idx. */ virtual void collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, const std::function& callback) const = 0; virtual bool has_btree_iterator(vespalib::datastore::EntryRef posting_idx) const noexcept = 0; virtual std::unique_ptr make_bitvector_iterator(vespalib::datastore::EntryRef posting_idx, uint32_t doc_id_limit, fef::TermFieldMatchData &match_data, bool strict) const = 0; virtual bool has_bitvector(vespalib::datastore::EntryRef posting_idx) const noexcept = 0; virtual int64_t get_integer_value(vespalib::datastore::EntryRef enum_idx) const noexcept = 0; /** * Returns true when btree posting list iterators are present for all terms. * * This means btree posting lists exist in addition to eventual bitvector posting lists. */ virtual bool has_always_btree_iterator() const noexcept = 0; virtual ~IDirectPostingStore() = default; }; }