diff options
Diffstat (limited to 'system')
-rw-r--r-- | system/api/search.go | 23 | ||||
-rw-r--r-- | system/search/search.go | 4 |
2 files changed, 24 insertions, 3 deletions
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 diff --git a/system/search/search.go b/system/search/search.go index 0b058bf..8cd0fe6 100644 --- a/system/search/search.go +++ b/system/search/search.go @@ -142,14 +142,14 @@ func DeleteIndex(id string) error { // TypeQuery conducts a search and returns a set of Ponzu "targets", Type:ID pairs, // and an error. If there is no search index for the typeName (Type) provided, // db.ErrNoIndex will be returned as the error -func TypeQuery(typeName, query string) ([]string, error) { +func TypeQuery(typeName, query string, count, offset int) ([]string, error) { idx, ok := Search[typeName] if !ok { return nil, ErrNoIndex } q := bleve.NewQueryStringQuery(query) - req := bleve.NewSearchRequest(q) + req := bleve.NewSearchRequestOptions(q, count, offset, false) res, err := idx.Search(req) if err != nil { return nil, err |