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

@@ -11,7 +11,6 @@ import (
"git.mills.io/prologic/spyda"
"git.mills.io/prologic/spyda/internal/session"
"git.mills.io/prologic/spyda/types"
)
type Meta struct {
@@ -52,7 +51,7 @@ type Context struct {
Title string
Meta Meta
Results types.Results
Results Results
Pager *paginator.Paginator
// Report abuse

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)
}

11
internal/results.go Normal file
View File

@@ -0,0 +1,11 @@
package internal
type Result struct {
ID string
URL string
Title string
Summary string
Length int
}
type Results []Result

View File

@@ -1,13 +0,0 @@
package types
type Item struct {
ID int
Length int
URL string
Title string
Author string
Summary string
Content string
HTMLContent string
}

View File

@@ -1,3 +0,0 @@
package types
type Results []Item