-
Notifications
You must be signed in to change notification settings - Fork 29
/
search_predicate.go
49 lines (41 loc) · 1021 Bytes
/
search_predicate.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
package pttbbs
import apipb "github.com/ptt/pttweb/proto/api"
type SearchPredicate interface {
toSearchFilter() *apipb.SearchFilter
}
func WithTitle(title string) SearchPredicate {
return &searchPredicate{&apipb.SearchFilter{
Type: apipb.SearchFilter_TYPE_TITLE,
StringData: title,
}}
}
func WithExactTitle(title string) SearchPredicate {
return &searchPredicate{&apipb.SearchFilter{
Type: apipb.SearchFilter_TYPE_EXACT_TITLE,
StringData: title,
}}
}
func WithAuthor(author string) SearchPredicate {
return &searchPredicate{&apipb.SearchFilter{
Type: apipb.SearchFilter_TYPE_AUTHOR,
StringData: author,
}}
}
func WithRecommend(n int) SearchPredicate {
if n < -100 {
n = -100
}
if n > 100 {
n = 100
}
return &searchPredicate{&apipb.SearchFilter{
Type: apipb.SearchFilter_TYPE_RECOMMEND,
NumberData: int64(n),
}}
}
type searchPredicate struct {
*apipb.SearchFilter
}
func (p *searchPredicate) toSearchFilter() *apipb.SearchFilter {
return p.SearchFilter
}