It works (but it sucks0

This commit is contained in:
James Mills
2021-02-02 08:23:42 +10:00
parent beae6d03c1
commit 03236ffa1f
5 changed files with 29 additions and 20 deletions

View File

@@ -151,7 +151,7 @@ func (s *Server) SearchHandler() httprouter.Handle {
return
}
results, err := s.indexer.Search(q)
searchResults, err := s.indexer.Search(q)
if err != nil {
log.WithError(err).Error("error performing search")
ctx.Error = true
@@ -160,7 +160,22 @@ func (s *Server) SearchHandler() httprouter.Handle {
return
}
log.Debug(results)
log.Debug(searchResults)
var results []Result
for _, searchResult := range searchResults.Hits {
result := Result{
ID: searchResult.ID,
Title: searchResult.Fields["Title"].(string),
Summary: searchResult.Fields["Summary"].(string),
URL: searchResult.Fields["URL"].(string),
Length: int(searchResult.Fields["Length"].(float64)),
}
results = append(results, result)
}
ctx.Results = results
s.render("search", w, ctx)
}