From e0e23e8a29a60f68767a24733a663d7ab34188fd Mon Sep 17 00:00:00 2001 From: namhq1989 Date: Mon, 14 Nov 2022 10:11:11 +0700 Subject: [PATCH] move search function to struct --- README.md | 2 +- search.go | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 11c0170..29bf15d 100644 --- a/README.md +++ b/README.md @@ -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"}, diff --git a/search.go b/search.go index def0202..516ec79 100644 --- a/search.go +++ b/search.go @@ -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, },