diff options
Diffstat (limited to 'system/api')
-rw-r--r-- | system/api/search.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/system/api/search.go b/system/api/search.go index ae6ac1c..9c7f0ae 100644 --- a/system/api/search.go +++ b/system/api/search.go @@ -8,6 +8,7 @@ import ( "github.com/ponzu-cms/ponzu/system/db" "github.com/ponzu-cms/ponzu/system/item" + "github.com/ponzu-cms/ponzu/system/search" ) func searchContentHandler(res http.ResponseWriter, req *http.Request) { @@ -42,9 +43,9 @@ func searchContentHandler(res http.ResponseWriter, req *http.Request) { } // execute search for query provided, if no index for type send 404 - matches, err := db.SearchType(t, q) - if err == db.ErrNoSearchIndex { - res.WriteHeader(http.StatusBadRequest) + matches, err := search.TypeQuery(t, q) + if err == search.ErrNoIndex { + res.WriteHeader(http.StatusNotFound) return } if err != nil { @@ -61,6 +62,11 @@ func searchContentHandler(res http.ResponseWriter, req *http.Request) { return } + // if we have matches, push the first as its matched by relevance + if len(bb) > 0 { + push(res, req, it, bb[0]) + } + var result = []json.RawMessage{} for i := range bb { result = append(result, bb[i]) |