summaryrefslogtreecommitdiffstats
path: root/streamingvisitors/src/vespa/vsm/searcher/intfieldsearcher.cpp
blob: 0fb71a3c3c6c14a07b62ebd0195e3a8787daf556 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "intfieldsearcher.h"

using search::streaming::QueryTerm;
using search::streaming::QueryTermList;

namespace vsm {

std::unique_ptr<FieldSearcher>
IntFieldSearcher::duplicate() const
{
    return std::make_unique<IntFieldSearcher>(*this);
}

IntFieldSearcher::IntFieldSearcher(FieldIdT fId) :
    FieldSearcher(fId),
    _intTerm()
{ }

IntFieldSearcher::~IntFieldSearcher() = default;

void IntFieldSearcher::prepare(search::streaming::QueryTermList& qtl,
                               const SharedSearcherBuf& buf,
                               const vsm::FieldPathMapT& field_paths,
                               search::fef::IQueryEnvironment& query_env)
{
    _intTerm.clear();
    FieldSearcher::prepare(qtl, buf, field_paths, query_env);
    for (auto qt : qtl) {
        size_t sz(qt->termLen());
        if (sz) {
            int64_t low;
            int64_t high;
            bool valid = qt->getAsIntegerTerm(low, high);
            _intTerm.push_back(IntInfo(low, high, valid));
        }
    }
}

void IntFieldSearcher::onValue(const document::FieldValue & fv)
{
    for(size_t j=0, jm(_intTerm.size()); j < jm; j++) {
        const IntInfo & ii = _intTerm[j];
        if (ii.valid() && (ii.cmp(fv.getAsLong()))) {
            addHit(*_qtl[j], 0);
        }
    }
    ++_words;
}

}