.oO SearXNG Developer Documentation Oo.
|
Functions | |
get_wiki_params (sxng_locale, eng_traits) | |
request (query, params) | |
response (resp) | |
fetch_traits (EngineTraits engine_traits) | |
fetch_wikimedia_traits (EngineTraits engine_traits) | |
Variables | |
dict | about |
list | display_type = ["infobox"] |
bool | send_accept_language_header = True |
str | list_of_wikipedias = 'https://meta.wikimedia.org/wiki/List_of_Wikipedias' |
str | wikipedia_article_depth = 'https://meta.wikimedia.org/wiki/Wikipedia_article_depth' |
str | rest_v1_summary_url = 'https://{wiki_netloc}/api/rest_v1/page/summary/{title}' |
dict | wiki_lc_locale_variants |
dict | wikipedia_script_variants |
lang_map = locales.LOCALE_BEST_MATCH.copy() | |
This module implements the Wikipedia engine. Some of this implementations are shared by other engines: - :ref:`wikidata engine` The list of supported languages is :py:obj:`fetched <fetch_wikimedia_traits>` from the article linked by :py:obj:`list_of_wikipedias`. Unlike traditional search engines, wikipedia does not support one Wikipedia for all languages, but there is one Wikipedia for each supported language. Some of these Wikipedias have a LanguageConverter_ enabled (:py:obj:`rest_v1_summary_url`). A LanguageConverter_ (LC) is a system based on language variants that automatically converts the content of a page into a different variant. A variant is mostly the same language in a different script. - `Wikipedias in multiple writing systems`_ - `Automatic conversion between traditional and simplified Chinese characters`_ PR-2554_: The Wikipedia link returned by the API is still the same in all cases (`https://zh.wikipedia.org/wiki/出租車`_) but if your browser's ``Accept-Language`` is set to any of ``zh``, ``zh-CN``, ``zh-TW``, ``zh-HK`` or .. Wikipedia's LC automatically returns the desired script in their web-page. - You can test the API here: https://reqbin.com/gesg2kvx .. _https://zh.wikipedia.org/wiki/出租車: https://zh.wikipedia.org/wiki/%E5%87%BA%E7%A7%9F%E8%BB%8A To support Wikipedia's LanguageConverter_, a SearXNG request to Wikipedia uses :py:obj:`get_wiki_params` and :py:obj:`wiki_lc_locale_variants' in the :py:obj:`fetch_wikimedia_traits` function. To test in SearXNG, query for ``!wp 出租車`` with each of the available Chinese options: - ``!wp 出租車 :zh`` should show 出租車 - ``!wp 出租車 :zh-CN`` should show 出租车 - ``!wp 出租車 :zh-TW`` should show 計程車 - ``!wp 出租車 :zh-HK`` should show 的士 - ``!wp 出租車 :zh-SG`` should show 德士 .. _LanguageConverter: https://www.mediawiki.org/wiki/Writing_systems#LanguageConverter .. _Wikipedias in multiple writing systems: https://meta.wikimedia.org/wiki/Wikipedias_in_multiple_writing_systems .. _Automatic conversion between traditional and simplified Chinese characters: https://en.wikipedia.org/wiki/Chinese_Wikipedia#Automatic_conversion_between_traditional_and_simplified_Chinese_characters .. _PR-2554: https://github.com/searx/searx/pull/2554
searx.engines.wikipedia.fetch_traits | ( | EngineTraits | engine_traits | ) |
Definition at line 240 of file wikipedia.py.
searx.engines.wikipedia.fetch_wikimedia_traits | ( | EngineTraits | engine_traits | ) |
Fetch languages from Wikipedia. Not all languages from the :py:obj:`list_of_wikipedias` are supported by SearXNG locales, only those known from :py:obj:`searx.locales.LOCALE_NAMES` or those with a minimal :py:obj:`editing depth <wikipedia_article_depth>`. The location of the Wikipedia address of a language is mapped in a :py:obj:`custom field <searx.enginelib.traits.EngineTraits.custom>` (``wiki_netloc``). Here is a reduced example: .. code:: python traits.custom['wiki_netloc'] = { "en": "en.wikipedia.org", .. "gsw": "als.wikipedia.org", .. "zh": "zh.wikipedia.org", "zh-classical": "zh-classical.wikipedia.org" }
Definition at line 245 of file wikipedia.py.
searx.engines.wikipedia.get_wiki_params | ( | sxng_locale, | |
eng_traits ) |
Returns the Wikipedia language tag and the netloc that fits to the ``sxng_locale``. To support LanguageConverter_ this function rates a locale (region) higher than a language (compare :py:obj:`wiki_lc_locale_variants`).
Definition at line 143 of file wikipedia.py.
searx.engines.wikipedia.request | ( | query, | |
params ) |
Assemble a request (`wikipedia rest_v1 summary API`_).
Definition at line 154 of file wikipedia.py.
searx.engines.wikipedia.response | ( | resp | ) |
Definition at line 170 of file wikipedia.py.
dict searx.engines.wikipedia.about |
Definition at line 70 of file wikipedia.py.
list searx.engines.wikipedia.display_type = ["infobox"] |
Definition at line 79 of file wikipedia.py.
searx.engines.wikipedia.lang_map = locales.LOCALE_BEST_MATCH.copy() |
Definition at line 218 of file wikipedia.py.
str searx.engines.wikipedia.list_of_wikipedias = 'https://meta.wikimedia.org/wiki/List_of_Wikipedias' |
Definition at line 88 of file wikipedia.py.
str searx.engines.wikipedia.rest_v1_summary_url = 'https://{wiki_netloc}/api/rest_v1/page/summary/{title}' |
Definition at line 99 of file wikipedia.py.
bool searx.engines.wikipedia.send_accept_language_header = True |
Definition at line 84 of file wikipedia.py.
dict searx.engines.wikipedia.wiki_lc_locale_variants |
Definition at line 116 of file wikipedia.py.
str searx.engines.wikipedia.wikipedia_article_depth = 'https://meta.wikimedia.org/wiki/Wikipedia_article_depth' |
Definition at line 92 of file wikipedia.py.
dict searx.engines.wikipedia.wikipedia_script_variants |
Definition at line 135 of file wikipedia.py.