From f949689b4d56daa9988c821e2f0e1b470cfc7275 Mon Sep 17 00:00:00 2001
From: JP Appel This is the experimental atlas server!
- Try POSTing a query to Atlas Server
- /search
This is the experimental atlas server! +Try POSTing a query to
/search+
You can sort the results using the query param
sortBy+
sortOrderwith asc or desc +`)) } func NewMux(db *data.Query) *http.ServeMux { @@ -37,7 +47,7 @@ func NewMux(db *data.Query) *http.ServeMux { } mux.HandleFunc("/", info) - mux.HandleFunc("/search", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("POST /search", func(w http.ResponseWriter, r *http.Request) { b := &strings.Builder{} if _, err := io.Copy(b, r.Body); err != nil { w.WriteHeader(http.StatusInternalServerError) @@ -70,6 +80,16 @@ func NewMux(db *data.Query) *http.ServeMux { } } + queryParams := r.URL.Query() + if queryParams.Has("sortBy") { + sortBy := queryParams.Get("sortBy") + sortOrder := queryParams.Get("sortOrder") + docCmp, ok := index.NewDocCmp(sortBy, sortOrder == "desc" || sortOrder == "descending") + if ok { + slices.SortFunc(docs, docCmp) + } + } + if !maxFileTime.IsZero() { w.Header().Add("Last-Modified", maxFileTime.UTC().Format(http.TimeFormat)) } -- cgit v1.2.3