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

#pragma once

#include "searchiterator.h"
#include <vespa/searchlib/attribute/i_document_weight_attribute.h>
#include <vespa/searchlib/fef/termfieldmatchdata.h>

namespace search::queryeval {

class DocumentWeightSearchIterator : public SearchIterator
{
private:
    fef::TermFieldMatchData          &_tfmd;
    fef::TermFieldMatchDataPosition * _matchPosition;
    DocumentWeightIterator            _iterator;
    queryeval::MinMaxPostingInfo      _postingInfo;

public:
    DocumentWeightSearchIterator(fef::TermFieldMatchData &tfmd,
                                 const IDocumentWeightAttribute &attr,
                                 IDocumentWeightAttribute::LookupResult dict_entry)
        : _tfmd(tfmd),
          _matchPosition(_tfmd.populate_fixed()),
          _iterator(attr.create(dict_entry.posting_idx)),
          _postingInfo(queryeval::MinMaxPostingInfo(dict_entry.min_weight, dict_entry.max_weight))
    { }
    void initRange(uint32_t begin, uint32_t end) override {
        SearchIterator::initRange(begin, end);
        _iterator.lower_bound(begin);
        updateDocId();
    }
    void updateDocId() {
        if (_iterator.valid()) {
            setDocId(_iterator.getKey());
        } else {
            setAtEnd();
        }
    }

    void doSeek(uint32_t docId) override {
        _iterator.linearSeek(docId);
        updateDocId();
    }

    void doUnpack(uint32_t docId) override {
        _tfmd.resetOnlyDocId(docId);
        _matchPosition->setElementWeight(_iterator.getData());
    }

    const queryeval::PostingInfo *getPostingInfo() const override { return &_postingInfo; }
    Trinary is_strict() const override { return Trinary::True; }
};

}