From 1518cf7ce9d52ef8285cf61f239f67c5fb4388db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?France=CC=81=20Wilke?= <francewilke@gmail.com> Date: Wed, 20 Jul 2022 16:11:13 +0200 Subject: [PATCH] Add limit and sorting to opensearch document store --- search/document_store.go | 4 +++- search/opensearch_types.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/search/document_store.go b/search/document_store.go index 9a6fb1c..76f34aa 100644 --- a/search/document_store.go +++ b/search/document_store.go @@ -142,7 +142,7 @@ func (ds *DocumentStore) Write(id string, data interface{}) error { // Search // Return: // docs will be a slice of the DocumentStore data type -func (ds *DocumentStore) Search(query Query, limit int64) (res *SearchResponseHits, err error) { +func (ds *DocumentStore) Search(query Query, sort []map[string]string, limit int64, offset int64) (res *SearchResponseHits, err error) { if ds == nil { return nil, errors.Errorf("document store == nil") } @@ -162,7 +162,9 @@ func (ds *DocumentStore) Search(query Query, limit int64) (res *SearchResponseHi // } // } body := SearchRequestBody{ + Sort: sort, Size: limit, + From: offset, Query: query, Timeout: Timeout, } diff --git a/search/opensearch_types.go b/search/opensearch_types.go index 7a05e67..896541b 100644 --- a/search/opensearch_types.go +++ b/search/opensearch_types.go @@ -46,7 +46,9 @@ type Query struct { } type QueryBool struct { + Must []FilterQuery `json:"must,omitempty"` // List of things that must appear in matching documents and will contribute to the score. Filter []FilterQuery `json:"filter,omitempty"` // List of things that must appear in matching documents. However, unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching + Should []Query `json:"should,omitempty"` // List of things that should appear in the matching document. MustNot []FilterQuery `json:"must_not,omitempty"` // List of things that must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned } -- GitLab