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

#include "ranksearch.h"

namespace search::queryeval {

void
RankSearch::doSeek(uint32_t docid)
{
    SearchIterator & firstChild(**getChildren().begin());
    if (firstChild.seek(docid)) {
        setDocId(docid);
    }
}

namespace {
/**
 * A simple implementation of the strict Rank search operation.
 **/
class RankSearchStrict : public RankSearch
{
protected:
    void doSeek(uint32_t docid) override;
    UP andWith(UP filter, uint32_t estimate) override;;

public:
    /**
     * Create a new Rank Search with the given children and
     * strictness. A strict Rank can assume that the first child below
     * is also strict. No such assumptions can be made about the other
     * children.
     *
     * @param children the search objects we are rank'ing
     **/
    RankSearchStrict(Children children) : RankSearch(std::move(children)) { }
};

SearchIterator::UP
RankSearchStrict::andWith(UP filter, uint32_t estimate)
{
    return getChildren()[0]->andWith(std::move(filter), estimate);
}

void
RankSearchStrict::doSeek(uint32_t docid)
{
    SearchIterator & firstChild(**getChildren().begin());
    setDocId(firstChild.seek(docid) ? docid : firstChild.getDocId());
}
}  // namespace

SearchIterator::UP
RankSearch::create(ChildrenIterators children, bool strict) {
    if (strict) {
        return UP(new RankSearchStrict(std::move(children)));
    } else {
        return UP(new RankSearch(std::move(children)));
    }
}

}