blob: eb8d15f84088f233fd7fcc22fee9a77a26ae098a (
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
|
// 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/query/query.h>
#include <vespa/searchlib/query/querynode.h>
namespace storage {
/**
* This class wraps a query and adds extra information to the list of leaf terms.
**/
class QueryWrapper
{
public:
class PhraseList {
private:
std::vector<search::PhraseQueryNode *> _phrases;
public:
PhraseList(search::Query & query);
search::PhraseQueryNode * findPhrase(search::QueryTerm * term, size_t & index);
};
class Term {
private:
search::QueryTerm * _term;
search::PhraseQueryNode * _parent;
size_t _index;
public:
Term() :
_term(NULL),
_parent(NULL),
_index(0)
{
}
Term(search::QueryTerm * term, search::PhraseQueryNode * parent, size_t index) :
_term(term),
_parent(parent),
_index(index)
{
}
search::QueryTerm * getTerm() { return _term; }
search::PhraseQueryNode * getParent() { return _parent; }
size_t getIndex() const { return _index; }
bool isPhraseTerm() const { return _parent != NULL; }
bool isFirstPhraseTerm() const { return isPhraseTerm() && getIndex() == 0; }
size_t getPosAdjust() const { return _parent != NULL ? _parent->width() - 1 : 0; }
};
typedef std::vector<Term> TermList;
private:
PhraseList _phraseList;
TermList _termList;
public:
QueryWrapper(search::Query & query);
TermList & getTermList() { return _termList; }
const TermList & getTermList() const { return _termList; }
};
} // namespace storage
|