- bug fix: number of results returned matches option
This commit is contained in:
parent
d52bae27ed
commit
d96bba44f0
@ -55,7 +55,7 @@ func main() {
|
||||
|
||||
## 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.
|
||||
|
||||
|
@ -326,6 +326,12 @@ func Search(ctx context.Context, searchTerm string, opts ...SearchOptions) ([]Re
|
||||
if rErr != nil {
|
||||
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
|
||||
}
|
||||
|
||||
@ -351,7 +357,7 @@ func url(searchTerm string, countryCode string, languageCode string, limit int,
|
||||
}
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user