Skip to content

Commit

Permalink
Merge pull request #188 from hearchco/names
Browse files Browse the repository at this point in the history
fix: refactor some engines.Names and config defaults logic
  • Loading branch information
k4lizen authored Feb 7, 2024
2 parents ea5ff1f + 79e3c90 commit 6f66cd9
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 100 deletions.
123 changes: 38 additions & 85 deletions src/config/defaults.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"log"
"time"

"github.com/hearchco/hearchco/src/category"
Expand All @@ -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",
},
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/engines/bing/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion src/engines/brave/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion src/engines/duckduckgo/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion src/engines/etools/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, engines.YANDEX},
}

var dompaths engines.DOMPaths = engines.DOMPaths{
Expand Down
1 change: 0 additions & 1 deletion src/engines/google/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion src/engines/googlescholar/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion src/engines/mojeek/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 5 additions & 1 deletion src/engines/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ const (
STARTPAGE
SWISSCOWS
YAHOO
YANDEX
YEP
)

// Returns Engine Names without UNDEFINED
func Names() []Name {
return _NameValues[1:]

Check failure on line 28 in src/engines/name.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: _NameValues
}

func (n Name) ToLower() string {
return strings.ToLower(n.String())

Check failure on line 32 in src/engines/name.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

n.String undefined (type Name has no field or method String)
}
1 change: 0 additions & 1 deletion src/engines/presearch/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}

/*
Expand Down
1 change: 0 additions & 1 deletion src/engines/qwant/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion src/engines/startpage/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion src/engines/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type Info struct {
Name Name
URL string
ResultsPerPage int
Crawlers []Name
}

type DOMPaths struct {
Expand Down
1 change: 0 additions & 1 deletion src/engines/swisscows/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion src/engines/yahoo/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 0 additions & 1 deletion src/engines/yep/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}

/*
Expand Down

0 comments on commit 6f66cd9

Please sign in to comment.