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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "node.h"
#include <vespa/searchlib/query/weight.h>
#include <vespa/vespalib/stllike/string.h>
namespace search::query {
/**
* This is a leaf in the Query tree. Sort of. Phrases are both terms
* and intermediate nodes.
*/
class Term
{
vespalib::string _view;
int32_t _id;
Weight _weight;
bool _ranked;
bool _position_data;
public:
virtual ~Term() = 0;
void setView(const vespalib::string & view) { _view = view; }
void setRanked(bool ranked) { _ranked = ranked; }
void setPositionData(bool position_data) { _position_data = position_data; }
void setStateFrom(const Term& other);
const vespalib::string & getView() const { return _view; }
Weight getWeight() const { return _weight; }
int32_t getId() const { return _id; }
bool isRanked() const { return _ranked; }
bool usePositionData() const { return _position_data; }
static bool isPossibleRangeTerm(vespalib::stringref term) noexcept {
return (term[0] == '[' || term[0] == '<' || term[0] == '>');
}
protected:
Term(vespalib::stringref view, int32_t id, Weight weight);
};
class TermNode : public Node, public Term {
protected:
TermNode(vespalib::stringref view, int32_t id, Weight weight) : Term(view, id, weight) {}
};
/**
* Generic functionality for most of Term's derived classes.
*/
template <typename T>
class TermBase : public TermNode {
T _term;
public:
using Type = T;
~TermBase() override = 0;
const T &getTerm() const { return _term; }
protected:
TermBase(T term, vespalib::stringref view, int32_t id, Weight weight);
};
template <typename T>
TermBase<T>::TermBase(T term, vespalib::stringref view, int32_t id, Weight weight)
: TermNode(view, id, weight),
_term(std::move(term))
{}
template <typename T>
TermBase<T>::~TermBase() = default;
}
|