summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2021-05-23 13:20:48 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2021-05-23 15:05:36 +0200
commit1933577c8e0a7635894439e278ccec5e3b284568 (patch)
tree57bf8a9228a78244330acfd908051994dc0bd2b5 /searx
parent2065a324d9ac53ca8ede30ce9746ed92bb3d5db0 (diff)
downloadsearxng-1933577c8e0a7635894439e278ccec5e3b284568.tar.gz
searxng-1933577c8e0a7635894439e278ccec5e3b284568.zip
[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 <markus.heiser@darmarit.de>
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/xpath.py22
1 files 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'])