all repos — searchix @ 49a07fb0b513dcaeb6241f4d87c160b9e0119260

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

feat: promote results with literal or prefix name matches
Alan Pearce alan@alanpearce.eu
Thu, 20 Mar 2025 19:55:17 +0100
commit

49a07fb0b513dcaeb6241f4d87c160b9e0119260

parent

7247322a386f065c643dc58f0ae5b57ad7ec1cc1

1 files changed, 19 insertions(+), 4 deletions(-)

jump to
M internal/index/search.gointernal/index/search.go
@@ -137,15 +137,30 @@ programsQuery.SetField("Programs") 	programsQuery.SetBoost(2)
 	query.AddShould(programsQuery)
 
+	programsLiteralQuery := bleve.NewTermQuery(keyword)
+	programsLiteralQuery.SetField("Programs")
+	programsLiteralQuery.SetBoost(50)
+	query.AddShould(programsLiteralQuery)
+
 	attrQuery := bleve.NewMatchQuery(keyword)
 	attrQuery.SetField("Attribute")
 	attrQuery.SetBoost(2)
 	query.AddShould(attrQuery)
 
-	nameLiteralQuery := bleve.NewMatchQuery(keyword)
-	nameLiteralQuery.SetField("Name")
-	nameLiteralQuery.SetBoost(2)
-	query.AddShould(nameLiteralQuery)
+	attrPrefixQuery := bleve.NewPrefixQuery(keyword)
+	attrPrefixQuery.SetField("Attribute")
+	attrPrefixQuery.SetBoost(10)
+	query.AddShould(attrPrefixQuery)
+
+	nameQuery := bleve.NewMatchQuery(keyword)
+	nameQuery.SetField("Name")
+	nameQuery.SetBoost(2)
+	query.AddShould(nameQuery)
+
+	namePrefixQuery := bleve.NewPrefixQuery(keyword)
+	namePrefixQuery.SetField("Name")
+	namePrefixQuery.SetBoost(10)
+	query.AddShould(namePrefixQuery)
 
 	search := bleve.NewSearchRequest(query)
 	search.Explain = config.DevMode