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

#include "document_scorer.h"
#include <vespa/searchlib/fef/rank_program.h>
#include <algorithm>
#include <cassert>

using search::feature_t;
using search::fef::FeatureResolver;
using search::fef::RankProgram;
using search::fef::LazyValue;
using search::queryeval::SearchIterator;

namespace proton::matching {

namespace {

LazyValue
extractScoreFeature(const RankProgram &rankProgram)
{
    FeatureResolver resolver(rankProgram.get_seeds());
    assert(resolver.num_features() == 1u);
    return resolver.resolve(0);
}

}

DocumentScorer::DocumentScorer(RankProgram &rankProgram,
                               SearchIterator &searchItr)
    : _searchItr(searchItr),
      _scoreFeature(extractScoreFeature(rankProgram))
{
}

void
DocumentScorer::score(TaggedHits &hits)
{
    if (hits.empty()) {
        return;
    }
    auto sort_on_docid = [](const TaggedHit &a, const TaggedHit &b){ return (a.first.first < b.first.first); };
    std::sort(hits.begin(), hits.end(), sort_on_docid);
    _searchItr.initRange(hits.front().first.first, hits.back().first.first + 1);
    for (auto &hit: hits) {
        hit.first.second = doScore(hit.first.first);
    }
}

}