aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_search.h
blob: 77503c07b52635404dab73332cd45bbbbb54f73b (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "wand_parts.h"
#include "weak_and_heap.h"
#include <vespa/searchlib/queryeval/searchiterator.h>
#include <vespa/searchlib/fef/matchdata.h>
#include <vespa/searchlib/fef/termfieldmatchdata.h>

namespace search::queryeval {

/**
 * WAND search iterator that uses a shared heap between match threads.
 */
struct ParallelWeakAndSearch : public SearchIterator
{
    using score_t = wand::score_t;
    using docid_t = wand::docid_t;

    /**
     * Params used to tweak the behavior of the WAND algorithm.
     */
    struct MatchParams
    {
        WeakAndHeap &scores;
        score_t      scoreThreshold;
        double       thresholdBoostFactor;
        uint32_t     scoresAdjustFrequency;
        docid_t      docIdLimit;
        MatchParams(WeakAndHeap &scores_,
                    score_t scoreThreshold_,
                    double thresholdBoostFactor_,
                    uint32_t scoresAdjustFrequency_)
            : scores(scores_),
              scoreThreshold(scoreThreshold_),
              thresholdBoostFactor(thresholdBoostFactor_),
              scoresAdjustFrequency(scoresAdjustFrequency_),
              docIdLimit(0)
        {}
        MatchParams &setDocIdLimit(docid_t value) {
            docIdLimit = value;
            return *this;
        }
    };

    /**
     * Params used for rank calculation.
     */
    struct RankParams
    {
        fef::TermFieldMatchData &rootMatchData;
        fef::MatchData::UP       childrenMatchData;
        RankParams(fef::TermFieldMatchData &rootMatchData_,
                   fef::MatchData::UP &&childrenMatchData_)
            : rootMatchData(rootMatchData_),
              childrenMatchData(std::move(childrenMatchData_))
        {}
    };

    using Terms = wand::Terms;

    virtual size_t get_num_terms() const = 0;
    virtual int32_t get_term_weight(size_t idx) const = 0;
    virtual score_t get_max_score(size_t idx) const = 0;
    virtual const MatchParams &getMatchParams() const = 0;

    static SearchIterator::UP createArrayWand(const Terms &terms, const MatchParams &matchParams, RankParams &&rankParams, bool strict);
    static SearchIterator::UP createHeapWand(const Terms &terms, const MatchParams &matchParams, RankParams &&rankParams, bool strict);
    static SearchIterator::UP create(const Terms &terms, const MatchParams &matchParams, RankParams &&rankParams, bool strict);

    static SearchIterator::UP create(fef::TermFieldMatchData &tmd,
                                     const MatchParams &matchParams,
                                     const std::vector<int32_t> &weights,
                                     const std::vector<IDocumentWeightAttribute::LookupResult> &dict_entries,
                                     const IDocumentWeightAttribute &attr,
                                     bool strict);
};

}