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)