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

Functions

 init (_)
 
 request (query, params)
 
 _general_results (dom)
 
 _image_results (dom)
 
 _news_results (dom)
 
 response (resp)
 
 fetch_traits (EngineTraits engine_traits)
 

Variables

dict about
 
bool paging = True
 
bool safesearch = True
 
bool time_range_support = True
 
int max_page = 10
 
str base_url = "https://www.mojeek.com"
 
list categories = ["general", "web"]
 
str search_type = ""
 
str results_xpath = '//ul[@class="results-standard"]/li/a[@class="ob"]'
 
str url_xpath = './@href'
 
str title_xpath = '../h2/a'
 
str content_xpath = '..//p[@class="s"]'
 
str suggestion_xpath = '//div[@class="top-info"]/p[@class="top-info spell"]/em/a'
 
str image_results_xpath = '//div[@id="results"]/div[contains(@class, "image")]'
 
str image_url_xpath = './a/@href'
 
str image_title_xpath = './a/@data-title'
 
str image_img_src_xpath = './a/img/@src'
 
str news_results_xpath = '//section[contains(@class, "news-search-result")]//article'
 
str news_url_xpath = './/h2/a/@href'
 
str news_title_xpath = './/h2/a'
 
str news_content_xpath = './/p[@class="s"]'
 
str language_param = 'lb'
 
str region_param = 'arc'
 
dict _delta_kwargs = {'day': 'days', 'week': 'weeks', 'month': 'months', 'year': 'years'}
 
 logger = logging.getLogger()
 

Detailed Description

Mojeek (general, images, news)

Function Documentation

◆ _general_results()

searx.engines.mojeek._general_results ( dom)
protected

Definition at line 88 of file mojeek.py.

88def _general_results(dom):
89 results = []
90
91 for result in eval_xpath_list(dom, results_xpath):
92 results.append(
93 {
94 'url': extract_text(eval_xpath(result, url_xpath)),
95 'title': extract_text(eval_xpath(result, title_xpath)),
96 'content': extract_text(eval_xpath(result, content_xpath)),
97 }
98 )
99
100 for suggestion in eval_xpath(dom, suggestion_xpath):
101 results.append({'suggestion': extract_text(suggestion)})
102
103 return results
104
105

Referenced by searx.engines.mojeek.response().

+ Here is the caller graph for this function:

◆ _image_results()

searx.engines.mojeek._image_results ( dom)
protected

Definition at line 106 of file mojeek.py.

106def _image_results(dom):
107 results = []
108
109 for result in eval_xpath_list(dom, image_results_xpath):
110 results.append(
111 {
112 'template': 'images.html',
113 'url': extract_text(eval_xpath(result, image_url_xpath)),
114 'title': extract_text(eval_xpath(result, image_title_xpath)),
115 'img_src': base_url + extract_text(eval_xpath(result, image_img_src_xpath)), # type: ignore
116 'content': '',
117 }
118 )
119
120 return results
121
122

Referenced by searx.engines.mojeek.response().

+ Here is the caller graph for this function:

◆ _news_results()

searx.engines.mojeek._news_results ( dom)
protected

Definition at line 123 of file mojeek.py.

123def _news_results(dom):
124 results = []
125
126 for result in eval_xpath_list(dom, news_results_xpath):
127 results.append(
128 {
129 'url': extract_text(eval_xpath(result, news_url_xpath)),
130 'title': extract_text(eval_xpath(result, news_title_xpath)),
131 'content': extract_text(eval_xpath(result, news_content_xpath)),
132 }
133 )
134
135 return results
136
137

Referenced by searx.engines.mojeek.response().

+ Here is the caller graph for this function:

◆ fetch_traits()

searx.engines.mojeek.fetch_traits ( EngineTraits engine_traits)

Definition at line 153 of file mojeek.py.

153def fetch_traits(engine_traits: EngineTraits):
154 # pylint: disable=import-outside-toplevel
155 from searx import network
156 from searx.locales import get_official_locales, region_tag
157 from babel import Locale, UnknownLocaleError
158 import contextlib
159
160 resp = network.get(base_url + "/preferences", headers={'Accept-Language': 'en-US,en;q=0.5'})
161 dom = html.fromstring(resp.text) # type: ignore
162
163 languages = eval_xpath_list(dom, f'//select[@name="{language_param}"]/option/@value')
164
165 engine_traits.custom['language_all'] = languages[0]
166
167 for code in languages[1:]:
168 with contextlib.suppress(UnknownLocaleError):
169 locale = Locale(code)
170 engine_traits.languages[locale.language] = code
171
172 regions = eval_xpath_list(dom, f'//select[@name="{region_param}"]/option/@value')
173
174 engine_traits.custom['region_all'] = regions[1]
175
176 for code in regions[2:]:
177 for locale in get_official_locales(code, engine_traits.languages):
178 engine_traits.regions[region_tag(locale)] = code

◆ init()

searx.engines.mojeek.init ( _)

Definition at line 61 of file mojeek.py.

61def init(_):
62 if search_type not in ('', 'images', 'news'):
63 raise ValueError(f"Invalid search type {search_type}")
64
65

◆ request()

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

Definition at line 66 of file mojeek.py.

