aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/extendableattributes.hpp
blob: 0b05f98821b5570bb354096480428c8103060a06 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 * @class search::SearchVisitor
 *
 * @brief Visitor that applies a search query to visitor data and converts them to a QueryResultCommand
 */
#pragma once

#include "extendableattributes.h"
#include "attrvector.hpp"

namespace search {

template <typename T>
std::unique_ptr<attribute::SearchContext>
SingleExtAttribute<T>::getSearch(QueryTermSimpleUP term, const attribute::SearchContextParams & params) const
{
    (void) term;
    (void) params;
    return {};
}

template <typename T>
SingleExtAttribute<T>::SingleExtAttribute(const vespalib::string &name)
    : Super(name, Config(BasicType::fromType(T()), attribute::CollectionType::SINGLE))
{}

template <typename T>
bool
SingleExtAttribute<T>::addDoc(typename Super::DocId &docId) {
    docId = this->_data.size();
    this->_data.push_back(attribute::getUndefined<T>());
    this->incNumDocs();
    this->setCommittedDocIdLimit(this->getNumDocs());
    return true;
}
template <typename T>
bool
SingleExtAttribute<T>::add(typename AddValueType<T>::Type v, int32_t ) {
    this->_data.back() = v;
    return true;
}
template <typename T>
void
SingleExtAttribute<T>::onAddDocs(typename Super::DocId lidLimit) {
    this->_data.reserve(lidLimit);
}

template <typename T>
MultiExtAttribute<T>::MultiExtAttribute(const vespalib::string &name, const attribute::CollectionType &ctype)
    : Super(name, Config(BasicType::fromType(T()), ctype))
{ }
template <typename T>
std::unique_ptr<attribute::SearchContext>
MultiExtAttribute<T>::getSearch(QueryTermSimpleUP term, const attribute::SearchContextParams & params) const
{
    (void) term;
    (void) params;
    return {};
}

template <typename T>
MultiExtAttribute<T>::MultiExtAttribute(const vespalib::string &name)
    : Super(name, Config(BasicType::fromType(static_cast<T>(0)), attribute::CollectionType::ARRAY))
{}

template <typename T>
bool
MultiExtAttribute<T>::addDoc(typename Super::DocId &docId) {
    docId = this->_idx.size() - 1;
    this->_idx.push_back(this->_idx.back());
    this->incNumDocs();
    this->setCommittedDocIdLimit(this->getNumDocs());
    return true;
}
template <typename T>
bool
MultiExtAttribute<T>::add(typename AddValueType<T>::Type v, int32_t) {
    this->_data.push_back(v);
    std::vector<uint32_t> &idx = this->_idx;
    idx.back()++;
    this->checkSetMaxValueCount(idx.back() - idx[idx.size() - 2]);
    return true;
}
template <typename T>
void
MultiExtAttribute<T>::onAddDocs(uint32_t lidLimit) {
    this->_data.reserve(lidLimit);
}

template <typename T>
MultiExtAttribute<T>::~MultiExtAttribute() = default;

template <typename B>
WeightedSetExtAttributeBase<B>::WeightedSetExtAttributeBase(const vespalib::string & name)
    : B(name, attribute::CollectionType::WSET),
      _weights()
{}

template <typename B>
WeightedSetExtAttributeBase<B>::~WeightedSetExtAttributeBase() = default;

template <typename B>
void
WeightedSetExtAttributeBase<B>::addWeight(int32_t w) {
    _weights.push_back(w);
}

}  // namespace search