From 9762a6ba801dcbd032ac48b704ee90844b5132ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksa=20Siri=C5=A1ki?= <31509435+aleksasiriski@users.noreply.github.com> Date: Mon, 2 Sep 2024 19:35:27 +0200 Subject: [PATCH] fix(config): ranking defaults --- src/config/defaults_cat_general.go | 8 ++---- src/config/defaults_cat_images.go | 2 +- src/config/defaults_cat_science.go | 8 +++--- src/config/defaults_cat_suggestions.go | 2 +- src/config/defaults_exchange.go | 2 +- src/config/defaults_ranking.go | 38 ++++++++++++++++++++++++-- 6 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/config/defaults_cat_general.go b/src/config/defaults_cat_general.go index 7c293196..fa0041bc 100644 --- a/src/config/defaults_cat_general.go +++ b/src/config/defaults_cat_general.go @@ -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{ diff --git a/src/config/defaults_cat_images.go b/src/config/defaults_cat_images.go index d1ac99d5..1ab8b856 100644 --- a/src/config/defaults_cat_images.go +++ b/src/config/defaults_cat_images.go @@ -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{ diff --git a/src/config/defaults_cat_science.go b/src/config/defaults_cat_science.go index edadce1a..f4ab453e 100644 --- a/src/config/defaults_cat_science.go +++ b/src/config/defaults_cat_science.go @@ -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{ diff --git a/src/config/defaults_cat_suggestions.go b/src/config/defaults_cat_suggestions.go index d8ce87d6..99151956 100644 --- a/src/config/defaults_cat_suggestions.go +++ b/src/config/defaults_cat_suggestions.go @@ -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{ diff --git a/src/config/defaults_exchange.go b/src/config/defaults_exchange.go index 8e6dd4d8..19f1ef1d 100644 --- a/src/config/defaults_exchange.go +++ b/src/config/defaults_exchange.go @@ -13,5 +13,5 @@ var exchangeEngines = []engines.Name{ } var exchangeTimings = ExchangeTimings{ - HardTimeout: 500 * time.Millisecond, + HardTimeout: 1 * time.Second, } diff --git a/src/config/defaults_ranking.go b/src/config/defaults_ranking.go index 40a3b7cc..34236abe 100644 --- a/src/config/defaults_ranking.go +++ b/src/config/defaults_ranking.go @@ -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, @@ -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{ @@ -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 +}