forked from RediSearch/redisearch-go
/
suggest.go
39 lines (32 loc) · 1.01 KB
/
suggest.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
package redisearch
import "sort"
// Suggestion is a single suggestion being added or received from the Autocompleter
type Suggestion struct {
Term string
Score float64
Payload string
Incr bool
}
// SuggestOptions are options which are passed when recieving suggestions from the Autocompleter
type SuggestOptions struct {
Num int
Fuzzy bool
WithPayloads bool
WithScores bool
}
// DefaultIndexingOptions are the default options for document indexing
var DefaultSuggestOptions = SuggestOptions{
Num: 5,
Fuzzy: false,
WithPayloads: false,
WithScores: false,
}
// SuggestionList is a sortable list of suggestions returned from an engine
type SuggestionList []Suggestion
func (l SuggestionList) Len() int { return len(l) }
func (l SuggestionList) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
func (l SuggestionList) Less(i, j int) bool { return l[i].Score > l[j].Score } //reverse sorting
// Sort the SuggestionList
func (l SuggestionList) Sort() {
sort.Sort(l)
}