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

Functions

 locale_to_lang_code (locale)
 
 get_lang_urls (language)
 
 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['it', 'software wikis']
 
bool paging = True
 
str base_url = 'https://wiki.gentoo.org'
 
str xpath_results = '//ul[@class="mw-search-results"]/li'
 
str xpath_link = './/div[@class="mw-search-result-heading"]/a'
 
str xpath_content = './/div[@class="searchresult"]'
 
dict lang_urls
 
dict main_langs
 

Detailed Description

 Gentoo Wiki

Function Documentation

◆ get_lang_urls()

searx.engines.gentoo.get_lang_urls ( language)

Definition at line 51 of file gentoo.py.

51def get_lang_urls(language):
52 if language != 'en':
53 return lang_urls['others']
54 return lang_urls['en']
55
56
57# Language names to build search requests for
58# those languages which are hosted on the main site.

Referenced by searx.engines.gentoo.request(), and searx.engines.gentoo.response().

+ Here is the caller graph for this function:

◆ locale_to_lang_code()

searx.engines.gentoo.locale_to_lang_code ( locale)

Definition at line 32 of file gentoo.py.

32def locale_to_lang_code(locale):
33 if locale.find('-') >= 0:
34 locale = locale.split('-')[0]
35 return locale
36
37
38# wikis for some languages were moved off from the main site, we need to make
39# requests to correct URLs to be able to get results in those languages

Referenced by searx.engines.gentoo.request(), and searx.engines.gentoo.response().

+ Here is the caller graph for this function:

◆ request()

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

Definition at line 84 of file gentoo.py.

84def request(query, params):
85 # translate the locale (e.g. 'en-US') to language code ('en')
86 language = locale_to_lang_code(params['language'])
87
88 # if our language is hosted on the main site, we need to add its name
89 # to the query in order to narrow the results to that language
90 if language in main_langs:
91 query += ' (' + main_langs[language] + ')'
92
93 # prepare the request parameters
94 query = urlencode({'search': query})
95 offset = (params['pageno'] - 1) * 20
96
97 # get request URLs for our language of choice
98 urls = get_lang_urls(language)
99 search_url = urls['base'] + urls['search']
100
101 params['url'] = search_url.format(query=query, offset=offset, language=language)
102
103 return params
104
105
106# get response from search-request

References searx.engines.gentoo.get_lang_urls(), and searx.engines.gentoo.locale_to_lang_code().

+ Here is the call graph for this function:

◆ response()

searx.engines.gentoo.response ( resp)

Definition at line 107 of file gentoo.py.

107def response(resp):
108 # get the base URL for the language in which request was made
109 language = locale_to_lang_code(resp.search_params['language'])
110 url = get_lang_urls(language)['base']
111
112 results = []
113
114 dom = html.fromstring(resp.text)
115
116 # parse results
117 for result in dom.xpath(xpath_results):
118 link = result.xpath(xpath_link)[0]
119 href = urljoin(url, link.attrib.get('href'))
120 title = extract_text(link)
121 content = extract_text(result.xpath(xpath_content))
122
123 results.append({'url': href, 'title': title, 'content': content})
124
125 return results

References searx.engines.gentoo.get_lang_urls(), and searx.engines.gentoo.locale_to_lang_code().

+ Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.gentoo.about
Initial value:
1= {
2 "website": 'https://wiki.gentoo.org/',
3 "wikidata_id": 'Q1050637',
4 "official_api_documentation": 'https://wiki.gentoo.org/api.php',
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'HTML',
8}

Definition at line 11 of file gentoo.py.

◆ base_url

str searx.engines.gentoo.base_url = 'https://wiki.gentoo.org'

Definition at line 23 of file gentoo.py.

◆ categories

list searx.engines.gentoo.categories = ['it', 'software wikis']

Definition at line 21 of file gentoo.py.

◆ lang_urls

dict searx.engines.gentoo.lang_urls
Initial value:
1= {
2 'en': {'base': 'https://wiki.gentoo.org', 'search': '/index.php?title=Special:Search&offset={offset}&{query}'},
3 'others': {
4 'base': 'https://wiki.gentoo.org',
5 'search': '/index.php?title=Special:Search&offset={offset}&{query}\
6 &profile=translation&languagefilter={language}',
7 },
8}

Definition at line 40 of file gentoo.py.

◆ main_langs

dict searx.engines.gentoo.main_langs
Initial value:
1= {
2 'ar': 'العربية',
3 'bg': 'Български',
4 'cs': 'Česky',
5 'da': 'Dansk',
6 'el': 'Ελληνικά',
7 'es': 'Español',
8 'he': 'עברית',
9 'hr': 'Hrvatski',
10 'hu': 'Magyar',
11 'it': 'Italiano',
12 'ko': '한국어',
13 'lt': 'Lietuviškai',
14 'nl': 'Nederlands',
15 'pl': 'Polski',
16 'pt': 'Português',
17 'ru': 'Русский',
18 'sl': 'Slovenský',
19 'th': 'ไทย',
20 'uk': 'Українська',
21 'zh': '简体中文',
22}

Definition at line 59 of file gentoo.py.

◆ paging

bool searx.engines.gentoo.paging = True

Definition at line 22 of file gentoo.py.

◆ xpath_content

str searx.engines.gentoo.xpath_content = './/div[@class="searchresult"]'

Definition at line 28 of file gentoo.py.

◆ xpath_link

str searx.engines.gentoo.xpath_link = './/div[@class="mw-search-result-heading"]/a'

Definition at line 27 of file gentoo.py.

◆ xpath_results

str searx.engines.gentoo.xpath_results = '//ul[@class="mw-search-results"]/li'

Definition at line 26 of file gentoo.py.