From eef58c9c1b8c793f49c62d63c33eff4d9fe5e9f7 Mon Sep 17 00:00:00 2001 From: rocketlaunchr-cto Date: Sun, 4 Oct 2020 12:00:55 +1100 Subject: [PATCH] - add overLimit feature --- search.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/search.go b/search.go index 122e8ce..04cfcc3 100644 --- a/search.go +++ b/search.go @@ -248,6 +248,10 @@ type SearchOptions struct { // UserAgent sets the UserAgent of the http request. // Default: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" UserAgent string + + // OverLimit searches for more results than that specified by Limit. + // It then reduces the returned results to match Limit. + OverLimit bool } // Search returns a list of search results from Google. @@ -320,7 +324,12 @@ func Search(ctx context.Context, searchTerm string, opts ...SearchOptions) ([]Re } }) - url := url(searchTerm, opts[0].CountryCode, lc, opts[0].Limit, opts[0].Start) + limit := opts[0].Limit + if opts[0].OverLimit { + limit = int(float64(opts[0].Limit) * 1.5) + } + + url := url(searchTerm, opts[0].CountryCode, lc, limit, opts[0].Start) c.Visit(url) if rErr != nil { @@ -357,7 +366,7 @@ func url(searchTerm string, countryCode string, languageCode string, limit int, } if limit != 0 { - url = fmt.Sprintf("%s&num=%d", url, int(float64(limit)*1.5)) // Factor in ads etc + url = fmt.Sprintf("%s&num=%d", url, limit) } return url