@@ -5,10 +5,10 @@
5# pylint: disable=missing-function-docstring, invalid-name
5# pylint: disable=missing-function-docstring, invalid-name
8−from json import loads
8+from json import loads, JSONDecodeError
9from urllib.parse import urlencode
9from urllib.parse import urlencode
10−# from searx import logger
11from searx.network import get
10from searx.network import get
11+from searx.exceptions import SearxEngineResponseException
@@ -22,6 +22,9 @@ about = {
23# engine dependent config
23# engine dependent config
24categories = ['general']
24categories = ['general']
25# gigablast's pagination is totally damaged, don't use it
28# gigablast's pagination is totally damaged, don't use it
26paging = False
29paging = False
27safesearch = True
30safesearch = True
@@ -34,6 +37,8 @@ base_url = 'https://gigablast.com'
34extra_param = ''
37extra_param = ''
35extra_param_path='/search?c=main&qlangcountry=en-us&q=south&s=10'
38extra_param_path='/search?c=main&qlangcountry=en-us&q=south&s=10'
40+_wait_for_results_msg = 'Loading results takes too long. Please enable fast option in gigablast engine.'
37def parse_extra_param(text):
42def parse_extra_param(text):
39 # example:
44 # example:
@@ -54,7 +59,6 @@ def parse_extra_param(text):
54 if re_var is not None and re_var.search(line):
59 if re_var is not None and re_var.search(line):
55 extra_param += re_var.search(line).group(1)
60 extra_param += re_var.search(line).group(1)
57− # logger.debug('gigablast extra_param="%s"', extra_param)
59def init(engine_settings=None): # pylint: disable=unused-argument
63def init(engine_settings=None): # pylint: disable=unused-argument
60 parse_extra_param(get(base_url + extra_param_path).text)
64 parse_extra_param(get(base_url + extra_param_path).text)
@@ -65,14 +69,17 @@ def request(query, params): # pylint: disable=unused-argument
66 # see API http://www.gigablast.com/api.html#/search
70 # see API http://www.gigablast.com/api.html#/search
67 # Take into account, that the API has some quirks ..
71 # Take into account, that the API has some quirks ..
69− query_args = dict(
72+ query_args = {
70− c = 'main'
73+ 'c': collections,
71− , format = 'json'
74+ 'format': 'json',
72− , q = query
75+ 'q': query,
73− , dr = 1
76+ 'dr': 1 ,
74− , showgoodimages = 0
77+ 'showgoodimages': 0,
81+ if search_type != '':
82+ query_args['searchtype'] = search_type
77 if params['language'] and params['language'] != 'all':
84 if params['language'] and params['language'] != 'all':
78 query_args['qlangcountry'] = params['language']
85 query_args['qlangcountry'] = params['language']
@@ -90,9 +97,13 @@ def request(query, params): # pylint: disable=unused-argument
90def response(resp):
97def response(resp):
91 results = []
98 results = []
93− response_json = loads(resp.text)
101+ response_json = loads(resp.text)
102+ except JSONDecodeError as e:
103+ if 'Waiting for results' in resp.text:
104+ raise SearxEngineResponseException(message=_wait_for_results_msg) # pylint: disable=raise-missing-from
95− # logger.debug('gigablast returns %s results', len(response_json['results']))
97 for result in response_json['results']:
108 for result in response_json['results']:
98 # see "Example JSON Output (&format=json)"
109 # see "Example JSON Output (&format=json)"