From 03236ffa1f62b770752fed0daa5ac4d019438688 Mon Sep 17 00:00:00 2001 From: James Mills Date: Tue, 2 Feb 2021 08:23:42 +1000 Subject: [PATCH] It works (but it sucks0 --- internal/context.go | 3 +-- internal/handlers.go | 19 +++++++++++++++++-- internal/results.go | 11 +++++++++++ types/item.go | 13 ------------- types/results.go | 3 --- 5 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 internal/results.go delete mode 100644 types/item.go delete mode 100644 types/results.go diff --git a/internal/context.go b/internal/context.go index a659c39..8fc6e12 100644 --- a/internal/context.go +++ b/internal/context.go @@ -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 diff --git a/internal/handlers.go b/internal/handlers.go index 2243604..407e190 100644 --- a/internal/handlers.go +++ b/internal/handlers.go @@ -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) } diff --git a/internal/results.go b/internal/results.go new file mode 100644 index 0000000..0eb12f4 --- /dev/null +++ b/internal/results.go @@ -0,0 +1,11 @@ +package internal + +type Result struct { + ID string + URL string + Title string + Summary string + Length int +} + +type Results []Result diff --git a/types/item.go b/types/item.go deleted file mode 100644 index 66754b9..0000000 --- a/types/item.go +++ /dev/null @@ -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 -} diff --git a/types/results.go b/types/results.go deleted file mode 100644 index 10d7f21..0000000 --- a/types/results.go +++ /dev/null @@ -1,3 +0,0 @@ -package types - -type Results []Item