all repos — searchix @ 24e3fc96ce2c96401155b86c6bfb6a6fb2e322f8

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

feat: improve relevance with compound words

Fixes: https://todo.sr.ht/~alanpearce/searchix/8
Fixes: https://todo.sr.ht/~alanpearce/searchix/10
Alan Pearce alan@alanpearce.eu
Thu, 06 Mar 2025 21:53:37 +0100
commit

24e3fc96ce2c96401155b86c6bfb6a6fb2e322f8

parent

839cd807ccd1c2c2d4048c5a892af19b08e5270a

2 files changed, 6 insertions(+), 13 deletions(-)

jump to
M internal/index/indexer.gointernal/index/indexer.go
@@ -19,6 +19,7 @@ "github.com/blevesearch/bleve/v2" 	"github.com/blevesearch/bleve/v2/analysis/analyzer/keyword"
 	"github.com/blevesearch/bleve/v2/analysis/analyzer/simple"
 	"github.com/blevesearch/bleve/v2/analysis/analyzer/web"
+	"github.com/blevesearch/bleve/v2/analysis/lang/en"
 	"github.com/blevesearch/bleve/v2/analysis/token/camelcase"
 	"github.com/blevesearch/bleve/v2/analysis/token/porter"
 	"github.com/blevesearch/bleve/v2/analysis/tokenizer/letter"
@@ -82,7 +83,7 @@ keywordFieldMapping := bleve.NewKeywordFieldMapping() 	keywordFieldMapping.Analyzer = simple.Name
 
 	nameMapping := bleve.NewTextFieldMapping()
-	nameMapping.Analyzer = simple.Name
+	nameMapping.Analyzer = en.AnalyzerName
 	nameMapping.IncludeTermVectors = true
 	nameMapping.Store = false
 
M internal/index/search.gointernal/index/search.go
@@ -140,16 +140,11 @@ ) (*Result, error) { 	query := bleve.NewBooleanQuery()
 
 	// match the user's query in any field ...
-	userQuery := bleve.NewMatchQuery(keyword)
-	userQuery.Analyzer = "option_name"
-
-	userQueryLoc := bleve.NewMatchQuery(keyword)
-	userQueryLoc.Analyzer = "loc"
-	userQueryLoc.SetBoost(2)
-
 	query.AddMust(bleve.NewDisjunctionQuery(
-		userQuery,
-		userQueryLoc,
+		bleve.NewTermQuery(keyword),
+		bleve.NewPrefixQuery(keyword),
+		bleve.NewMatchPhraseQuery(keyword),
+		bleve.NewMatchQuery(keyword),
 	))
 
 	if source != nil {
@@ -166,17 +161,14 @@ } 
 	programsQuery := bleve.NewMatchQuery(keyword)
 	programsQuery.SetField("Programs")
-	programsQuery.Analyzer = "keyword_single"
 	query.AddShould(programsQuery)
 
 	attrQuery := bleve.NewMatchQuery(keyword)
 	attrQuery.SetField("Attribute")
-	attrQuery.Analyzer = "keyword_single"
 	query.AddShould(attrQuery)
 
 	nameLiteralQuery := bleve.NewMatchQuery(keyword)
 	nameLiteralQuery.SetField("Name")
-	nameLiteralQuery.Analyzer = "keyword_single"
 	query.AddShould(nameLiteralQuery)
 
 	search := bleve.NewSearchRequest(query)