aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/query/streaming/multi_term.cpp
blob: f5a09892551cb139d08dad880b8b403d4bc15178 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "multi_term.h"
#include <vespa/searchlib/query/tree/term_vector.h>

using search::fef::ITermData;
using search::fef::MatchData;
using search::query::TermVector;

namespace search::streaming {

MultiTerm::MultiTerm(std::unique_ptr<QueryNodeResultBase> result_base, const string & index, uint32_t num_terms)
    : QueryTerm(std::move(result_base), "", index, Type::WORD, Normalizing::NONE),
      _terms()
{
    _terms.reserve(num_terms);
}

MultiTerm::MultiTerm(std::unique_ptr<QueryNodeResultBase> result_base, const string & index,
                     std::unique_ptr<TermVector> terms, Normalizing normalizing)
    : MultiTerm(std::move(result_base), index, terms->size())
{
    auto num_terms = terms->size();
    for (uint32_t i = 0; i < num_terms; ++i) {
        add_term(std::make_unique<QueryTerm>(std::unique_ptr<QueryNodeResultBase>(), terms->getAsString(i).first, "", Type::WORD, normalizing));
    }
}

MultiTerm::~MultiTerm() = default;

void
MultiTerm::add_term(std::unique_ptr<QueryTerm> term)
{
    _terms.emplace_back(std::move(term));
}

void
MultiTerm::reset()
{
    for (auto& term : _terms) {
        term->reset();
    }
}

bool
MultiTerm::evaluate() const
{
    for (const auto& term : _terms) {
        if (term->evaluate()) return true;
    }
    return false;
}

}