aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/queryeval/termwise_blueprint_helper.cpp
blob: 3eddda57cccbc0b8a890ba150e48ab79047cce6b (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "termwise_blueprint_helper.h"
#include "termwise_search.h"

namespace search {
namespace queryeval {

TermwiseBlueprintHelper::TermwiseBlueprintHelper(const IntermediateBlueprint &self,
                                                 const MultiSearch::Children &subSearches,
                                                 UnpackInfo &unpackInfo)
    : children(),
      termwise(),
      first_termwise(subSearches.size()),
      termwise_unpack()
{
    children.reserve(subSearches.size());
    termwise.reserve(subSearches.size());
    for (size_t i = 0; i < subSearches.size(); ++i) {
        bool need_unpack = unpackInfo.needUnpack(i);
        bool allow_termwise = self.getChild(i).getState().allow_termwise_eval();
        if (need_unpack || !allow_termwise) {
            if (need_unpack) {
                size_t index = (i < first_termwise) ? children.size() : (children.size() + 1);
                termwise_unpack.add(index);
            }
            children.push_back(subSearches[i]);
        } else {
            first_termwise = std::min(i, first_termwise);
            termwise.push_back(subSearches[i]);
        }
    }
}

TermwiseBlueprintHelper::~TermwiseBlueprintHelper() { }

void
TermwiseBlueprintHelper::insert_termwise(SearchIterator::UP search, bool strict)
{
    auto termwise_search = make_termwise(std::move(search), strict);
    children.insert(children.begin() + first_termwise, termwise_search.release());
}

} // namespace queryeval
} // namespace search