v0.3.0 #12

Merged
partisan merged 13 commits from work into main 2024-09-29 18:36:46 +00:00
Showing only changes of commit 2679b04284 - Show all commits

View file

@ -41,16 +41,21 @@ var suggestionSources = []SuggestionSource{
FetchFunc: fetchEcosiaSuggestions,
Latency: 50 * time.Millisecond,
},
{
Name: "Qwant",
FetchFunc: fetchQwantSuggestions,
Latency: 50 * time.Millisecond,
},
// { // Not working with fetchSuggestionsFromURL func
// Name: "Qwant",
// FetchFunc: fetchQwantSuggestions,
// Latency: 50 * time.Millisecond,
// },
{
Name: "Startpage",
FetchFunc: fetchStartpageSuggestions,
Latency: 50 * time.Millisecond,
},
{
Name: "Yahoo",
FetchFunc: fetchYahooSuggestions,
Latency: 50 * time.Millisecond,
},
// I advise against it, but you can use it if you want to
// {
// Name: "Google",
@ -161,7 +166,27 @@ func fetchStartpageSuggestions(query string) []string {
return fetchSuggestionsFromURL(url)
}
// fetchSuggestionsFromURL fetches suggestions from the given URL.
func fetchYahooSuggestions(query string) []string {
encodedQuery := url.QueryEscape(query)
url := fmt.Sprintf("https://search.yahoo.com/sugg/gossip/gossip-us-ura/?output=fxjson&command=%s", encodedQuery)
printDebug("Fetching suggestions from Yahoo: %s", url)
return fetchSuggestionsFromURL(url)
}
// func fetchBaiduSuggestions(query string) []string {
// encodedQuery := url.QueryEscape(query)
// url := fmt.Sprintf("https://suggestion.baidu.com/su?wd=%s", encodedQuery)
// printDebug("Fetching suggestions from Baidu: %s", url)
// return fetchSuggestionsFromURL(url)
// }
// func fetchSogouSuggestions(query string) []string {
// encodedQuery := url.QueryEscape(query)
// url := fmt.Sprintf("https://w.sugg.sogou.com/sugg/ajaj_json.jsp?key=%s", encodedQuery)
// printDebug("Fetching suggestions from Sogou: %s", url)
// return fetchSuggestionsFromURL(url)
// }
func fetchSuggestionsFromURL(url string) []string {
resp, err := http.Get(url)
if err != nil {
@ -176,6 +201,9 @@ func fetchSuggestionsFromURL(url string) []string {
return []string{}
}
// Print the raw HTTP response for debugging
fmt.Printf("Raw response from %s:\n%s\n", url, string(body))
// Log the Content-Type for debugging.
contentType := resp.Header.Get("Content-Type")
printDebug("Response Content-Type from %s: %s", url, contentType)
@ -225,3 +253,30 @@ func toJSONStringArray(strings []string) string {
}
return "[" + result + "]"
}
// func testSuggestionSources(query string) {
// for _, source := range suggestionSources {
// fmt.Printf("Testing %s...\n", source.Name)
// // Fetch suggestions
// suggestions := source.FetchFunc(query)
// // If we get results, print them
// if len(suggestions) > 0 {
// fmt.Printf("Suggestions from %s:\n", source.Name)
// for i, suggestion := range suggestions {
// fmt.Printf("%d: %s\n", i+1, suggestion)
// }
// } else {
// fmt.Printf("No suggestions from %s.\n", source.Name)
// }
// // Small separator for clarity
// fmt.Println("--------------------------")
// }
// }
// func main() {
// query := "test query"
// testSuggestionSources(query)
// }