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

#pragma once

#include "itermfielddata.h"
#include <vespa/searchlib/query/weight.h>
#include <vespa/vespalib/stllike/string.h>
#include <cstddef>
#include <optional>

namespace search::fef {

/**
 * Interface to static match data for a single unit (term/phrase/etc).
 **/
class ITermData
{
protected:
    virtual ~ITermData() = default;

public:
    /**
     * Returns the term weight.
     **/
    virtual query::Weight getWeight() const = 0;

    /**
     * Returns the number of terms represented by this term data object.
     **/
    virtual uint32_t getPhraseLength() const = 0;

    /**
     * Obtain the unique id of this term. 0 means not set.
     *
     * @return unique id or 0
     **/
    virtual uint32_t getUniqueId() const = 0;

    /**
     * Returns the name of a query tensor this term is referencing, if set.
     */
    virtual std::optional<vespalib::string> query_tensor_name() const = 0;

    /**
     * Get number of fields searched
     **/
    virtual size_t numFields() const = 0;

    /**
     * Direct access to data for individual fields
     * @param i local index, must have: 0 <= i < numFields()
     */
    virtual const ITermFieldData &field(size_t i) const = 0;

    /**
     * Obtain information about a specific field that may be searched
     * by this term. If the requested field is not searched by this
     * term, NULL will be returned.
     *
     * @param fieldId global field ID
     * @return term field data, or NULL if not found
     **/
    virtual const ITermFieldData *lookupField(uint32_t fieldId) const = 0;
};

/**
 * convenience adapter for easy iteration
 **/
class ITermFieldRangeAdapter
{
    const ITermData& _ref;
    size_t _idx;
    size_t _lim;
public:
    explicit ITermFieldRangeAdapter(const ITermData& ref)
        : _ref(ref), _idx(0), _lim(ref.numFields())
    {}

    bool valid() const { return (_idx < _lim); }

    const ITermFieldData& get() const  { return _ref.field(_idx); }

    void next() { ++_idx; }
};

}