1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "multistringattribute.h"
#include "postinglistattribute.h"
#include "i_document_weight_attribute.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<StringAttribute>
* T: IEnumStore::Index (array) or
* multivalue::WeightedValue<IEnumStore::Index> (weighted set)
*/
template <typename B, typename T>
class MultiValueStringPostingAttributeT
: public MultiValueStringAttributeT<B, T>,
protected PostingListAttributeSubBase<AttributeWeightPosting,
typename B::LoadedVector,
typename B::LoadedValueType,
typename B::EnumStore>
{
public:
using EnumStore = typename MultiValueStringAttributeT<B, T>::EnumStore;
using EnumStoreBatchUpdater = typename EnumStore::BatchUpdater;
private:
struct DocumentWeightAttributeAdapter final : IDocumentWeightAttribute {
const MultiValueStringPostingAttributeT &self;
DocumentWeightAttributeAdapter(const MultiValueStringPostingAttributeT &self_in) : self(self_in) {}
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<void(vespalib::datastore::EntryRef)>& callback) const override;
void create(vespalib::datastore::EntryRef idx, std::vector<DocumentWeightIterator> &dst) const override;
DocumentWeightIterator create(vespalib::datastore::EntryRef idx) const override;
std::unique_ptr<queryeval::SearchIterator> make_bitvector_iterator(vespalib::datastore::EntryRef idx, uint32_t doc_id_limit, fef::TermFieldMatchData &match_data, bool strict) const override;
};
DocumentWeightAttributeAdapter _document_weight_attribute_adapter;
using LoadedVector = typename B::LoadedVector;
using PostingParent = PostingListAttributeSubBase<AttributeWeightPosting,
LoadedVector,
typename B::LoadedValueType,
typename B::EnumStore>;
using ComparatorType = typename EnumStore::ComparatorType;
using DocId = typename MultiValueStringAttributeT<B, T>::DocId;
using DocIndices = typename MultiValueStringAttributeT<B, T>::DocIndices;
using Posting = typename PostingParent::Posting;
using PostingMap = typename PostingParent::PostingMap;
using QueryTermSimpleUP = AttributeVector::QueryTermSimpleUP;
using SelfType = MultiValueStringPostingAttributeT<B, T>;
using WeightedIndex = typename MultiValueStringAttributeT<B, T>::WeightedIndex;
using generation_t = typename MultiValueStringAttributeT<B, T>::generation_t;
using PostingParent::_postingList;
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::getPostingList;
using Dictionary = EnumPostingTree;
using PostingList = typename PostingParent::PostingList;
MultiValueStringPostingAttributeT(const vespalib::string & name, const AttributeVector::Config & c);
MultiValueStringPostingAttributeT(const vespalib::string & name);
~MultiValueStringPostingAttributeT();
void removeOldGenerations(generation_t firstUsed) override;
void onGenerationChange(generation_t generation) override;
std::unique_ptr<attribute::SearchContext>
getSearch(QueryTermSimpleUP term, const attribute::SearchContextParams & params) const override;
const IDocumentWeightAttribute *asDocumentWeightAttribute() 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<EnumAttribute<StringAttribute>, vespalib::datastore::AtomicEntryRef>;
using WeightedSetStringPostingAttribute = MultiValueStringPostingAttributeT<EnumAttribute<StringAttribute>, multivalue::WeightedValue<vespalib::datastore::AtomicEntryRef> >;
} // namespace search
|