logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git
commit: b9a9abe10d569f15755bf8a6833adc9f425a2b2d
parent 371fc09b6f2afa9e4f0b3a367760c407615b8e53
Author: Thomas Pointhuber <thomas.pointhuber@gmx.at>
Date:   Wed, 23 Dec 2015 18:43:35 +0100

[enh] improve gigablast engine
add language and safesearch support

Diffstat:

Msearx/engines/gigablast.py39++++++++++++++++++++++++++++++---------
Msearx/tests/engines/test_gigablast.py1+
2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/searx/engines/gigablast.py b/searx/engines/gigablast.py @@ -19,11 +19,21 @@ from time import time # engine dependent config categories = ['general'] paging = True -number_of_results = 5 +number_of_results = 10 +language_support = True +safesearch = True -# search-url, invalid HTTPS certificate +# search-url base_url = 'https://gigablast.com/' -search_string = 'search?{query}&n={number_of_results}&s={offset}&format=xml&qh=0&rxiyd={rxiyd}&rand={rand}' +search_string = 'search?{query}'\ + '&n={number_of_results}'\ + '&s={offset}'\ + '&format=xml'\ + '&qh=0'\ + '&rxiyd={rxiyd}'\ + '&rand={rand}'\ + '&qlang={lang}'\ + '&ff={safesearch}' # specific xpath variables results_xpath = '//response//result' @@ -36,12 +46,23 @@ content_xpath = './/sum' def request(query, params): offset = (params['pageno'] - 1) * number_of_results - search_path = search_string.format( - query=urlencode({'q': query}), - offset=offset, - number_of_results=number_of_results, - rxiyd=randint(10000, 10000000), - rand=int(time())) + if params['language'] == 'all': + language = 'xx' + else: + language = params['language'][0:2] + + if params['safesearch'] >= 1: + safesearch = 1 + else: + safesearch = 0 + + search_path = search_string.format(query=urlencode({'q': query}), + offset=offset, + number_of_results=number_of_results, + rxiyd=randint(10000, 10000000), + rand=int(time()), + lang=language, + safesearch=safesearch) params['url'] = base_url + search_path diff --git a/searx/tests/engines/test_gigablast.py b/searx/tests/engines/test_gigablast.py @@ -10,6 +10,7 @@ class TestGigablastEngine(SearxTestCase): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 0 + dicto['language'] = 'all' params = gigablast.request(query, dicto) self.assertTrue('url' in params) self.assertTrue(query in params['url'])