- bug fix: number of results returned matches option

This commit is contained in:
rocketlaunchr-cto 2020-10-04 11:50:04 +11:00
parent d52bae27ed
commit d96bba44f0
2 changed files with 8 additions and 2 deletions

View File

@ -55,7 +55,7 @@ func main() {
## Warning ## Warning
The implementation relies on Google's search page DOM being constant. If it changes, then the implementation will break. Having said that, it hasn't changed for years. The implementation relies on Google's search page DOM being constant. From time to time, Google changes their DOM and thus breaks the implementation.
In the event it changes, this package will be updated as soon as possible. In the event it changes, this package will be updated as soon as possible.

View File

@ -326,6 +326,12 @@ func Search(ctx context.Context, searchTerm string, opts ...SearchOptions) ([]Re
if rErr != nil { if rErr != nil {
return nil, rErr return nil, rErr
} }
// Reduce results to max limit
if opts[0].Limit != 0 && len(results) > opts[0].Limit {
return results[:opts[0].Limit], nil
}
return results, nil return results, nil
} }
@ -351,7 +357,7 @@ func url(searchTerm string, countryCode string, languageCode string, limit int,
} }
if limit != 0 { if limit != 0 {
url = fmt.Sprintf("%s&num=%d", url, limit) url = fmt.Sprintf("%s&num=%d", url, int(float64(limit)*1.5)) // Factor in ads etc
} }
return url return url