Skip to content

Commit

Permalink
Always sort highlights by data added, descendant (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
svera authored Apr 8, 2024
1 parent eaa86c4 commit d4ef983
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
20 changes: 11 additions & 9 deletions internal/webserver/controller/document/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,30 @@ func (d *Controller) Search(c *fiber.Ctx) error {
return fiber.ErrInternalServerError
}

highlights, err := d.hlRepository.Highlights(int(session.ID), page, 6)
docsSortedByHighlightedDate, err := d.hlRepository.Highlights(int(session.ID), page, 6)
if err != nil {
return fiber.ErrInternalServerError
}

docs, err := d.idx.Documents(highlights.Hits())
docs, err := d.idx.Documents(docsSortedByHighlightedDate.Hits())
if err != nil {
return fiber.ErrInternalServerError
}

docsSortedByHighlightedDate := make([]index.Document, len(docs))
i := 0
for path := range docs {
docsSortedByHighlightedDate[i] = docs[path]
docsSortedByHighlightedDate[i].Highlighted = true
i++
highlights := make([]index.Document, 0, len(docs))
for _, path := range docsSortedByHighlightedDate.Hits() {
if _, ok := docs[path]; !ok {
continue
}
doc := docs[path]
doc.Highlighted = true
highlights = append(highlights, doc)
}

return c.Render("index", fiber.Map{
"Count": count,
"Title": "Coreander",
"Highlights": docsSortedByHighlightedDate,
"Highlights": highlights,
"EmailSendingConfigured": emailSendingConfigured,
"EmailFrom": d.sender.From(),
}, "layout")
Expand Down
23 changes: 12 additions & 11 deletions internal/webserver/controller/highlight/highlights.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,31 @@ func (h *Controller) Highlights(c *fiber.Ctx) error {
return fiber.ErrNotFound
}

highlights, err := h.hlRepository.Highlights(int(user.ID), page, model.ResultsPerPage)
docsSortedByHighlightedDate, err := h.hlRepository.Highlights(int(user.ID), page, model.ResultsPerPage)
if err != nil {
return fiber.ErrInternalServerError
}

docs, err := h.idx.Documents(highlights.Hits())
docs, err := h.idx.Documents(docsSortedByHighlightedDate.Hits())
if err != nil {
return fiber.ErrInternalServerError
}

docsSortedByHighlightedDate := make([]index.Document, len(docs))

i := 0
for path := range docs {
docsSortedByHighlightedDate[i] = docs[path]
docsSortedByHighlightedDate[i].Highlighted = true
i++
highlights := make([]index.Document, 0, len(docs))
for _, path := range docsSortedByHighlightedDate.Hits() {
if _, ok := docs[path]; !ok {
continue
}
doc := docs[path]
doc.Highlighted = true
highlights = append(highlights, doc)
}

paginatedResults := result.NewPaginated[[]index.Document](
model.ResultsPerPage,
page,
highlights.TotalHits(),
docsSortedByHighlightedDate,
docsSortedByHighlightedDate.TotalHits(),
highlights,
)

return c.Render("highlights", fiber.Map{
Expand Down

0 comments on commit d4ef983

Please sign in to comment.