aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/engine/propertiesmap.h
blob: 5ba48553b90b0a701d25a50015610d8afa5ef56a (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchlib/fef/properties.h>
#include <vespa/searchlib/common/mapnames.h>

namespace search::engine {

/**
 * A simple wrapper class used to hold multiple named collections of
 * properties.
 **/
class PropertiesMap
{
private:
    using Props = search::fef::Properties;
    using PropsMap = vespalib::hash_map<vespalib::string, Props>;

    static Props _emptyProperties;
    PropsMap     _propertiesMap;

    /**
     * Obtain a named collection of properties. This method will
     * return an empty collection of properties if the properties did
     * not exist.
     *
     * @param name name of properties
     * @return the properties
     **/
    const Props &lookup(vespalib::stringref name) const;

public:
    using ITR = PropsMap::const_iterator;

    PropertiesMap();
    PropertiesMap(uint32_t sz);
    PropertiesMap(const PropertiesMap &) = delete;
    PropertiesMap & operator=(const PropertiesMap &) = delete;
    ~PropertiesMap();

    /**
     * Obtain a named collection of properties. This method will
     * create the properties if they did not exist yet.
     *
     * @param name name of properties
     * @return the properties
     **/
    Props &lookupCreate(vespalib::stringref name);

    /**
     * Obtain the number of named collection of properties held by
     * this object.
     *
     * @return number of named collections of properties
     **/
    uint32_t size() const { return _propertiesMap.size(); }

    /**
     * Iterate the map.
     *
     * @return begin iterator
     **/
    ITR begin() const { return _propertiesMap.begin(); }

    /**
     * Iterate the map.
     *
     * @return end iterator
     **/
    ITR end() const { return _propertiesMap.end(); }

    /**
     * Obtain rank properties (used to tune ranking evaluation)
     *
     * @return rank properties
     **/
    const Props &rankProperties() const {
        return lookup(MapNames::RANK);
    }

    /**
     * Obtain feature overrides (used to hardwire the values of
     * features during ranking evaluation)
     *
     * @return feature overrides
     **/
    const Props &featureOverrides() const {
        return lookup(MapNames::FEATURE);
    }

    /**
     * Obtain properties used to define additional highlight terms to
     * be used during dynamic summary generation.
     *
     * @return highlight terms properties
     **/
    const Props &highlightTerms() const {
        return lookup(MapNames::HIGHLIGHTTERMS);
    }

    /**
     * Obtain match properties (used to tune match evaluation)
     *
     * @return match properties
     **/
    const Props &matchProperties() const {
        return lookup(MapNames::MATCH);
    }

    /**
     * Obtain cache properties (used to tune cache usage)
     *
     * @return cache properties
     **/
    const Props &cacheProperties() const {
        return lookup(MapNames::CACHES);
    }

    /**
     * Obtain model overrides
     *
     * @return model properties
     **/
    const Props &modelOverrides() const {
        return lookup(MapNames::MODEL);
    }

    /**
     * Obtain trace
     *
     * @return trace
     **/
    const Props &trace() const {
        return lookup(MapNames::TRACE);
    }
};

}