From f689391ad2245bdab05e76bffdef2e9094486fcc Mon Sep 17 00:00:00 2001 From: hiddenMedic <124312252+hiddenMedic@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:02:33 +0100 Subject: [PATCH 1/2] fix: defaults refactor --- src/config/defaults.go | 123 +++++++++++----------------------- src/engines/etools/options.go | 2 +- src/engines/name.go | 6 +- 3 files changed, 44 insertions(+), 87 deletions(-) diff --git a/src/config/defaults.go b/src/config/defaults.go index f2ed7b45..2e013cfc 100644 --- a/src/config/defaults.go +++ b/src/config/defaults.go @@ -1,6 +1,7 @@ package config import ( + "log" "time" "github.com/hearchco/hearchco/src/category" @@ -9,80 +10,36 @@ import ( const DefaultLocale string = "en_US" -func NewRanking() Ranking { - return Ranking{ - REXP: 0.5, - A: 1, - B: 0, - C: 1, - D: 0, - TRA: 1, - TRB: 0, - TRC: 1, - TRD: 0, - Engines: map[string]EngineRanking{ - engines.BING.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.BRAVE.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.DUCKDUCKGO.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.ETOOLS.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.GOOGLE.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.GOOGLESCHOLAR.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.MOJEEK.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.PRESEARCH.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.QWANT.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.STARTPAGE.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.SWISSCOWS.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.YAHOO.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.YANDEX.ToLower(): { - Mul: 1, - Const: 0, - }, - engines.YEP.ToLower(): { - Mul: 1, - Const: 0, - }, - }, +func EmptyRanking() Ranking { + rnk := Ranking{ + REXP: 0.5, + A: 1, + B: 0, + C: 1, + D: 0, + TRA: 1, + TRB: 0, + TRC: 1, + TRD: 0, + Engines: map[string]EngineRanking{}, + } + + for _, eng := range engines.Names() { + rnk.Engines[eng.ToLower()] = EngineRanking{ + Mul: 1, + Const: 0, + } } + + return rnk +} + +func NewRanking() Ranking { + return EmptyRanking() } func NewSettings() map[engines.Name]Settings { - return map[engines.Name]Settings{ + mp := map[engines.Name]Settings{ engines.BING: { Shortcut: "bi", }, @@ -123,24 +80,20 @@ func NewSettings() map[engines.Name]Settings { Shortcut: "yep", }, } + + // Check if all search engines have a shortcut set + for _, eng := range engines.Names() { + if _, ok := mp[eng]; !ok { + log.Fatalf("config.NewSettings(): %v doesn't have a shortcut set.", eng) + // ^FATAL + } + } + + return mp } func NewAllEnabled() []engines.Name { - return []engines.Name{ - engines.BING, - engines.BRAVE, - engines.DUCKDUCKGO, - engines.ETOOLS, - engines.GOOGLE, - engines.GOOGLESCHOLAR, - engines.MOJEEK, - engines.PRESEARCH, - engines.QWANT, - engines.STARTPAGE, - engines.SWISSCOWS, - engines.YAHOO, - engines.YEP, - } + return engines.Names() } func NewGeneral() []engines.Name { diff --git a/src/engines/etools/options.go b/src/engines/etools/options.go index 5c2db8fd..54e307d1 100644 --- a/src/engines/etools/options.go +++ b/src/engines/etools/options.go @@ -9,7 +9,7 @@ var Info engines.Info = engines.Info{ Name: engines.ETOOLS, URL: "https://www.etools.ch/searchSubmit.do", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.BING, engines.GOOGLE, engines.MOJEEK, engines.YANDEX}, + Crawlers: []engines.Name{engines.BING, engines.GOOGLE, engines.MOJEEK}, } var dompaths engines.DOMPaths = engines.DOMPaths{ diff --git a/src/engines/name.go b/src/engines/name.go index 9aa3bfb1..98c0b029 100644 --- a/src/engines/name.go +++ b/src/engines/name.go @@ -20,10 +20,14 @@ const ( STARTPAGE SWISSCOWS YAHOO - YANDEX YEP ) +// Returns Engine Names without UNDEFINED +func Names() []Name { + return _NameValues[1:] +} + func (n Name) ToLower() string { return strings.ToLower(n.String()) } From f2fc464ef9332b599f055c3fa24a4fb091240cf3 Mon Sep 17 00:00:00 2001 From: hiddenMedic <124312252+hiddenMedic@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:16:26 +0100 Subject: [PATCH 2/2] fix: remove Crawlers fron engines.Info --- src/engines/bing/options.go | 1 - src/engines/brave/options.go | 1 - src/engines/duckduckgo/options.go | 1 - src/engines/etools/options.go | 1 - src/engines/google/options.go | 1 - src/engines/googlescholar/options.go | 1 - src/engines/mojeek/options.go | 1 - src/engines/presearch/options.go | 1 - src/engines/qwant/options.go | 1 - src/engines/startpage/options.go | 1 - src/engines/structs.go | 1 - src/engines/swisscows/options.go | 1 - src/engines/yahoo/options.go | 1 - src/engines/yep/options.go | 1 - 14 files changed, 14 deletions(-) diff --git a/src/engines/bing/options.go b/src/engines/bing/options.go index 2e2a619f..723c0cfc 100644 --- a/src/engines/bing/options.go +++ b/src/engines/bing/options.go @@ -7,7 +7,6 @@ var Info engines.Info = engines.Info{ Name: engines.BING, URL: "https://www.bing.com/search?q=", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.BING}, } var dompaths engines.DOMPaths = engines.DOMPaths{ diff --git a/src/engines/brave/options.go b/src/engines/brave/options.go index 049c301d..7dabd01f 100644 --- a/src/engines/brave/options.go +++ b/src/engines/brave/options.go @@ -7,7 +7,6 @@ var Info engines.Info = engines.Info{ Name: engines.BRAVE, URL: "https://search.brave.com/search?q=", ResultsPerPage: 20, - Crawlers: []engines.Name{engines.BRAVE, engines.GOOGLE}, } var dompaths engines.DOMPaths = engines.DOMPaths{ diff --git a/src/engines/duckduckgo/options.go b/src/engines/duckduckgo/options.go index 7492cb0f..bf044edc 100644 --- a/src/engines/duckduckgo/options.go +++ b/src/engines/duckduckgo/options.go @@ -7,7 +7,6 @@ var Info engines.Info = engines.Info{ Name: engines.DUCKDUCKGO, URL: "https://lite.duckduckgo.com/lite/", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.BING}, } var dompaths engines.DOMPaths = engines.DOMPaths{ diff --git a/src/engines/etools/options.go b/src/engines/etools/options.go index 54e307d1..48b7219b 100644 --- a/src/engines/etools/options.go +++ b/src/engines/etools/options.go @@ -9,7 +9,6 @@ var Info engines.Info = engines.Info{ Name: engines.ETOOLS, URL: "https://www.etools.ch/searchSubmit.do", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.BING, engines.GOOGLE, engines.MOJEEK}, } var dompaths engines.DOMPaths = engines.DOMPaths{ diff --git a/src/engines/google/options.go b/src/engines/google/options.go index fd638448..58d8d376 100644 --- a/src/engines/google/options.go +++ b/src/engines/google/options.go @@ -9,7 +9,6 @@ var Info engines.Info = engines.Info{ Name: engines.GOOGLE, URL: "https://www.google.com/search?q=", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.GOOGLE}, } var dompaths engines.DOMPaths = engines.DOMPaths{ diff --git a/src/engines/googlescholar/options.go b/src/engines/googlescholar/options.go index 14beaba0..68cb9474 100644 --- a/src/engines/googlescholar/options.go +++ b/src/engines/googlescholar/options.go @@ -7,7 +7,6 @@ var Info engines.Info = engines.Info{ Name: engines.GOOGLESCHOLAR, URL: "https://scholar.google.com/scholar?q=", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.GOOGLE}, } var dompaths engines.DOMPaths = engines.DOMPaths{ diff --git a/src/engines/mojeek/options.go b/src/engines/mojeek/options.go index bf088ff4..57bcd621 100644 --- a/src/engines/mojeek/options.go +++ b/src/engines/mojeek/options.go @@ -7,7 +7,6 @@ var Info engines.Info = engines.Info{ Name: engines.MOJEEK, URL: "https://www.mojeek.com/search?q=", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.MOJEEK}, } var dompaths engines.DOMPaths = engines.DOMPaths{ diff --git a/src/engines/presearch/options.go b/src/engines/presearch/options.go index d4d04d7b..48f0ec76 100644 --- a/src/engines/presearch/options.go +++ b/src/engines/presearch/options.go @@ -7,7 +7,6 @@ var Info engines.Info = engines.Info{ Name: engines.PRESEARCH, URL: "https://presearch.com/search?q=", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.GOOGLE}, } /* diff --git a/src/engines/qwant/options.go b/src/engines/qwant/options.go index b9a870f7..b16b4eb7 100644 --- a/src/engines/qwant/options.go +++ b/src/engines/qwant/options.go @@ -7,7 +7,6 @@ var Info engines.Info = engines.Info{ Name: engines.QWANT, URL: "https://api.qwant.com/v3/search/web?q=", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.BING}, } var Support engines.SupportedSettings = engines.SupportedSettings{ diff --git a/src/engines/startpage/options.go b/src/engines/startpage/options.go index 6b59252f..823a54bf 100644 --- a/src/engines/startpage/options.go +++ b/src/engines/startpage/options.go @@ -7,7 +7,6 @@ var Info engines.Info = engines.Info{ Name: engines.STARTPAGE, URL: "https://www.startpage.com/sp/search?q=", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.GOOGLE}, } var dompaths engines.DOMPaths = engines.DOMPaths{ diff --git a/src/engines/structs.go b/src/engines/structs.go index 156dfa2a..336fe5c7 100644 --- a/src/engines/structs.go +++ b/src/engines/structs.go @@ -35,7 +35,6 @@ type Info struct { Name Name URL string ResultsPerPage int - Crawlers []Name } type DOMPaths struct { diff --git a/src/engines/swisscows/options.go b/src/engines/swisscows/options.go index 089b51fe..cde85d26 100644 --- a/src/engines/swisscows/options.go +++ b/src/engines/swisscows/options.go @@ -7,7 +7,6 @@ var Info engines.Info = engines.Info{ Name: engines.SWISSCOWS, URL: "https://api.swisscows.com/web/search?", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.BING}, } var Support engines.SupportedSettings = engines.SupportedSettings{ diff --git a/src/engines/yahoo/options.go b/src/engines/yahoo/options.go index 36e4fe1e..d1cb26df 100644 --- a/src/engines/yahoo/options.go +++ b/src/engines/yahoo/options.go @@ -11,7 +11,6 @@ var Info engines.Info = engines.Info{ Name: engines.YAHOO, URL: "https://search.yahoo.com/search?p=", ResultsPerPage: 10, - Crawlers: []engines.Name{engines.BING}, } var dompaths engines.DOMPaths = engines.DOMPaths{ diff --git a/src/engines/yep/options.go b/src/engines/yep/options.go index 26a266c3..645d0f02 100644 --- a/src/engines/yep/options.go +++ b/src/engines/yep/options.go @@ -9,7 +9,6 @@ var Info engines.Info = engines.Info{ Name: engines.YEP, URL: "https://api.yep.com/fs/2/search?", ResultsPerPage: 20, - Crawlers: []engines.Name{engines.YEP}, } /*