aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/multi_numeric_search_context.h
blob: 9f33fa90f8546b1399575ec9d5742f8cbe611acb (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
// 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 "multi_value_mapping_read_view.h"
#include "numeric_range_matcher.h"
#include <vespa/searchcommon/attribute/multivalue.h>

namespace search::attribute {

/*
 * MultiNumericSearchContext handles the creation of search iterators for
 * a query term on a multi value numeric attribute vector.
 */
template <typename T, typename M>
class MultiNumericSearchContext : public NumericSearchContext<NumericRangeMatcher<T>>
{
private:
    using DocId = ISearchContext::DocId;
    MultiValueMappingReadView<M> _mv_mapping_read_view;

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

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

public:
    MultiNumericSearchContext(std::unique_ptr<QueryTermSimple> qTerm, const AttributeVector& toBeSearched, MultiValueMappingReadView<M> mv_mapping_read_view);
    int32_t find(DocId doc, int32_t elemId, int32_t & weight) const {
        auto values(_mv_mapping_read_view.get(doc));
        for (uint32_t i(elemId); i < values.size(); i++) {
            if (this->match(multivalue::get_value(values[i]))) {
                weight = multivalue::get_weight(values[i]);
                return i;
            }
        }
        weight = 0;
        return -1;
    }

    int32_t find(DocId doc, int32_t elemId) const {
        auto values(_mv_mapping_read_view.get(doc));
        for (uint32_t i(elemId); i < values.size(); i++) {
            if (this->match(multivalue::get_value(values[i]))) {
                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;
};

}