aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h
blob: da9aea233af035b7eeed663204e7c85cd6bd024d (plain) (blame)
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
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "singlestringattribute.h"
#include "postinglistattribute.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<StringAttribute>
 */
template <typename B>
class SingleValueStringPostingAttributeT
    : public SingleValueStringAttributeT<B>,
      protected PostingListAttributeSubBase<AttributePosting,
                                            typename B::LoadedVector,
                                            typename B::LoadedValueType,
                                            typename B::EnumStore>
{
private:
    friend class PostingListAttributeTest;
    template <typename, typename, typename> 
    friend class attribute::PostingSearchContext; // getEnumStore()
    friend class StringAttributeTest;
    typedef SingleValueStringPostingAttributeT<B> SelfType;
    typedef typename B::LoadedVector    LoadedVector;
    typedef attribute::LoadedEnumAttributeVector LoadedEnumAttributeVector;
    typedef PostingListAttributeSubBase<AttributePosting,
                                        LoadedVector,
                                        typename B::LoadedValueType,
                                        typename B::EnumStore> PostingParent;
    typedef typename SingleValueStringAttributeT<B>::DocId         DocId;
public:
    typedef typename SingleValueStringAttributeT<B>::EnumStore     EnumStore;
private:
    typedef typename SingleValueStringAttributeT<B>::EnumIndex     EnumIndex;
    typedef typename SingleValueStringAttributeT<B>::generation_t  generation_t;
    typedef typename SingleValueStringAttributeT<B>::ValueModifier ValueModifier;

    typedef typename SingleValueStringAttributeT<B>::StringSingleImplSearchContext StringSingleImplSearchContext;
    typedef attribute::StringPostingSearchContext<StringSingleImplSearchContext,
                                                  SelfType,
                                                  btree::BTreeNoLeafData>
    StringSinglePostingSearchContext;

    typedef StringAttribute::Change       Change;
    typedef StringAttribute::ChangeVector ChangeVector;
    using QueryTermSimpleUP = AttributeVector::QueryTermSimpleUP;

    typedef typename PostingParent::PostingList PostingList;
    typedef typename PostingParent::PostingMap  PostingMap;
    // typedef typename PostingParent::Posting     Posting;

    typedef EnumPostingTree Dictionary;
    typedef typename EnumStore::ComparatorType ComparatorType;
    typedef typename EnumStore::FoldedComparatorType FoldedComparatorType;
    typedef typename Dictionary::Iterator   DictionaryIterator;
    typedef typename Dictionary::ConstIterator   DictionaryConstIterator;
    typedef typename Dictionary::FrozenView FrozenDictionary;
    using PostingParent::_postingList;
    using PostingParent::clearAllPostings;
    using PostingParent::handleFillPostings;
    using PostingParent::fillPostingsFixupEnumBase;
    using PostingParent::forwardedOnAddDoc;
public:
    using PostingParent::getPostingList;

private:
    void freezeEnumDictionary() override;
    void mergeMemoryStats(MemoryUsage & total) override;
    void applyUpdateValueChange(const Change & c,
                                EnumStore & enumStore,
                                std::map<DocId, EnumIndex> &currEnumIndices);

    void
    makePostingChange(const EnumStoreComparator *cmp,
                      Dictionary &dict,
                      const std::map<DocId, EnumIndex> &currEnumIndices,
                      PostingMap &changePost);

    void applyValueChanges(EnumStoreBase::IndexVector & unused) override;
public:
    SingleValueStringPostingAttributeT(const vespalib::string & name, const AttributeVector::Config & c =
                                       AttributeVector::Config(AttributeVector::BasicType::STRING));
    ~SingleValueStringPostingAttributeT();

    void removeOldGenerations(generation_t firstUsed) override;
    void onGenerationChange(generation_t generation) override;

    AttributeVector::SearchContext::UP
    getSearch(QueryTermSimpleUP term, const attribute::SearchContextParams & params) const override;

    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 fillPostings(LoadedVector & loaded) override {
        handleFillPostings(loaded);
    }

    attribute::IPostingListAttributeBase * getIPostingListAttributeBase() override {
        return this;
    }

    void fillPostingsFixupEnum(const LoadedEnumAttributeVector &loaded) override {
        fillPostingsFixupEnumBase(loaded);
    }
};

typedef SingleValueStringPostingAttributeT<EnumAttribute<StringAttribute> > SingleValueStringPostingAttribute;

} // namespace search