diff options
| author | Marc Abonce Seguin <marc-abonce@mailbox.org> | 2018-02-28 22:30:48 -0600 |
|---|---|---|
| committer | Marc Abonce Seguin <marc-abonce@mailbox.org> | 2018-03-27 00:08:03 -0600 |
| commit | 772c048d01c7585fd60afca1ce30a1914e6e5b4a (patch) | |
| tree | 96a5662897df2bcf0ab53456e0a67ace998f2169 /searx/engines/bing.py | |
| parent | d1eae9359f8c5920632a730744ea2208070f06da (diff) | |
refactor engine's search language handling
Add match_language function in utils to match any user given
language code with a list of engine's supported languages.
Also add language_aliases dict on each engine to translate
standard language codes into the custom codes used by the engine.
Diffstat (limited to 'searx/engines/bing.py')
| -rw-r--r-- | searx/engines/bing.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/searx/engines/bing.py b/searx/engines/bing.py index 2e58d0293..c6d41782b 100644 --- a/searx/engines/bing.py +++ b/searx/engines/bing.py @@ -16,12 +16,14 @@ from lxml import html from searx.engines.xpath import extract_text from searx.url_utils import urlencode +from searx.utils import match_language # engine dependent config categories = ['general'] paging = True language_support = True supported_languages_url = 'https://www.bing.com/account/general' +language_aliases = {'zh-CN': 'zh-CHS', 'zh-TW': 'zh-CHT', 'zh-HK': 'zh-CHT'} # search-url base_url = 'https://www.bing.com/' @@ -32,9 +34,9 @@ search_string = 'search?{query}&first={offset}' def request(query, params): offset = (params['pageno'] - 1) * 10 + 1 - lang = params['language'].split('-')[0].upper() + lang = match_language(params['language'], supported_languages, language_aliases) - query = u'language:{} {}'.format(lang, query.decode('utf-8')).encode('utf-8') + query = u'language:{} {}'.format(lang.split('-')[0].upper(), query.decode('utf-8')).encode('utf-8') search_path = search_string.format( query=urlencode({'q': query}), |