all repos — searchix @ 598b1f24aa5f20eb8ab47fd5bb73aae55779c1b2

Search engine for NixOS, nix-darwin, home-manager and NUR users

refactor: remove unnecessary source lookup
Alan Pearce alan@alanpearce.eu
Tue, 11 Mar 2025 15:47:22 +0100
commit

598b1f24aa5f20eb8ab47fd5bb73aae55779c1b2

parent

12947e5a912ddcd6bb82cbaab2811d02de703871

M internal/components/data.gointernal/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.templinternal/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.gointernal/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.gointernal/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{},