blob: 4930e0653d4c828aa839bf37aa0611e1bf483047 (
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 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/searchcommon/attribute/attributecontent.h>
namespace search::features {
/**
* Define the point type that makes up the end-points in our path.
*/
struct Vector2 {
Vector2(double _x, double _y) noexcept : x(_x), y(_y) { }
double x, y;
};
/**
* Implements the executor for the distance to path feature.
*/
class DistanceToPathExecutor : public fef::FeatureExecutor {
private:
attribute::IntegerContent _intBuf; // Position value buffer.
std::vector<Vector2> _path; // Path given by query.
const attribute::IAttributeVector *_pos; // Position attribute.
public:
/**
* Constructs an executor for the distance to path feature.
*
* @param path The path associated with the query environment.
* @param pos The attribute to use for positions (expects zcurve encoding).
*/
DistanceToPathExecutor(std::vector<Vector2> &path,
const attribute::IAttributeVector *pos);
void execute(uint32_t docId) override;
/**
* Defines a default distance value to use if a proper one can not be determined.
*/
static const feature_t DEFAULT_DISTANCE;
};
/**
* Implements the blueprint for the distance to path feature.
*/
class DistanceToPathBlueprint : public fef::Blueprint {
private:
vespalib::string _posAttr; // Name of the position attribute.
public:
DistanceToPathBlueprint();
~DistanceToPathBlueprint() override;
void visitDumpFeatures(const fef::IIndexEnvironment &env, fef::IDumpFeatureVisitor &visitor) const override;
[[nodiscard]] fef::Blueprint::UP createInstance() const override;
[[nodiscard]] fef::ParameterDescriptions getDescriptions() const override {
return fef::ParameterDescriptions().desc().string();
}
bool setup(const fef::IIndexEnvironment & env, const fef::ParameterList & params) override;
fef::FeatureExecutor &createExecutor(const fef::IQueryEnvironment &env, vespalib::Stash &stash) const override;
};
}
|