aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/fef/matchdata.h
blob: bb3ea40768df201b7983633486764ee8e10e5569 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "handle.h"
#include "termfieldmatchdata.h"
#include <memory>
#include <vector>

namespace search::fef {

/**
 * An object of this class is used to store all basic data and derived
 * features for a single hit.
 **/
class MatchData
{
private:
    std::vector<TermFieldMatchData> _termFields;
    double                          _termwise_limit;

public:
    /**
     * Wrapper for constructor parameters
     **/
    class Params
    {
    private:
        uint32_t _numTermFields;

        friend class ::search::fef::MatchData;
        Params() : _numTermFields(0) {}
    public:
        uint32_t numTermFields() const { return _numTermFields; }
        Params & numTermFields(uint32_t value) {
            _numTermFields = value;
            return *this;
        }
    };
    /**
     * Avoid C++'s most vexing parse problem.
     * (reference: http://www.amazon.com/dp/0201749629/)
     **/
    static Params params() { return Params(); }

    /**
     * Convenience typedef for an auto-pointer to this class.
     **/
    using UP = std::unique_ptr<MatchData>;

    /**
     * Create a new object with the given number of term, attribute, and feature
     * slots.
     *
     * @param numTerms number of term slots
     * @param numAttributes number of attribute slots
     * @param numFeatures number of feature slots
     **/
    explicit MatchData(const Params &cparams);

    /**
     * Reset this match data in such a way that it can be re-used with
     * either the same search iterator tree or with a new search
     * iterator tree where the only difference in interaction with the
     * match data is which terms are unpacked. Note that this will
     * reset some properties, but not all. Use with caution.
     **/
    void soft_reset();

    MatchData(const MatchData &rhs) = delete;
    MatchData & operator=(const MatchData &rhs) = delete;

    /**
     * A number in the range [0,1] indicating how much of the corpus
     * the query must match for termwise evaluation to be enabled. 1
     * means never allowed. 0 means always allowed. The initial value
     * is 1 (never). This value is used when creating a search
     * (queryeval::Blueprint::createSearch).
     **/
    double get_termwise_limit() const { return _termwise_limit; }
    void set_termwise_limit(double value) { _termwise_limit = value; }

    /**
     * Obtain the number of term fields allocated in this match data
     * structure.
     *
     * @return number of term fields allocated
     **/
    uint32_t getNumTermFields() const { return _termFields.size(); }

    /**
     * Resolve a term field handle into a pointer to the actual data.
     *
     * @return term field match data
     * @param handle term field handle
     **/
    TermFieldMatchData *resolveTermField(TermFieldHandle handle) { return &_termFields[handle]; }

    /**
     * Resolve a term field handle into a pointer to the actual data.
     *
     * @return term field match data
     * @param handle term field handle
     **/
    const TermFieldMatchData *resolveTermField(TermFieldHandle handle) const { return &_termFields[handle]; }

    static MatchData::UP makeTestInstance(uint32_t numTermFields, uint32_t fieldIdLimit);
};

}