-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsort.go
64 lines (52 loc) · 1.15 KB
/
sort.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
package tableorm
import (
"github.com/aliyun/aliyun-tablestore-go-sdk/tablestore/search"
)
func (db *DB) SortByField(field string, asc bool) *DB {
var order *search.SortOrder
if asc {
order = search.SortOrder_ASC.Enum()
} else {
order = search.SortOrder_DESC.Enum()
}
sorter := &search.FieldSort{
FieldName: field,
Order: order,
}
db.sorters = append(db.sorters, sorter)
return db
}
func (db *DB) SortByPrimaryKey(asc bool) *DB {
var order *search.SortOrder
if asc {
order = search.SortOrder_ASC.Enum()
} else {
order = search.SortOrder_DESC.Enum()
}
sorter := &search.PrimaryKeySort{
Order: order,
}
db.sorters = append(db.sorters, sorter)
return db
}
func (db *DB) SortByScore(asc bool) *DB {
var order *search.SortOrder
if asc {
order = search.SortOrder_ASC.Enum()
} else {
order = search.SortOrder_DESC.Enum()
}
sorter := &search.ScoreSort{
Order: order,
}
db.sorters = append(db.sorters, sorter)
return db
}
func (db *DB) SortByGeoDistance(field string, points []string) *DB {
sorter := &search.GeoDistanceSort{
FieldName: field,
Points: points,
}
db.sorters = append(db.sorters, sorter)
return db
}