From 1c67b6aecea8d9c7276fc1d7bef585bc4118f255 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sun, 6 Jun 2021 08:18:07 +0200 Subject: [enh] google engine: supports "default language" Same behaviour behaviour than Whoogle [1]. Only the google engine with the "Default language" choice "(all)"" is changed by this patch. When searching for a locate place, the result are in the expect language, without missing results [2]: > When a language is not specified, the language interpretation is left up to > Google to decide how the search results should be delivered. The query parameters are copied from Whoogle. With the ``all`` language: - add parameter ``source=lnt`` - don't use parameter ``lr`` - don't add a ``Accept-Language`` HTTP header. The new signature of function ``get_lang_info()`` is: lang_info = get_lang_info(params, lang_list, custom_aliases, supported_any_language) Argument ``supported_any_language`` is True for google.py and False for the other google engines. With this patch the function now returns: - query parameters: ``lang_info['params']`` - HTTP headers: ``lang_info['headers']`` - and as before this patch: - ``lang_info['subdomain']`` - ``lang_info['country']`` - ``lang_info['language']`` [1] https://github.com/benbusby/whoogle-search [2] https://github.com/benbusby/whoogle-search/releases/tag/v0.5.4 --- searx/engines/google_scholar.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'searx/engines/google_scholar.py') diff --git a/searx/engines/google_scholar.py b/searx/engines/google_scholar.py index a0ca70e53..fbf443e2e 100644 --- a/searx/engines/google_scholar.py +++ b/searx/engines/google_scholar.py @@ -81,15 +81,14 @@ def request(query, params): # params, {}, language_aliases - params, supported_languages, language_aliases + params, supported_languages, language_aliases, False ) # subdomain is: scholar.google.xy lang_info['subdomain'] = lang_info['subdomain'].replace("www.", "scholar.") query_url = 'https://'+ lang_info['subdomain'] + '/scholar' + "?" + urlencode({ 'q': query, - 'hl': lang_info['hl'], - 'lr': lang_info['lr'], + **lang_info['params'], 'ie': "utf8", 'oe': "utf8", 'start' : offset, @@ -100,8 +99,8 @@ def request(query, params): logger.debug("query_url --> %s", query_url) params['url'] = query_url - logger.debug("HTTP header Accept-Language --> %s", lang_info['Accept-Language']) - params['headers']['Accept-Language'] = lang_info['Accept-Language'] + logger.debug("HTTP header Accept-Language --> %s", lang_info.get('Accept-Language')) + params['headers'].update(lang_info['headers']) params['headers']['Accept'] = ( 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' ) -- cgit v1.2.3 From 2ac3e5b20b50045574d55ff01cfa19f3ca9da8b9 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Fri, 11 Jun 2021 16:31:50 +0200 Subject: [fix] log messages from: google- images, news, scholar, videos - HTTP header Accept-Language --> lang_info['headers']['Accept-Language'] - remove obsolete query_url log messages which is already logged by httpx._client:HTTP request Signed-off-by: Markus Heiser --- searx/engines/google_scholar.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'searx/engines/google_scholar.py') diff --git a/searx/engines/google_scholar.py b/searx/engines/google_scholar.py index fbf443e2e..8442a7bfa 100644 --- a/searx/engines/google_scholar.py +++ b/searx/engines/google_scholar.py @@ -77,12 +77,11 @@ def request(query, params): offset = (params['pageno'] - 1) * 10 lang_info = get_lang_info( # pylint: disable=undefined-variable - - - # params, {}, language_aliases - params, supported_languages, language_aliases, False ) + logger.debug( + "HTTP header Accept-Language --> %s", lang_info['headers']['Accept-Language']) + # subdomain is: scholar.google.xy lang_info['subdomain'] = lang_info['subdomain'].replace("www.", "scholar.") @@ -95,11 +94,8 @@ def request(query, params): }) query_url += time_range_url(params) - - logger.debug("query_url --> %s", query_url) params['url'] = query_url - logger.debug("HTTP header Accept-Language --> %s", lang_info.get('Accept-Language')) params['headers'].update(lang_info['headers']) params['headers']['Accept'] = ( 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -- cgit v1.2.3