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

#pragma once

#include <vespa/searchlib/fef/blueprint.h>
#include <vespa/vespalib/util/rand48.h>

namespace search::features {

/**
 * Implements the executor for the random feature outputting a number in the interval [0, 1>.
 **/
class RandomExecutor : public search::fef::FeatureExecutor {
private:
    vespalib::Rand48   _rnd;       // seeded once per query
    vespalib::Rand48   _matchRnd;  // seeded once per match
    uint64_t _matchSeed;

public:
    RandomExecutor(uint64_t seed, uint64_t matchSeed);
    void execute(uint32_t docId) override;
};

/**
 * Implements the blueprint for the random feature.
 */
class RandomBlueprint : public search::fef::Blueprint {
private:
    uint64_t _seed;

public:
    RandomBlueprint();
    void visitDumpFeatures(const search::fef::IIndexEnvironment & env, search::fef::IDumpFeatureVisitor & visitor) const override;
    search::fef::Blueprint::UP createInstance() const override;
    search::fef::ParameterDescriptions getDescriptions() const override {
        return search::fef::ParameterDescriptions().
            desc().
            desc().string(); // in order to name different features
    }

    bool setup(const search::fef::IIndexEnvironment & env, const search::fef::ParameterList & params) override;
    search::fef::FeatureExecutor &createExecutor(const search::fef::IQueryEnvironment &env, vespalib::Stash &stash) const override;
};

}