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
2 files changed, 6 insertions(+), 13 deletions(-)
M internal/index/indexer.go → internal/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.go → internal/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)