aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h
blob: 53feb4b5085b13fd956248d47a887c11a23478fb (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "ipostinglistsearchcontext.h"

namespace vespalib::datastore {
    class EntryComparator;
    class IUniqueStoreDictionaryReadSnapshot;
}

namespace search { class IEnumStoreDictionary; }

namespace search::attribute {

/**
 * Search context helper for enumerated attributes, used to eliminate
 * searches for values that are not present at all.
 */

class EnumHintSearchContext : public IPostingListSearchContext
{
    const std::unique_ptr<vespalib::datastore::IUniqueStoreDictionaryReadSnapshot> _dict_snapshot;
    uint32_t                _uniqueValues;
    uint32_t                _docIdLimit;
    uint64_t                _numValues; // attr.getStatus().getNumValues();

protected:
    EnumHintSearchContext(const IEnumStoreDictionary &dictionary,
                          uint32_t docIdLimit,
                          uint64_t numValues);
    ~EnumHintSearchContext() override;

public:
    void lookupTerm(const vespalib::datastore::EntryComparator &comp);
    void lookupRange(const vespalib::datastore::EntryComparator &low, const vespalib::datastore::EntryComparator &high);

protected:
    std::unique_ptr<queryeval::SearchIterator>
    createPostingIterator(fef::TermFieldMatchData *matchData, bool strict) override;

    void fetchPostings(const queryeval::ExecuteInfo & execInfo, bool strict) override;
    HitEstimate calc_hit_estimate() const override;
    uint32_t get_committed_docid_limit() const noexcept { return _docIdLimit; }
};

}