Add additional fields to search request

This commit is contained in:
James Mills
2021-02-02 00:18:45 +10:00
parent 8a1161cf77
commit 4383b3125d
4 changed files with 62 additions and 1 deletions

View File

@@ -142,6 +142,26 @@ func (s *Server) CacheHandler() httprouter.Handle {
func (s *Server) SearchHandler() httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
ctx := NewContext(s.config, s.db, r)
q := strings.TrimSpace(r.FormValue("q"))
if q == "" {
ctx.Error = true
ctx.Message = "Error empty search"
s.render("error", w, ctx)
return
}
results, err := s.indexer.Search(q)
if err != nil {
log.WithError(err).Error("error performing search")
ctx.Error = true
ctx.Message = "Error performing search, please try again later"
s.render("error", w, ctx)
return
}
log.Debug(results)
s.render("search", w, ctx)
}
}