summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp
blob: 3d03bedab507680f312a5023d356cc933e53615f (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "postinglistsearchcontext.h"
#include "postinglistsearchcontext.hpp"
#include "attributeiterators.hpp"
#include "diversity.hpp"
#include <vespa/searchlib/btree/btreeiterator.hpp>



namespace search {

namespace attribute {

using btree::BTreeNode;

PostingListSearchContext::
PostingListSearchContext(const Dictionary &dictionary,
                         uint32_t docIdLimit,
                         uint64_t numValues,
                         bool hasWeight,
                         const EnumStoreBase &esb,
                         uint32_t minBvDocFreq,
                         bool useBitVector)
    : _frozenDictionary(dictionary.getFrozenView()),
      _lowerDictItr(BTreeNode::Ref(), dictionary.getAllocator()),
      _upperDictItr(BTreeNode::Ref(), dictionary.getAllocator()),
      _uniqueValues(0u),
      _docIdLimit(docIdLimit),
      _dictSize(_frozenDictionary.size()),
      _numValues(numValues),
      _hasWeight(hasWeight),
      _useBitVector(useBitVector),
      _pidx(),
      _frozenRoot(),
      _FSTC(0.0),
      _PLSTC(0.0),
      _esb(esb),
      _minBvDocFreq(minBvDocFreq),
      _gbv(nullptr)
{
}


PostingListSearchContext::~PostingListSearchContext()
{
}


void
PostingListSearchContext::lookupTerm(const EnumStoreComparator &comp)
{
    _lowerDictItr.lower_bound(_frozenDictionary.getRoot(), EnumIndex(), comp);
    _upperDictItr = _lowerDictItr;
    if (_upperDictItr.valid() && !comp(EnumIndex(), _upperDictItr.getKey())) {
        ++_upperDictItr;
        _uniqueValues = 1u;
    }
}


void
PostingListSearchContext::lookupRange(const EnumStoreComparator &low,
                                      const EnumStoreComparator &high)
{
    _lowerDictItr.lower_bound(_frozenDictionary.getRoot(), EnumIndex(), low);
    _upperDictItr = _lowerDictItr;
    if (_upperDictItr.valid() && !high(EnumIndex(), _upperDictItr.getKey())) {
        _upperDictItr.seekPast(EnumIndex(), high);
    }
    _uniqueValues = _upperDictItr - _lowerDictItr;
}


void
PostingListSearchContext::lookupSingle()
{
    if (_lowerDictItr.valid()) {
        _pidx = _lowerDictItr.getData();
    }
}

template class PostingListSearchContextT<btree::BTreeNoLeafData>;
template class PostingListSearchContextT<int32_t>;
template class PostingListFoldedSearchContextT<btree::BTreeNoLeafData>;
template class PostingListFoldedSearchContextT<int32_t>;


} // namespace attribute

} // namespace search