removed results loging + added logs for no results returned where missing + improved image fetching
This commit is contained in:
parent
a138928d63
commit
87ac6f05f9
5 changed files with 19 additions and 14 deletions
14
images.go
14
images.go
|
@ -97,15 +97,11 @@ func getImageResultsFromCacheOrFetch(cacheKey CacheKey, query, safe, lang string
|
|||
|
||||
func fetchImageResults(query, safe, lang string, page int) []ImageSearchResult {
|
||||
var results []ImageSearchResult
|
||||
var err error
|
||||
var duration time.Duration
|
||||
|
||||
for attempts := 0; attempts < len(imageSearchEngines); attempts++ {
|
||||
engine := selectSearchEngine(imageSearchEngines)
|
||||
for _, engine := range imageSearchEngines {
|
||||
log.Printf("Using image search engine: %s", engine.Name)
|
||||
|
||||
var searchResults []SearchResult
|
||||
searchResults, duration, err = engine.Func(query, safe, lang, page)
|
||||
searchResults, duration, err := engine.Func(query, safe, lang, page)
|
||||
updateEngineMetrics(&engine, duration, err == nil)
|
||||
if err != nil {
|
||||
log.Printf("Error performing image search with %s: %v", engine.Name, err)
|
||||
|
@ -116,11 +112,17 @@ func fetchImageResults(query, safe, lang string, page int) []ImageSearchResult {
|
|||
results = append(results, result.(ImageSearchResult))
|
||||
}
|
||||
|
||||
// If results are found, break out of the loop
|
||||
if len(results) > 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If no results found after trying all engines
|
||||
if len(results) == 0 {
|
||||
log.Printf("No image results found for query: %s", query)
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
|
|
|
@ -69,5 +69,10 @@ func PerformBraveTextSearch(query, safe, lang string, offset int) ([]TextSearchR
|
|||
|
||||
duration := time.Since(startTime) // Calculate the duration
|
||||
|
||||
// Return an error if no results are found
|
||||
if len(results) == 0 {
|
||||
return nil, duration, fmt.Errorf("no results found")
|
||||
}
|
||||
|
||||
return results, duration, nil
|
||||
}
|
||||
|
|
|
@ -31,10 +31,6 @@ func PerformGoogleTextSearch(query, safe, lang string, page int) ([]TextSearchRe
|
|||
return nil, 0, err
|
||||
}
|
||||
|
||||
if debugMode {
|
||||
fmt.Println("Generated User Agent (text):", TextUserAgent)
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", TextUserAgent)
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
|
|
@ -34,10 +34,6 @@ func PerformLibreXTextSearch(query, safe, lang string, page int) ([]TextSearchRe
|
|||
return nil, 0, err
|
||||
}
|
||||
|
||||
if debugMode {
|
||||
log.Println("Generated User Agent (text):", userAgent)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", searchURL, nil)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
@ -74,9 +70,14 @@ func PerformLibreXTextSearch(query, safe, lang string, page int) ([]TextSearchRe
|
|||
|
||||
duration := time.Since(startTime) // Calculate the duration
|
||||
|
||||
if len(results) == 0 {
|
||||
return nil, duration, fmt.Errorf("no results found")
|
||||
}
|
||||
|
||||
return results, duration, nil
|
||||
}
|
||||
|
||||
// This is just stupid it will probbably lead to printing error twice
|
||||
func logError(message string, err error) error {
|
||||
log.Printf("%s: %v", message, err)
|
||||
return fmt.Errorf("%s: %w", message, err)
|
||||
|
|
1
text.go
1
text.go
|
@ -105,6 +105,7 @@ func fetchTextResults(query, safe, lang string, page int) []TextSearchResult {
|
|||
results = append(results, result.(TextSearchResult))
|
||||
}
|
||||
|
||||
// If results are found, break out of the loop
|
||||
if len(results) > 0 {
|
||||
break
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue