aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_iterator.h
blob: 9cbb1d39a9196c4a19f7820a04cec7c58614a2f8 (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
61
62
63
64
// Copyright 2019 Oath Inc. 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/tensor/dense/dense_tensor_view.h>
#include <vespa/eval/tensor/dense/mutable_dense_tensor_view.h>
#include <vespa/searchlib/fef/termfieldmatchdata.h>
#include <vespa/searchlib/tensor/dense_tensor_attribute.h>
#include <vespa/searchlib/tensor/distance_function.h>
#include <vespa/vespalib/util/priority_queue.h>
#include <cmath>

namespace search::queryeval {

class NearestNeighborIterator : public SearchIterator
{
public:
    using DenseTensorAttribute = search::tensor::DenseTensorAttribute;
    using DenseTensorView = vespalib::tensor::DenseTensorView;

    struct Params {
        fef::TermFieldMatchData &tfmd;
        const DenseTensorView &queryTensor;
        const DenseTensorAttribute &tensorAttribute;
        NearestNeighborDistanceHeap &distanceHeap;
        const search::BitVector *filter;
        const search::tensor::DistanceFunction *distanceFunction;
        
        Params(fef::TermFieldMatchData &tfmd_in,
               const DenseTensorView &queryTensor_in,
               const DenseTensorAttribute &tensorAttribute_in,
               NearestNeighborDistanceHeap &distanceHeap_in,
               const search::BitVector *filter_in,
               const search::tensor::DistanceFunction *distanceFunction_in)
          : tfmd(tfmd_in),
            queryTensor(queryTensor_in),
            tensorAttribute(tensorAttribute_in),
            distanceHeap(distanceHeap_in),
            filter(filter_in),
            distanceFunction(distanceFunction_in)
        {}
    };

    NearestNeighborIterator(Params params_in)
        : _params(params_in)
    {}
    
    static std::unique_ptr<NearestNeighborIterator> create(
            bool strict,
            fef::TermFieldMatchData &tfmd,
            const vespalib::tensor::DenseTensorView &queryTensor,
            const search::tensor::DenseTensorAttribute &tensorAttribute,
            NearestNeighborDistanceHeap &distanceHeap,
            const search::BitVector *filter,
            const search::tensor::DistanceFunction *dist_fun);

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

} // namespace