refactor: remove unnecessary source lookup
Alan Pearce alan@alanpearce.eu
Tue, 11 Mar 2025 15:47:22 +0100
4 files changed, 1 insertions(+), 43 deletions(-)
M internal/components/data.go → internal/components/data.go
@@ -4,15 +4,12 @@ import ( "go.alanpearce.eu/searchix/frontend" "go.alanpearce.eu/searchix/internal/config" search "go.alanpearce.eu/searchix/internal/index" - - "github.com/blevesearch/bleve/v2" ) type TemplateData struct { Sources []*config.Source Source *config.Source Query string - SourceResult *bleve.SearchResult ExtraHeadHTML string Code int Message string
M internal/components/page.templ → internal/components/page.templ
@@ -46,7 +46,7 @@ <nav> <h1><a href="/">Searchix</a></h1> <a if tdata.Source == nil { - if tdata.SourceResult != nil || tdata.Query != "" { + if tdata.Query != "" { class="current" } href="/"
M internal/index/search.go → internal/index/search.go
@@ -52,38 +52,6 @@ return enabledSources, nil } -func (index *ReadIndex) GetSource( - ctx context.Context, - source *config.Source, -) (*bleve.SearchResult, error) { - var query query.Query - if source == nil { - query = bleve.NewMatchAllQuery() - } else { - tq := bleve.NewTermQuery(source.Name) - tq.SetField("Source") - query = tq - } - search := bleve.NewSearchRequest(query) - - result, err := index.index.SearchInContext(ctx, search) - - select { - case <-ctx.Done(): - return nil, ctx.Err() - default: - if err != nil { - return nil, errors.WithMessagef( - err, - "failed to execute search to find source %s in index", - source, - ) - } - } - - return result, nil -} - func setField[T query.FieldableQuery]( q T, field string,
M internal/server/mux.go → internal/server/mux.go
@@ -175,19 +175,12 @@ log.Error("template error", "template", importerType, "error", err) errorHandler(w, r, err.Error(), http.StatusInternalServerError) } } else { - sourceResult, err := index.GetSource(ctx, source) - if err != nil { - errorHandler(w, r, err.Error(), http.StatusInternalServerError) - - return - } w.Header().Add("Cache-Control", "max-age=14400") err = components.SearchPage( components.TemplateData{ ExtraHeadHTML: cfg.Web.ExtraHeadHTML, Sources: sources, Source: source, - SourceResult: sourceResult, Assets: frontend.Assets, }, components.ResultData{},