Skip to content

Commit

Permalink
Merge pull request #390 from hearchco/as/fix/ranking-defaults
Browse files Browse the repository at this point in the history
fix(config): ranking defaults
  • Loading branch information
aleksasiriski authored Sep 2, 2024
2 parents 3b79a7c + 9762a6b commit c6763f5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/config/defaults_cat_general.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@ var generalRequiredByOriginEngines = []engines.Name{
engines.GOOGLE,
}

var generalPreferredEngines = []engines.Name{
engines.ETOOLS, // Not in ByOrigin because it only gives 10 results across a lot of engines that it scrapes from.
}
var generalPreferredEngines = []engines.Name{}

var generalPreferredByOriginEngines = []engines.Name{
engines.BRAVE,
engines.MOJEEK,
// engines.YEP,
}

func generalRanking() CategoryRanking {
return EmptyRanking(generalEngines)
return ReqPrefOthRanking(generalRequiredEngines, generalPreferredEngines, generalEngines)
}

var generalTimings = CategoryTimings{
Expand Down
2 changes: 1 addition & 1 deletion src/config/defaults_cat_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var imagesPreferredEngines = []engines.Name{}
var imagesPreferredByOriginEngines = []engines.Name{}

func imagesRanking() CategoryRanking {
return EmptyRanking(imagesEngines)
return ReqPrefOthRanking(imagesRequiredEngines, imagesPreferredEngines, imagesEngines)
}

var imagesTimings = CategoryTimings{
Expand Down
8 changes: 4 additions & 4 deletions src/config/defaults_cat_science.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ var scienceEngines = []engines.Name{
engines.GOOGLESCHOLAR,
}

var scienceRequiredEngines = []engines.Name{}

var scienceRequiredByOriginEngines = []engines.Name{
var scienceRequiredEngines = []engines.Name{
engines.GOOGLESCHOLAR,
}

var scienceRequiredByOriginEngines = []engines.Name{}

var sciencePreferredEngines = []engines.Name{}

var sciencePreferredByOriginEngines = []engines.Name{}

func scienceRanking() CategoryRanking {
return EmptyRanking(scienceEngines)
return ReqPrefOthRanking(scienceRequiredEngines, sciencePreferredEngines, scienceEngines)
}

var scienceTimings = CategoryTimings{
Expand Down
2 changes: 1 addition & 1 deletion src/config/defaults_cat_suggestions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var suggestionsPreferredEngines = []engines.Name{}
var suggestionsPreferredByOriginEngines = []engines.Name{}

func suggestionsRanking() CategoryRanking {
return EmptyRanking(suggestionsEngines)
return ReqPrefOthRanking(suggestionsRequiredEngines, suggestionsPreferredEngines, suggestionsEngines)
}

var suggestionsTimings = CategoryTimings{
Expand Down
2 changes: 1 addition & 1 deletion src/config/defaults_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ var exchangeEngines = []engines.Name{
}

var exchangeTimings = ExchangeTimings{
HardTimeout: 500 * time.Millisecond,
HardTimeout: 1 * time.Second,
}
38 changes: 36 additions & 2 deletions src/config/defaults_ranking.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/hearchco/agent/src/search/engines"
)

func EmptyRanking(engs []engines.Name) CategoryRanking {
rnk := CategoryRanking{
func initCategoryRanking() CategoryRanking {
return CategoryRanking{
REXP: 0.5,
A: 1,
B: 0,
Expand All @@ -17,6 +17,10 @@ func EmptyRanking(engs []engines.Name) CategoryRanking {
TRD: 0,
Engines: map[string]CategoryEngineRanking{},
}
}

func EmptyRanking(engs []engines.Name) CategoryRanking {
rnk := initCategoryRanking()

for _, eng := range engs {
rnk.Engines[eng.String()] = CategoryEngineRanking{
Expand All @@ -27,3 +31,33 @@ func EmptyRanking(engs []engines.Name) CategoryRanking {

return rnk
}

func ReqPrefOthRanking(req []engines.Name, pref []engines.Name, oth []engines.Name) CategoryRanking {
rnk := initCategoryRanking()

// First set the least important engines
for _, eng := range oth {
rnk.Engines[eng.String()] = CategoryEngineRanking{
Mul: 1,
Const: 0,
}
}

// Afterwards overwrite with the preferred engines
for _, eng := range pref {
rnk.Engines[eng.String()] = CategoryEngineRanking{
Mul: 1.25,
Const: 0,
}
}

// Finally overwrite with the required engines
for _, eng := range req {
rnk.Engines[eng.String()] = CategoryEngineRanking{
Mul: 1.5,
Const: 0,
}
}

return rnk
}

0 comments on commit c6763f5

Please sign in to comment.