move search function to struct
This commit is contained in:
parent
a1c8dad070
commit
e0e23e8a29
|
@ -59,7 +59,7 @@ func demo() {
|
|||
}
|
||||
|
||||
var data = make([]Player, 0)
|
||||
total, err := meilisearch.Search("player", meilisearch.SearchPayload{
|
||||
total, err := index.Search(meilisearch.SearchPay load{
|
||||
Query: "ronaldo",
|
||||
Filter: [][]string{
|
||||
[]string{"age > 40"},
|
||||
|
|
|
@ -9,9 +9,8 @@ import (
|
|||
ms "github.com/meilisearch/meilisearch-go"
|
||||
)
|
||||
|
||||
// Search return result from database
|
||||
func Search(index string, payload SearchPayload, response interface{}) (int64, error) {
|
||||
result, err := client.Index(index).Search(payload.Query, &ms.SearchRequest{
|
||||
func (i Index) Search(payload SearchPayload, response interface{}) (int64, error) {
|
||||
result, err := getIndex(i.Name).Search(payload.Query, &ms.SearchRequest{
|
||||
Offset: payload.Pagination.Offset,
|
||||
Limit: payload.Pagination.Limit,
|
||||
Filter: payload.Filter,
|
||||
|
@ -23,7 +22,7 @@ func Search(index string, payload SearchPayload, response interface{}) (int64, e
|
|||
Source: "meilisearch.Search",
|
||||
Message: err.Error(),
|
||||
Data: logger.Map{
|
||||
"index": index,
|
||||
"index": i.Name,
|
||||
"payload": payload,
|
||||
},
|
||||
})
|
||||
|
@ -43,7 +42,7 @@ func Search(index string, payload SearchPayload, response interface{}) (int64, e
|
|||
Source: "meilisearch.Search",
|
||||
Message: err.Error(),
|
||||
Data: logger.Map{
|
||||
"index": index,
|
||||
"index": i.Name,
|
||||
"payload": payload,
|
||||
"hits": result.Hits,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue