summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/features/matchesfeature.h
blob: 53c6151a7137ba24d81511bdc134ddd48082d172 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchlib/fef/blueprint.h>

namespace search::features {

/**
 * Implements the executor for the matches feature for index and
 * attribute fields.
 */
class MatchesExecutor : public fef::FeatureExecutor
{
private:
    std::vector<fef::TermFieldHandle> _handles;
    const fef::MatchData             *_md;

    void handle_bind_match_data(const fef::MatchData &md) override;

public:
    MatchesExecutor(uint32_t fieldId,
                    const fef::IQueryEnvironment &env,
                    uint32_t begin, uint32_t end);
    void execute(uint32_t docId) override;
};

/**
 * Implements the blueprint for the matches executor.
 *
 * matches(name)
 *  - returns 1 if there is an index or attribute with this name which matched the query, 0 otherwise
 * matches(name,n)
 *  - returns 1 if there is an index or attribute with this name which matched with the query term at the given position, 0 otherwise
 */
class MatchesBlueprint : public fef::Blueprint
{
private:
    const fef::FieldInfo *_field;
    uint32_t              _termIdx;

public:
    MatchesBlueprint();
    void visitDumpFeatures(const fef::IIndexEnvironment & env, fef::IDumpFeatureVisitor & visitor) const override;
    fef::Blueprint::UP createInstance() const override;
    fef::ParameterDescriptions getDescriptions() const override {
        return fef::ParameterDescriptions().desc().field().desc().field().number();
    }
    bool setup(const fef::IIndexEnvironment & env, const fef::ParameterList & params) override;
    fef::FeatureExecutor &createExecutor(const fef::IQueryEnvironment &env, vespalib::Stash &stash) const override;
};

}