summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/memoryindex/posting_iterator.cpp
blob: 63040aab66f077f172256b9b51f45c1f2e00dc6c (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "posting_iterator.h"
#include <vespa/vespalib/btree/btreeiterator.hpp>
#include <vespa/vespalib/btree/btreenode.hpp>
#include <vespa/vespalib/btree/btreenodeallocator.hpp>
#include <vespa/vespalib/btree/btreenodestore.hpp>
#include <vespa/vespalib/btree/btreeroot.hpp>

#include <vespa/log/log.h>
LOG_SETUP(".searchlib.memoryindex.posting_iterator");

namespace search::memoryindex {

PostingIterator::PostingIterator(FieldIndex::PostingList::ConstIterator itr,
                                 const FeatureStore & featureStore,
                                 uint32_t packedIndex,
                                 const fef::TermFieldMatchDataArray & matchData) :
    queryeval::RankedSearchIteratorBase(matchData),
    _itr(itr),
    _featureStore(featureStore),
    _featureDecoder(nullptr)
{
    _featureStore.setupForField(packedIndex, _featureDecoder);
}

PostingIterator::~PostingIterator() {}

void
PostingIterator::initRange(uint32_t begin, uint32_t end)
{
    SearchIterator::initRange(begin, end);
    _itr.lower_bound(begin);
    if (!_itr.valid() || isAtEnd(_itr.getKey())) {
        setAtEnd();
    } else {
        setDocId(_itr.getKey());
    }
    clearUnpacked();
}

void
PostingIterator::doSeek(uint32_t docId)
{
    if (getUnpacked()) {
        clearUnpacked();
    }
    _itr.linearSeek(docId);
    if (!_itr.valid()) {
        setAtEnd();
    } else {
        setDocId(_itr.getKey());
    }
}

void
PostingIterator::doUnpack(uint32_t docId)
{
    if (!_matchData.valid() || getUnpacked()) {
        return;
    }
    assert(docId == getDocId());
    assert(_itr.valid());
    assert(docId == _itr.getKey());
    datastore::EntryRef featureRef(_itr.getData());
    _featureStore.setupForUnpackFeatures(featureRef, _featureDecoder);
    _featureDecoder.unpackFeatures(_matchData, docId);
    setUnpacked();
}

}