aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/search_context.cpp
blob: 2b68cf58ae6aa7899ff376d70be4cc3c94169842 (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
73
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "search_context.h"
#include "attributevector.h"
#include "attributeiterators.hpp"
#include "ipostinglistsearchcontext.h"
#include <vespa/searchlib/queryeval/emptysearch.h>

using search::queryeval::SearchIterator;

namespace search::attribute {

HitEstimate
SearchContext::calc_hit_estimate() const
{
    if (_plsc != nullptr) {
        return _plsc->calc_hit_estimate();
    }
    return HitEstimate::unknown(std::max(uint64_t(_attr.getNumDocs()), _attr.getStatus().getNumValues()));
}

std::unique_ptr<SearchIterator>
SearchContext::createIterator(fef::TermFieldMatchData* matchData, bool strict)
{
    if (_plsc != nullptr) {
        auto res = _plsc->createPostingIterator(matchData, strict);
        if (res) {
            return res;
        }
    }
    return createFilterIterator(matchData, strict);
}


std::unique_ptr<SearchIterator>
SearchContext::createFilterIterator(fef::TermFieldMatchData* matchData, bool strict)
{
    if (!valid()) {
        return std::make_unique<queryeval::EmptySearch>();
    }
    if (getIsFilter()) {
        return (strict ?
                std::make_unique<FilterAttributeIteratorStrict<SearchContext>>(*this, matchData) :
                std::make_unique<FilterAttributeIteratorT<SearchContext>>(*this, matchData));
    }
    return (strict ?
            std::make_unique<AttributeIteratorStrict<SearchContext>>(*this, matchData) :
            std::make_unique<AttributeIteratorT<SearchContext>>(*this, matchData));
}


void
SearchContext::fetchPostings(const queryeval::ExecuteInfo& execInfo, bool strict)
{
    if (_plsc != nullptr) {
        _plsc->fetchPostings(execInfo, strict);
    }
}

const vespalib::string&
SearchContext::attributeName() const
{
    return _attr.getName();
}

bool
SearchContext::getIsFilter() const
{
    return _attr.getIsFilter();
}


}