aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/matching/document_scorer.h
blob: 0a2b08920cc6bb1b0cce86904f9a816a4b94901e (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "i_match_loop_communicator.h"
#include <vespa/searchlib/fef/featureexecutor.h>
#include <vespa/searchlib/queryeval/searchiterator.h>

namespace search::fef {
    class RankProgram;
}

namespace proton::matching {

/**
 * Class used to calculate the rank score for a set of documents using
 * a rank program for calculation and a search iterator for unpacking
 * match data. The doScore function must be called with increasing
 * docid.
 */
class DocumentScorer
{
private:
    search::queryeval::SearchIterator &_searchItr;
    search::fef::LazyValue _scoreFeature;

public:
    using TaggedHit = IMatchLoopCommunicator::TaggedHit;
    using TaggedHits = IMatchLoopCommunicator::TaggedHits;

    DocumentScorer(search::fef::RankProgram &rankProgram,
                   search::queryeval::SearchIterator &searchItr);

    search::feature_t doScore(uint32_t docId) {
        _searchItr.unpack(docId);
        return _scoreFeature.as_number(docId);
    }

    // annotate hits with rank score, may change order
    void score(TaggedHits &hits);
};

}