blob: 0d5c46b3ee34b893952e5d6eec5aa2e66ea6ebf7 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <cstdint>
namespace search::query {
/**
* Represents the weight given on a query item such as a term, phrase, or equiv.
* Normally given and used as an integer percent value.
*/
class Weight
{
private:
int32_t _weight;
public:
/**
* constructor.
* @param value The initial weight in percent; should be 100 unless a specific value is set.
**/
explicit Weight(int32_t value) noexcept : _weight(value) {}
/**
* change the weight value.
* @param value The new weight value in percent.
**/
void setPercent(int32_t value) { _weight = value; }
/**
* retrieve the weight value.
* @return weight value in percent.
**/
int32_t percent() const { return _weight; }
/**
* retrieve the weight value as a multiplier.
* @return weight multiplier with 100 percent giving 1.0 as multiplier.
**/
double multiplier() const { return 0.01 * _weight; }
/** compare two weights */
bool operator== (const Weight& other) const noexcept { return _weight == other._weight; }
};
}
inline search::query::Weight operator+(const search::query::Weight& a, const search::query::Weight& b)
{
return search::query::Weight(a.percent() + b.percent());
}
|