From 5b0a4704b4b1a55686c79cbcd3631f316f450307 Mon Sep 17 00:00:00 2001 From: AKP Date: Sun, 5 Nov 2023 11:37:35 +0000 Subject: [PATCH] eeeeeee --- ui/internal/httpcore/httpcore.go | 8 ++++++++ ui/internal/search/search.go | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/ui/internal/httpcore/httpcore.go b/ui/internal/httpcore/httpcore.go index 0673407..522435d 100644 --- a/ui/internal/httpcore/httpcore.go +++ b/ui/internal/httpcore/httpcore.go @@ -60,6 +60,10 @@ func (e *endpoints) search(ctx *fiber.Ctx) error { return err } + if len(results) > 50 { + results = results[:50] + } + var resultNodes []g.Node conf := config.Get() @@ -82,6 +86,10 @@ func (e *endpoints) search(ctx *fiber.Ctx) error { for _, tok := range res.Tokens { if tok.Start >= startPos && tok.End <= endPos { for i, ch := range plaintext[tok.Start : tok.End+1] { + pos := (tok.Start - startPos) + i + if pos >= len(x) { + continue + } x[(tok.Start-startPos)+i] = html.B(g.Text(string(ch))) } } diff --git a/ui/internal/search/search.go b/ui/internal/search/search.go index 895e30b..fb25830 100644 --- a/ui/internal/search/search.go +++ b/ui/internal/search/search.go @@ -2,6 +2,8 @@ package search import ( "context" + "database/sql" + "errors" "git.tdpain.net/codemicro/hn84/ui/internal/database" "git.tdpain.net/codemicro/hn84/util" "github.com/uptrace/bun" @@ -80,6 +82,9 @@ func DoSearch(db *bun.DB, query []string) ([]*Match, error) { for docID, tokens := range tokensByDocument { doc := new(database.Document) if err := db.NewSelect().Model(doc).Where("id = ?", docID).Scan(context.Background(), doc); err != nil { + if errors.Is(err, sql.ErrNoRows) { + continue + } return nil, util.Wrap("final assembly", err) }