/
fuzzy.go
62 lines (58 loc) · 2.08 KB
/
fuzzy.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
package search
// Fuzzy returns documents that contain terms similar to the search term,
// as measured by a Levenshtein edit distance.
//
// An edit distance is the number of one-character changes needed to turn one
// term into another. These changes can include:
//
// - Changing a character (box → fox)
//
// - Removing a character (black → lack)
//
// - Inserting a character (sic → sick)
//
// - Transposing two adjacent characters (act → cat)
//
// To find similar terms, the fuzzy query creates a set of all possible
// variations, or expansions, of the search term within a specified edit
// distance. The query then returns exact matches for each expansion.
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html
type Fuzzy struct {
Value string `json:"value" bson:"value"`
FuzzinessParam `json:",inline" bson:",inline"`
MaxExpansionsParam `json:",inline" bson:",inline"`
PrefixLengthParam `json:",inline" bson:",inline"`
TranspositionsParam `json:",inline" bson:",inline"`
RewriteParam `json:",inline" bson:",inline"`
}
func NewFuzzy() Fuzzy {
return Fuzzy{}
}
// FuzzyQuery returns documents that contain terms similar to the search term,
// as measured by a Levenshtein edit distance.
//
// An edit distance is the number of one-character changes needed to turn one
// term into another. These changes can include:
//
// - Changing a character (box → fox)
//
// - Removing a character (black → lack)
//
// - Inserting a character (sic → sick)
//
// - Transposing two adjacent characters (act → cat)
//
// To find similar terms, the fuzzy query creates a set of all possible
// variations, or expansions, of the search term within a specified edit
// distance. The query then returns exact matches for each expansion.
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html
type FuzzyQuery struct {
Fuzzy map[string]Fuzzy `json:"fuzzy,omitempty" bson:"fuzzy,omitempty"`
}
func NewFuzzyQuery() FuzzyQuery {
return FuzzyQuery{
Fuzzy: map[string]Fuzzy{},
}
}