all repos — searchix @ 782b636c6ba9ebccecf46c7a1e5583e8108baf9a

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

feat: demote NUR results in combined search
Alan Pearce alan@alanpearce.eu
Thu, 20 Mar 2025 20:00:59 +0100
commit

782b636c6ba9ebccecf46c7a1e5583e8108baf9a

parent

49a07fb0b513dcaeb6241f4d87c160b9e0119260

1 files changed, 10 insertions(+), 3 deletions(-)

jump to
M internal/index/search.gointernal/index/search.go
@@ -66,6 +66,12 @@ 	return q
 }
 
+func setBoost[T query.BoostableQuery](q T, boost float64) T {
+	q.SetBoost(boost)
+
+	return q
+}
+
 func (index *ReadIndex) search(
 	ctx context.Context,
 	request *bleve.SearchRequest,
@@ -125,9 +131,10 @@ query.AddMust( 			setField(bleve.NewTermQuery(source.Key), "Source"),
 		)
 	} else {
-		q := bleve.NewTermQuery("nixpkgs")
-		q.SetField("Source")
-		q.SetBoost(-150)
+		q := bleve.NewDisjunctionQuery(
+			setBoost(setField(bleve.NewTermQuery("nixpkgs"), "Source"), -150),
+			setBoost(setField(bleve.NewTermQuery("nur"), "Source"), -200),
+		)
 
 		query.AddShould(q)
 	}