aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/queryeval/isourceselector.h
blob: d7b4f9e21551dbf001f956b70f591a2e5fd6e403 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchlib/attribute/singlenumericattribute.h>

namespace search::queryeval {

using Source = uint8_t;

namespace sourceselector {

class Iterator {
public:
    using SourceStore = SingleValueNumericAttribute<IntegerAttributeTemplate<int8_t> >;

    Iterator(const SourceStore & source) : _source(source) { }
    Iterator(const Iterator &) = delete;
    Iterator & operator = (const Iterator &) = delete;
    virtual ~Iterator() { }
    /**
     * Obtain the source to be used for the given document. This
     * function should always be called with increasing document
     * ids.
     *
     * @return source id
     * @param docId document id
     **/
    queryeval::Source getSource(uint32_t docId) const {
        return _source.getFast(docId);
    }

    uint32_t getDocIdLimit() const {
        return _source.getCommittedDocIdLimit();
    }
private:
    const SourceStore & _source;
};

}

/**
 * Component used to select between sources during result blending.
 **/
class ISourceSelector
{
protected:
    using SourceStore = sourceselector::Iterator::SourceStore;
public:
    using UP = std::unique_ptr<ISourceSelector>;
    using SP = std::shared_ptr<ISourceSelector>;
    static const Source SOURCE_LIMIT = 254u;

protected:
    ISourceSelector(Source defaultSource);
public:
    void setBaseId(uint32_t baseId) { _baseId = baseId; }
    uint32_t      getBaseId() const { return _baseId; }
    void setDefaultSource(Source source);
    Source getDefaultSource() const { return _defaultSource; }
    /**
     * Set the source to be used for a given document.
     *
     * @param docId local document id
     * @param source source for this document
     **/
    virtual void setSource(uint32_t docId, Source source) = 0;

    /**
     * Gets the limit for docId numbers known to this selector.
     *
     * @return one above highest known doc id
     **/
    virtual uint32_t getDocIdLimit() const = 0;

    /**
     * Sets the lid limit in this selector.
     *
     * @param lidLimit the new lid limit (one above highest valid doc id).
     */
    virtual void compactLidSpace(uint32_t lidLimit) = 0;

    /**
     * Create a new iterator over the data held by this source
     * selector.
     *
     * @return source selection iterator
     **/
    virtual std::unique_ptr<sourceselector::Iterator> createIterator() const = 0;

    /**
     * empty; defined for safe subclassing.
     **/
    virtual ~ISourceSelector() {}
private:
    uint32_t _baseId;
    Source   _defaultSource;
};

}