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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "numeric_search_context.h"
#include "enumstore.h"
#include "multi_value_mapping_read_view.h"
#include <vespa/searchcommon/attribute/multivalue.h>
namespace search::attribute {
/*
* MultiEnumSearchContext handles the creation of search iterators for
* a query term on a multi value enumerated attribute vector.
* This class should be considered to be an abstract class.
*/
template <typename T, typename BaseSC, typename M>
class MultiEnumSearchContext : public BaseSC
{
protected:
using DocId = ISearchContext::DocId;
MultiValueMappingReadView<M> _mv_mapping_read_view;
const EnumStoreT<T>& _enum_store;
int32_t onFind(DocId docId, int32_t elemId, int32_t & weight) const override {
return find(docId, elemId, weight);
}
int32_t onFind(DocId docId, int32_t elemId) const override {
return find(docId, elemId);
}
MultiEnumSearchContext(typename BaseSC::MatcherType&& matcher, const AttributeVector& toBeSearched, MultiValueMappingReadView<M> mv_mapping_read_view, const EnumStoreT<T>& enum_store);
public:
int32_t find(DocId doc, int32_t elemId, int32_t & weight) const {
auto indices(_mv_mapping_read_view.get(doc));
for (uint32_t i(elemId); i < indices.size(); i++) {
T v = _enum_store.get_value(multivalue::get_value_ref(indices[i]).load_acquire());
if (this->match(v)) {
weight = multivalue::get_weight(indices[i]);
return i;
}
}
weight = 0;
return -1;
}
int32_t find(DocId doc, int32_t elemId) const {
auto indices(_mv_mapping_read_view.get(doc));
for (uint32_t i(elemId); i < indices.size(); i++) {
T v = _enum_store.get_value(multivalue::get_value_ref(indices[i]).load_acquire());
if (this->match(v)) {
return i;
}
}
return -1;
}
std::unique_ptr<queryeval::SearchIterator>
createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) override;
uint32_t get_committed_docid_limit() const noexcept override;
};
}
|