.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx_engine.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3 Searx (all)
4"""
5
6from json import loads
7from searx.engines import categories as searx_categories
8
9# about
10about = {
11 "website": 'https://github.com/searxng/searxng',
12 "wikidata_id": 'Q17639196',
13 "official_api_documentation": 'https://docs.searxng.org/dev/search_api.html',
14 "use_official_api": True,
15 "require_api_key": False,
16 "results": 'JSON',
17}
18
19categories = searx_categories.keys()
20
21# search-url
22instance_urls = []
23instance_index = 0
24
25
26# do search-request
27def request(query, params):
28 global instance_index # pylint: disable=global-statement
29 params['url'] = instance_urls[instance_index % len(instance_urls)]
30 params['method'] = 'POST'
31
32 instance_index += 1
33
34 params['data'] = {
35 'q': query,
36 'pageno': params['pageno'],
37 'language': params['language'],
38 'time_range': params['time_range'],
39 'category': params['category'],
40 'format': 'json',
41 }
42
43 return params
44
45
46# get response from search-request
47def response(resp):
48
49 response_json = loads(resp.text)
50 results = response_json['results']
51
52 for i in ('answers', 'infoboxes'):
53 results.extend(response_json[i])
54
55 results.extend({'suggestion': s} for s in response_json['suggestions'])
56
57 results.append({'number_of_results': response_json['number_of_results']})
58
59 return results
::1337x
Definition 1337x.py:1