aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/single_numeric_search_context.h
blob: 6362c69cdac401b5589493dafcddc49b99763547 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "numeric_search_context.h"
#include <vespa/vespalib/util/arrayref.h>
#include <vespa/vespalib/util/atomic.h>

namespace search::attribute {

/*
 * SingleNumericSearchContext handles the creation of search iterators for
 * a query term on a single value numeric attribute vector.
 */
template <typename T, typename M>
class SingleNumericSearchContext final : public NumericSearchContext<M>
{
private:
    using DocId = ISearchContext::DocId;
    vespalib::ConstArrayRef<T> _data;

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

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

public:
    SingleNumericSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, vespalib::ConstArrayRef<T> data);
    int32_t find(DocId docId, int32_t elemId, int32_t& weight) const {
        if ( elemId != 0) return -1;
        const T v = vespalib::atomic::load_ref_relaxed(_data[docId]);
        weight = 1;
        return this->match(v) ? 0 : -1;
    }

    int32_t find(DocId docId, int elemId) const {
        if ( elemId != 0) return -1;
        const T v = vespalib::atomic::load_ref_relaxed(_data[docId]);
        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;
};

}