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

#pragma once

#include "searchiterator.h"
#include "nearest_neighbor_distance_heap.h"
#include <vespa/eval/eval/value.h>
#include <vespa/searchlib/fef/termfieldmatchdata.h>
#include <vespa/searchlib/tensor/i_tensor_attribute.h>
#include <vespa/vespalib/util/priority_queue.h>
#include <cmath>

namespace search::tensor { class DistanceCalculator; }

namespace search::queryeval {

class GlobalFilter;

class NearestNeighborIterator : public SearchIterator
{
public:
    using ITensorAttribute = search::tensor::ITensorAttribute;
    using Value = vespalib::eval::Value;

    struct Params {
        fef::TermFieldMatchData &tfmd;
        std::unique_ptr<search::tensor::DistanceCalculator> distance_calc;
        NearestNeighborDistanceHeap &distanceHeap;
        const GlobalFilter &filter;

        Params(fef::TermFieldMatchData &tfmd_in,
               std::unique_ptr<search::tensor::DistanceCalculator> distance_calc_in,
               NearestNeighborDistanceHeap &distanceHeap_in,
               const GlobalFilter &filter_in)
          : tfmd(tfmd_in),
            distance_calc(std::move(distance_calc_in)),
            distanceHeap(distanceHeap_in),
            filter(filter_in)
        {}
    };

    NearestNeighborIterator(Params params_in)
        : _params(std::move(params_in))
    {}

    static std::unique_ptr<NearestNeighborIterator> create(
            bool strict,
            fef::TermFieldMatchData &tfmd,
            std::unique_ptr<search::tensor::DistanceCalculator> distance_calc,
            NearestNeighborDistanceHeap &distanceHeap,
            const GlobalFilter &filter);

    const Params& params() const { return _params; }
private:
    Params _params;
};

} // namespace