From 4ce9a46dccafabe120aa5f798aeab38e1fee9f63 Mon Sep 17 00:00:00 2001 From: Tornike Razmadze Date: Thu, 1 Mar 2018 22:01:59 +0400 Subject: added count and offset to search api (#232) --- system/api/search.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'system/api') diff --git a/system/api/search.go b/system/api/search.go index b77de68..039f0bd 100644 --- a/system/api/search.go +++ b/system/api/search.go @@ -5,6 +5,7 @@ import ( "log" "net/http" "net/url" + "strconv" "github.com/ponzu-cms/ponzu/system/db" "github.com/ponzu-cms/ponzu/system/item" @@ -42,8 +43,28 @@ func searchContentHandler(res http.ResponseWriter, req *http.Request) { return } + count, err := strconv.Atoi(qs.Get("count")) // int: determines number of posts to return (10 default, -1 is all) + if err != nil { + if qs.Get("count") == "" { + count = 10 + } else { + res.WriteHeader(http.StatusInternalServerError) + return + } + } + + offset, err := strconv.Atoi(qs.Get("offset")) // int: multiplier of count for pagination (0 default) + if err != nil { + if qs.Get("offset") == "" { + offset = 0 + } else { + res.WriteHeader(http.StatusInternalServerError) + return + } + } + // execute search for query provided, if no index for type send 404 - matches, err := search.TypeQuery(t, q) + matches, err := search.TypeQuery(t, q, count, offset) if err == search.ErrNoIndex { res.WriteHeader(http.StatusNotFound) return -- cgit v1.2.3