blob: 578fc9fe0e533c685927fbddde78bfe8dd228703 (
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
66
67
68
69
70
71
72
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "floatfieldsearcher.h"
using search::streaming::QueryTerm;
using search::streaming::QueryTermList;
namespace vsm {
std::unique_ptr<FieldSearcher>
FloatFieldSearcher::duplicate() const
{
return std::make_unique<FloatFieldSearcher>(*this);
}
std::unique_ptr<FieldSearcher>
DoubleFieldSearcher::duplicate() const
{
return std::make_unique<DoubleFieldSearcher>(*this);
}
template<typename T>
FloatFieldSearcherT<T>::FloatFieldSearcherT(FieldIdT fId) :
FieldSearcher(fId),
_floatTerm()
{}
template<typename T>
FloatFieldSearcherT<T>::~FloatFieldSearcherT() {}
template<typename T>
void FloatFieldSearcherT<T>::prepare(search::streaming::QueryTermList& qtl,
const SharedSearcherBuf& buf,
const vsm::FieldPathMapT& field_paths,
search::fef::IQueryEnvironment& query_env)
{
_floatTerm.clear();
FieldSearcher::prepare(qtl, buf, field_paths, query_env);
for (auto qt : qtl) {
size_t sz(qt->termLen());
if (sz) {
double low;
double high;
bool valid = qt->getAsDoubleTerm(low, high);
_floatTerm.push_back(FloatInfo(low, high, valid));
}
}
}
template<typename T>
void FloatFieldSearcherT<T>::onValue(const document::FieldValue & fv)
{
for(size_t j=0, jm(_floatTerm.size()); j < jm; j++) {
const FloatInfo & ii = _floatTerm[j];
if (ii.valid() && (ii.cmp(fv.getAsDouble()))) {
addHit(*_qtl[j], 0);
}
}
++_words;
}
template<typename T>
bool FloatFieldSearcherT<T>::FloatInfo::cmp(T key) const
{
return (_lower <= key) && (key <= _upper);
}
template class FloatFieldSearcherT<float>;
template class FloatFieldSearcherT<double>;
}
|