Skip to content

Commit 9184a1b

Browse files
committed
improve pagination
1 parent 1c942b8 commit 9184a1b

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

listeners/paginations/filter.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package paginations
22

33
import (
4+
"fmt"
5+
46
configs "github.com/crowdeco/skeleton/configs"
57
events "github.com/crowdeco/skeleton/events"
68
handlers "github.com/crowdeco/skeleton/handlers"
@@ -16,7 +18,9 @@ func (u *Filter) Handle(event interface{}) {
1618
filters := e.Filters
1719

1820
for _, v := range filters {
19-
query.Must(elastic.NewMatchQuery(v.Field, v.Value))
21+
q := elastic.NewWildcardQuery(v.Field, fmt.Sprintf("*%s*", v.Value))
22+
q.Boost(1.0)
23+
query.Must(q)
2024
}
2125
}
2226

paginations/adapter/elasticsearch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (es *ElasticsearchAdapter) Nums() (int64, error) {
4242
return result.TotalHits(), nil
4343
}
4444

45-
func (es *ElasticsearchAdapter) Slice(offset, length int, data interface{}) error {
45+
func (es *ElasticsearchAdapter) Slice(offset int, length int, data interface{}) error {
4646
es.pageQuery.Must(elastic.NewRangeQuery("Counter").From(offset).To(length + offset))
4747

4848
result, err := es.client.Search().Index(es.index).IgnoreUnavailable(true).Query(es.pageQuery).Size(length).Do(es.context)

paginations/pagination.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (p *Pagination) Handle(pagination *grpcs.Pagination) {
4141
pagination.Limit = 17
4242
}
4343

44+
p.Filters = nil
4445
if len(pagination.Fields) == len(pagination.Values) {
4546
for k, v := range pagination.Fields {
4647
if v != "" {

0 commit comments

Comments
 (0)