aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/single_enum_search_context.h
blob: 2079fa87378d5034c533f831a629a4742cb80823 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "search_context.h"
#include "enumstore.h"

namespace search::attribute {

/*
 * SingleEnumSearchContext handles the creation of search iterators for
 * a query term on a single value enumerated attribute vector.
 * This class should be considered to be an abstract class.
 */
template <typename T, typename BaseSC>
class SingleEnumSearchContext : public BaseSC
{
protected:
    using DocId = ISearchContext::DocId;
    using AtomicEntryRef = vespalib::datastore::AtomicEntryRef;
    using EnumIndices = vespalib::ConstArrayRef<AtomicEntryRef>;
    EnumIndices                 _enum_indices;
    const EnumStoreT<T>&        _enum_store;

    int32_t onFind(DocId docId, int32_t elemId, int32_t & weight) const final {
        return find(docId, elemId, weight);
    }

    int32_t onFind(DocId docId, int32_t elemId) const final {
        return find(docId, elemId);
    }

public:
    SingleEnumSearchContext(typename BaseSC::MatcherType&& matcher, const AttributeVector& toBeSearched, EnumIndices enum_indices, const EnumStoreT<T>& enum_store);

    int32_t find(DocId docId, int32_t elemId, int32_t & weight) const {
        if ( elemId != 0) return -1;
        T v = _enum_store.get_value(_enum_indices[docId].load_acquire());
        weight = 1;
        return this->match(v) ? 0 : -1;
    }

    int32_t find(DocId docId, int32_t elemId) const {
        if ( elemId != 0) return -1;
        T v = _enum_store.get_value(_enum_indices[docId].load_acquire());
        return this->match(v) ? 0 : -1;
    }

    std::unique_ptr<queryeval::SearchIterator>
    createFilterIterator(fef::TermFieldMatchData* matchData, bool strict) override;
    uint32_t get_committed_docid_limit() const noexcept override;
};

}