forked from couchbase/gocb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchquery_sorting.go
123 lines (102 loc) · 2.99 KB
/
searchquery_sorting.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
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
package gocb
import (
"encoding/json"
)
// FtsSort represents an FTS sorting for a search query.
type FtsSort interface {
}
type ftsSortBase struct {
options map[string]interface{}
}
func newFtsSortBase() ftsSortBase {
return ftsSortBase{
options: make(map[string]interface{}),
}
}
// MarshalJSON marshal's this query to JSON for the FTS REST API.
func (q ftsSortBase) MarshalJSON() ([]byte, error) {
return json.Marshal(q.options)
}
// SearchSortScore represents a FTS score sort.
type SearchSortScore struct {
ftsSortBase
}
// NewSearchSortScore creates a new SearchSortScore.
func NewSearchSortScore() *SearchSortScore {
q := &SearchSortScore{newFtsSortBase()}
q.options["by"] = "score"
return q
}
// Descending specifies the ordering of the results.
func (q *SearchSortScore) Descending(descending bool) *SearchSortScore {
q.options["desc"] = descending
return q
}
// SearchSortID represents a FTS Document ID sort.
type SearchSortID struct {
ftsSortBase
}
// NewSearchSortID creates a new SearchSortScore.
func NewSearchSortID() *SearchSortID {
q := &SearchSortID{newFtsSortBase()}
q.options["by"] = "id"
return q
}
// Descending specifies the ordering of the results.
func (q *SearchSortID) Descending(descending bool) *SearchSortID {
q.options["desc"] = descending
return q
}
// SearchSortField represents a FTS field sort.
type SearchSortField struct {
ftsSortBase
}
// NewSearchSortField creates a new SearchSortField.
func NewSearchSortField(field string) *SearchSortField {
q := &SearchSortField{newFtsSortBase()}
q.options["by"] = "field"
q.options["field"] = field
return q
}
// Type allows you to specify the FTS field sort type.
func (q *SearchSortField) Type(value string) *SearchSortField {
q.options["type"] = value
return q
}
// Mode allows you to specify the FTS field sort mode.
func (q *SearchSortField) Mode(mode string) *SearchSortField {
q.options["mode"] = mode
return q
}
// Missing allows you to specify the FTS field sort missing behaviour.
func (q *SearchSortField) Missing(missing string) *SearchSortField {
q.options["missing"] = missing
return q
}
// Descending specifies the ordering of the results.
func (q *SearchSortField) Descending(descending bool) *SearchSortField {
q.options["desc"] = descending
return q
}
// SearchSortGeoDistance represents a FTS geo sort.
type SearchSortGeoDistance struct {
ftsSortBase
}
// NewSearchSortGeoDistance creates a new SearchSortGeoDistance.
func NewSearchSortGeoDistance(field string, lon, lat float64) *SearchSortGeoDistance {
q := &SearchSortGeoDistance{newFtsSortBase()}
q.options["by"] = "geo_distance"
q.options["field"] = field
q.options["location"] = []float64{lon, lat}
return q
}
// Unit specifies the unit used for sorting
func (q *SearchSortGeoDistance) Unit(unit string) *SearchSortGeoDistance {
q.options["unit"] = unit
return q
}
// Descending specifies the ordering of the results.
func (q *SearchSortGeoDistance) Descending(descending bool) *SearchSortGeoDistance {
q.options["desc"] = descending
return q
}