diff options
author | Alan Pearce | 2025-01-02 15:14:34 +0100 |
---|---|---|
committer | Alan Pearce | 2025-01-02 15:14:34 +0100 |
commit | 797c6e27e18f6c47ceb4266d747a05064365c32d (patch) | |
tree | 2c67bb5e15f5bc1c3679ff8107b72b6e71132a53 /internal/index/indexer.go | |
parent | 58643f38bdd62dc538a03865b1f81eb77d957779 (diff) | |
download | searchix-797c6e27e18f6c47ceb4266d747a05064365c32d.tar.lz searchix-797c6e27e18f6c47ceb4266d747a05064365c32d.tar.zst searchix-797c6e27e18f6c47ceb4266d747a05064365c32d.zip |
fix: boost non-stemmed matches over stemmed matches
https://todo.sr.ht/~alanpearce/searchix/7
Diffstat (limited to 'internal/index/indexer.go')
-rw-r--r-- | internal/index/indexer.go | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/internal/index/indexer.go b/internal/index/indexer.go index 476ca29..0c12104 100644 --- a/internal/index/indexer.go +++ b/internal/index/indexer.go @@ -18,11 +18,11 @@ import ( "github.com/blevesearch/bleve/v2" "github.com/blevesearch/bleve/v2/analysis/analyzer/custom" "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/token/camelcase" "github.com/blevesearch/bleve/v2/analysis/token/porter" "github.com/blevesearch/bleve/v2/analysis/tokenizer/letter" - "github.com/blevesearch/bleve/v2/analysis/tokenizer/single" "github.com/blevesearch/bleve/v2/document" "github.com/blevesearch/bleve/v2/mapping" indexAPI "github.com/blevesearch/bleve_index_api" @@ -81,20 +81,19 @@ func createIndexMapping() (mapping.IndexMapping, error) { } err = indexMapping.AddCustomAnalyzer("keyword_single", map[string]interface{}{ "type": keyword.Name, - "tokenizer": single.Name, - "token_filters": []string{ - porter.Name, - }, + "tokenizer": letter.Name, }) if err != nil { return nil, errors.WithMessage(err, "could not add custom analyser") } + identityFieldMapping := bleve.NewKeywordFieldMapping() + keywordFieldMapping := bleve.NewKeywordFieldMapping() - keywordFieldMapping.Analyzer = "keyword_single" + keywordFieldMapping.Analyzer = simple.Name nameMapping := bleve.NewTextFieldMapping() - nameMapping.Analyzer = "option_name" + nameMapping.Analyzer = simple.Name nameMapping.IncludeTermVectors = true nameMapping.Store = false @@ -110,10 +109,10 @@ func createIndexMapping() (mapping.IndexMapping, error) { optionMapping := bleve.NewDocumentStaticMapping() optionMapping.AddFieldMappingsAt("Name", nameMapping) - optionMapping.AddFieldMappingsAt("Source", keywordFieldMapping) + optionMapping.AddFieldMappingsAt("Source", identityFieldMapping) optionMapping.AddFieldMappingsAt("Loc", locFieldMapping) optionMapping.AddFieldMappingsAt("RelatedPackages", textFieldMapping) - optionMapping.AddFieldMappingsAt("Description", textFieldMapping) + optionMapping.AddFieldMappingsAt("Description", descriptionFieldMapping) optionMapping.AddSubDocumentMapping("Default", nixValueMapping) optionMapping.AddSubDocumentMapping("Example", nixValueMapping) @@ -123,7 +122,7 @@ func createIndexMapping() (mapping.IndexMapping, error) { packageMapping.AddFieldMappingsAt("Name", nameMapping) packageMapping.AddFieldMappingsAt("Attribute", keywordFieldMapping) packageMapping.AddFieldMappingsAt("Source", keywordFieldMapping) - packageMapping.AddFieldMappingsAt("Description", textFieldMapping) + packageMapping.AddFieldMappingsAt("Description", descriptionFieldMapping) packageMapping.AddFieldMappingsAt("MainProgram", keywordFieldMapping) packageMapping.AddFieldMappingsAt("PackageSet", keywordFieldMapping) packageMapping.AddFieldMappingsAt("Platforms", keywordFieldMapping) |