From 731ad7f7126078816069b93ba013e2fb06e738c8 Mon Sep 17 00:00:00 2001 From: CZmisaCZ <50033306+CZmisaCZ@users.noreply.github.com> Date: Sun, 16 Jun 2024 01:30:18 +0200 Subject: [PATCH] this is stupid --- text.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/text.go b/text.go index 6d75b3b..ce021ba 100644 --- a/text.go +++ b/text.go @@ -101,9 +101,7 @@ func fetchTextResults(query, safe, lang string, page int) []TextSearchResult { continue } - for _, result := range searchResults { - results = append(results, result.(TextSearchResult)) - } + results = append(results, validateResults(searchResults)...) // If results are found, break out of the loop if len(results) > 0 { @@ -114,6 +112,20 @@ func fetchTextResults(query, safe, lang string, page int) []TextSearchResult { return results } +func validateResults(searchResults []SearchResult) []TextSearchResult { + var validResults []TextSearchResult + + // Remove anything that is missing a URL or Header + for _, result := range searchResults { + textResult := result.(TextSearchResult) + if textResult.URL != "" || textResult.Header != "" { + validResults = append(validResults, textResult) + } + } + + return validResults +} + func wrapTextSearchFunc(f func(string, string, string, int) ([]TextSearchResult, time.Duration, error)) func(string, string, string, int) ([]SearchResult, time.Duration, error) { return func(query, safe, lang string, page int) ([]SearchResult, time.Duration, error) { textResults, duration, err := f(query, safe, lang, page)