66def request(query, params):
67 args = {
68 'q': query,
69 'safe': min(params['safesearch'], 1),
70 'fmt': search_type,
71 language_param: traits.get_language(params['searxng_locale'], traits.custom['language_all']),
72 region_param: traits.get_region(params['searxng_locale'], traits.custom['region_all']),
73 }
74
75 if search_type == '':
76 args['s'] = 10 * (params['pageno'] - 1)
77
78 if params['time_range'] and search_type != 'images':
79 kwargs = {_delta_kwargs[params['time_range']]: 1}
80 args["since"] = (datetime.now() - relativedelta(**kwargs)).strftime("%Y%m%d") # type: ignore
81 logger.debug(args["since"])
82
83 params['url'] = f"{base_url}/search?{urlencode(args)}"
84
85 return params
86
87

◆ response()

searx.engines.mojeek.response ( resp)

Definition at line 138 of file mojeek.py.

138def response(resp):
139 dom = html.fromstring(resp.text)
140
141 if search_type == '':
142 return _general_results(dom)
143
144 if search_type == 'images':
145 return _image_results(dom)
146
147 if search_type == 'news':
148 return _news_results(dom)
149
150 raise ValueError(f"Invalid search type {search_type}")
151
152

References searx.engines.mojeek._general_results(), searx.engines.mojeek._image_results(), and searx.engines.mojeek._news_results().

+ Here is the call graph for this function:

Variable Documentation

◆ _delta_kwargs

dict searx.engines.mojeek._delta_kwargs = {'day': 'days', 'week': 'weeks', 'month': 'months', 'year': 'years'}
protected

Definition at line 51 of file mojeek.py.

◆ about

dict searx.engines.mojeek.about
Initial value:
1= {
2 'website': 'https://mojeek.com',
3 'wikidata_id': 'Q60747299',
4 'official_api_documentation': 'https://www.mojeek.com/support/api/search/request_parameters.html',
5 'use_official_api': False,
6 'require_api_key': False,
7 'results': 'HTML',
8}

Definition at line 14 of file mojeek.py.

◆ base_url

str searx.engines.mojeek.base_url = "https://www.mojeek.com"

Definition at line 27 of file mojeek.py.

◆ categories

list searx.engines.mojeek.categories = ["general", "web"]

Definition at line 29 of file mojeek.py.

◆ content_xpath

str searx.engines.mojeek.content_xpath = '..//p[@class="s"]'

Definition at line 35 of file mojeek.py.

◆ image_img_src_xpath

str searx.engines.mojeek.image_img_src_xpath = './a/img/@src'

Definition at line 41 of file mojeek.py.

◆ image_results_xpath

str searx.engines.mojeek.image_results_xpath = '//div[@id="results"]/div[contains(@class, "image")]'

Definition at line 38 of file mojeek.py.

◆ image_title_xpath

str searx.engines.mojeek.image_title_xpath = './a/@data-title'

Definition at line 40 of file mojeek.py.

◆ image_url_xpath

str searx.engines.mojeek.image_url_xpath = './a/@href'

Definition at line 39 of file mojeek.py.

◆ language_param

str searx.engines.mojeek.language_param = 'lb'

Definition at line 48 of file mojeek.py.

◆ logger

searx.engines.mojeek.logger = logging.getLogger()

Definition at line 56 of file mojeek.py.

◆ max_page

int searx.engines.mojeek.max_page = 10

Definition at line 25 of file mojeek.py.

◆ news_content_xpath

str searx.engines.mojeek.news_content_xpath = './/p[@class="s"]'

Definition at line 46 of file mojeek.py.

◆ news_results_xpath

str searx.engines.mojeek.news_results_xpath = '//section[contains(@class, "news-search-result")]//article'

Definition at line 43 of file mojeek.py.

◆ news_title_xpath

str searx.engines.mojeek.news_title_xpath = './/h2/a'

Definition at line 45 of file mojeek.py.

◆ news_url_xpath

str searx.engines.mojeek.news_url_xpath = './/h2/a/@href'

Definition at line 44 of file mojeek.py.

◆ paging

bool searx.engines.mojeek.paging = True

Definition at line 22 of file mojeek.py.

◆ region_param

str searx.engines.mojeek.region_param = 'arc'

Definition at line 49 of file mojeek.py.

◆ results_xpath

str searx.engines.mojeek.results_xpath = '//ul[@class="results-standard"]/li/a[@class="ob"]'

Definition at line 32 of file mojeek.py.

◆ safesearch

bool searx.engines.mojeek.safesearch = True

Definition at line 23 of file mojeek.py.

◆ search_type

str searx.engines.mojeek.search_type = ""

Definition at line 30 of file mojeek.py.

◆ suggestion_xpath

str searx.engines.mojeek.suggestion_xpath = '//div[@class="top-info"]/p[@class="top-info spell"]/em/a'

Definition at line 36 of file mojeek.py.

◆ time_range_support

bool searx.engines.mojeek.time_range_support = True

Definition at line 24 of file mojeek.py.

◆ title_xpath

str searx.engines.mojeek.title_xpath = '../h2/a'

Definition at line 34 of file mojeek.py.

◆ url_xpath

str searx.engines.mojeek.url_xpath = './@href'

Definition at line 33 of file mojeek.py.