From d96bba44f009e6d0fb493667292854fe447568cf Mon Sep 17 00:00:00 2001 From: rocketlaunchr-cto Date: Sun, 4 Oct 2020 11:50:04 +1100 Subject: [PATCH] - bug fix: number of results returned matches option --- README.md | 2 +- search.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4d2deb8..657a93a 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/search.go b/search.go index 8aea829..122e8ce 100644 --- a/search.go +++ b/search.go @@ -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