From 1933577c8e0a7635894439e278ccec5e3b284568 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 23 May 2021 13:20:48 +0200 Subject: [PATCH] [enh] XPath engine - add ISO 639-1 {lang} replacement to search-URL BTW: remove obsolte params['query'] and not needed paging condition. Signed-off-by: Markus Heiser --- searx/engines/xpath.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/searx/engines/xpath.py b/searx/engines/xpath.py index 920adf4c6..8c2b2d0a2 100644 --- a/searx/engines/xpath.py +++ b/searx/engines/xpath.py @@ -37,8 +37,15 @@ Search URL of the engine, replacements are: ``{pageno}``: Page number if engine supports pagging :py:obj:`paging` +``{lang}``: + ISO 639-1 language code (en, de, fr ..) """ +lang_all='en' +'''Replacement ``{lang}`` in :py:obj:`search_url` if language ``all`` is +selected. +''' + soft_max_redirects = 0 '''Maximum redirects, soft limit. Record an error but don't stop the engine''' @@ -77,14 +84,15 @@ def request(query, params): '''Build request parameters (see :ref:`engine request`). ''' - query = urlencode({'q': query})[2:] - - fargs = {'query': query} - if paging and search_url.find('{pageno}') >= 0: - fargs['pageno'] = (params['pageno'] - 1) * page_size + first_page_num - + lang = lang_all + if params['language'] != 'all': + lang = params['language'][:2] + fargs = { + 'query': urlencode({'q': query})[2:], + 'lang': lang, + 'pageno': (params['pageno'] - 1) * page_size + first_page_num + } params['url'] = search_url.format(**fargs) - params['query'] = query params['soft_max_redirects'] = soft_max_redirects logger.debug("query_url --> %s", params['url'])