.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
online_url_search.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Processors for engine-type: ``online_url_search``
3
4"""
5
6import re
7from .online import OnlineProcessor
8
9re_search_urls = {
10 'http': re.compile(r'https?:\/\/[^ ]*'),
11 'ftp': re.compile(r'ftps?:\/\/[^ ]*'),
12 'data:image': re.compile('data:image/[^; ]*;base64,[^ ]*'),
13}
14
15
17 """Processor class used by ``online_url_search`` engines."""
18
19 engine_type = 'online_url_search'
20
21 def get_params(self, search_query, engine_category):
22 """Returns a set of :ref:`request params <engine request online>` or ``None`` if
23 search query does not match to :py:obj:`re_search_urls`.
24 """
25
26 params = super().get_params(search_query, engine_category)
27 if params is None:
28 return None
29
30 url_match = False
31 search_urls = {}
32
33 for k, v in re_search_urls.items():
34 m = v.search(search_query.query)
35 v = None
36 if m:
37 url_match = True
38 v = m[0]
39 search_urls[k] = v
40
41 if not url_match:
42 return None
43
44 params['search_urls'] = search_urls
45 return params