.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.stract Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 
 fetch_traits (EngineTraits engine_traits)
 

Variables

dict about
 
list categories = ['general']
 
bool paging = True
 
str base_url = "https://stract.com/beta/api"
 
str search_url = base_url + "/search"
 

Detailed Description

Stract is an independent open source search engine.  At this state, it's
still in beta and hence this implementation will need to be updated once beta
ends.

Function Documentation

◆ fetch_traits()

searx.engines.stract.fetch_traits ( EngineTraits engine_traits)

Definition at line 63 of file stract.py.

63def fetch_traits(engine_traits: EngineTraits):
64 # pylint: disable=import-outside-toplevel
65 from searx import network
66 from babel import Locale, languages
67 from searx.locales import region_tag
68
69 territories = Locale("en").territories
70
71 json = network.get(base_url + "/docs/openapi.json").json()
72 regions = json['components']['schemas']['Region']['enum']
73
74 engine_traits.all_locale = regions[0]
75
76 for region in regions[1:]:
77 for code, name in territories.items():
78 if region not in (code, name):
79 continue
80 for lang in languages.get_official_languages(code, de_facto=True):
81 engine_traits.regions[region_tag(Locale(lang, code))] = region

◆ request()

searx.engines.stract.request ( query,
params )

Definition at line 28 of file stract.py.

28def request(query, params):
29 params['url'] = search_url
30 params['method'] = "POST"
31 params['headers'] = {
32 'Accept': 'application/json',
33 'Content-Type': 'application/json',
34 'User-Agent': searx_useragent(),
35 }
36 region = traits.get_region(params["searxng_locale"], default=traits.all_locale)
37 params['data'] = dumps(
38 {
39 'query': query,
40 'page': params['pageno'] - 1,
41 'selectedRegion': region,
42 }
43 )
44
45 return params
46
47

◆ response()

searx.engines.stract.response ( resp)

Definition at line 48 of file stract.py.

48def response(resp):
49 results = []
50
51 for result in resp.json()["webpages"]:
52 results.append(
53 {
54 'url': result['url'],
55 'title': result['title'],
56 'content': ''.join(fragment['text'] for fragment in result['snippet']['text']['fragments']),
57 }
58 )
59
60 return results
61
62

Variable Documentation

◆ about

dict searx.engines.stract.about
Initial value:
1= {
2 "website": "https://stract.com/",
3 "use_official_api": True,
4 "official_api_documentation": "https://stract.com/beta/api/docs/#/search/api",
5 "require_api_key": False,
6 "results": "JSON",
7}

Definition at line 12 of file stract.py.

◆ base_url

str searx.engines.stract.base_url = "https://stract.com/beta/api"

Definition at line 22 of file stract.py.

◆ categories

list searx.engines.stract.categories = ['general']

Definition at line 19 of file stract.py.

◆ paging

bool searx.engines.stract.paging = True

Definition at line 20 of file stract.py.

◆ search_url

str searx.engines.stract.search_url = base_url + "/search"

Definition at line 23 of file stract.py.