/
norms.go
79 lines (74 loc) · 3.12 KB
/
norms.go
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
package mapping
// WithNorms is a mapping with the Norms parameter
//
// Norms store various normalization factors that are later used at query time
// in order to compute the score of a document relatively to a query.
//
// Although useful for scoring, norms also require quite a lot of disk
// (typically in the order of one byte per document per field in your index,
// even for documents that don’t have this specific field). As a consequence, if
// you don’t need scoring on a specific field, you should disable norms on that
// field. In particular, this is the case for fields that are used solely for
// filtering or aggregations.
//
// Norms can be disabled (but not reenabled after the fact)
//
// If updating the norms via the REST API, they will not be removed instantly,
// but will be removed as old segments are merged into new segments as you
// continue indexing new documents. Any score computation on a field that has
// had norms removed might return inconsistent results since some documents
// won’t have norms anymore while other documents might still have norms.
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/norms.html
type WithNorms interface {
// Whether field-length should be taken into account when scoring queries.
// Accepts true (default) or false.
Norms() bool
// SetNorms sets the Norms value to v
SetIndexPhrases(v bool)
}
// FieldWithNorms is a Field with the norms parameter
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/norms.html
type FieldWithNorms interface {
Field
WithNorms
}
// NormsParam is a mixin that adds the norms parameter
//
// Norms store various normalization factors that are later used at query time
// in order to compute the score of a document relatively to a query.
//
// Although useful for scoring, norms also require quite a lot of disk
// (typically in the order of one byte per document per field in your index,
// even for documents that don’t have this specific field). As a consequence, if
// you don’t need scoring on a specific field, you should disable norms on that
// field. In particular, this is the case for fields that are used solely for
// filtering or aggregations.
//
// Norms can be disabled (but not reenabled after the fact)
//
// If updating the norms via the REST API, they will not be removed instantly,
// but will be removed as old segments are merged into new segments as you
// continue indexing new documents. Any score computation on a field that has
// had norms removed might return inconsistent results since some documents
// won’t have norms anymore while other documents might still have norms.
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/norms.html
type NormsParam struct {
NormsValue *bool `bson:"norms,omitempty" json:"norms,omitempty"`
}
// Norms determines whether field-length should be taken into account when
// scoring queries. Accepts true (default) or false.
func (n NormsParam) Norms() bool {
if n.NormsValue != nil {
return *n.NormsValue
}
return true
}
// SetNorms sets the Norms value to v
func (n *NormsParam) SetNorms(v bool) {
if n.Norms() != v {
n.NormsValue = &v
}
}