summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarIT.de>2021-06-08 10:56:18 +0000
committerGitHub <noreply@github.com>2021-06-08 10:56:18 +0000
commit5c5db719d2039d34aa1426bf7eb3e57055d4a54a (patch)
tree15a7a5e1a811f1366cdb49b69e35633afaf56114 /searx
parent5f76238d5cd6f9c850d5237fe639ba2900fd3e6c (diff)
parent6f7b0d72c084845ea073a82a357c5e99cd41a85f (diff)
downloadsearxng-5c5db719d2039d34aa1426bf7eb3e57055d4a54a.tar.gz
searxng-5c5db719d2039d34aa1426bf7eb3e57055d4a54a.zip
Merge pull request #97 from return42/drop-searx-admin
[docs] reorder blog articles
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/demo_offline.py74
-rw-r--r--searx/engines/demo_online.py92
-rw-r--r--searx/engines/dictzone.py2
-rw-r--r--searx/engines/translated.py2
-rw-r--r--searx/search/processors/online_dictionary.py4
5 files changed, 170 insertions, 4 deletions
diff --git a/searx/engines/demo_offline.py b/searx/engines/demo_offline.py
new file mode 100644
index 000000000..06609d2c3
--- /dev/null
+++ b/searx/engines/demo_offline.py
@@ -0,0 +1,74 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+"""Within this module we implement a *demo offline engine*. Do not look to
+close to the implementation, its just a simple example. To get in use of this
+*demo* engine add the following entry to your engines list in ``settings.yml``:
+
+.. code:: yaml
+
+ - name: my offline engine
+ engine: demo_offline
+ shortcut: demo
+ disabled: false
+
+"""
+
+import json
+
+engine_type = 'offline'
+categories = ['general']
+disabled = True
+timeout = 2.0
+
+about = {
+ "wikidata_id": None,
+ "official_api_documentation": None,
+ "use_official_api": False,
+ "require_api_key": False,
+ "results": 'JSON',
+}
+
+# if there is a need for globals, use a leading underline
+_my_offline_engine = None
+
+def init(engine_settings=None):
+ """Initialization of the (offline) engine. The origin of this demo engine is a
+ simple json string which is loaded in this example while the engine is
+ initialized.
+
+ """
+ global _my_offline_engine # pylint: disable=global-statement
+
+ _my_offline_engine = (
+ '[ {"value": "%s"}'
+ ', {"value":"first item"}'
+ ', {"value":"second item"}'
+ ', {"value":"third item"}'
+ ']'
+
+ % engine_settings.get('name')
+ )
+
+def search(query, request_params):
+ """Query (offline) engine and return results. Assemble the list of results from
+ your local engine. In this demo engine we ignore the 'query' term, usual
+ you would pass the 'query' term to your local engine to filter out the
+ results.
+
+ """
+ global _my_offline_engine # pylint: disable=global-statement
+ ret_val = []
+
+ result_list = json.loads(_my_offline_engine)
+
+ for row in result_list:
+ entry = {
+ 'query' : query,
+ 'language' : request_params['language'],
+ 'value' : row.get("value"),
+ # choose a result template or comment out to use the *default*
+ 'template' : 'key-value.html',
+ }
+ ret_val.append(entry)
+
+ return ret_val
diff --git a/searx/engines/demo_online.py b/searx/engines/demo_online.py
new file mode 100644
index 000000000..a0f736e42
--- /dev/null
+++ b/searx/engines/demo_online.py
@@ -0,0 +1,92 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+"""Within this module we implement a *demo online engine*. Do not look to
+close to the implementation, its just a simple example which queries `The Art
+Institute of Chicago <https://www.artic.edu>`_
+
+To get in use of this *demo* engine add the following entry to your engines
+list in ``settings.yml``:
+
+.. code:: yaml
+
+ - name: my online engine
+ engine: demo_online
+ shortcut: demo
+ disabled: false
+
+"""
+
+from json import loads
+from urllib.parse import urlencode
+
+engine_type = 'offline'
+categories = ['general']
+disabled = True
+timeout = 2.0
+categories = ['images']
+paging = True
+page_size = 20
+
+search_api = 'https://api.artic.edu/api/v1/artworks/search?'
+image_api = 'https://www.artic.edu/iiif/2/'
+
+about = {
+ "website": 'https://www.artic.edu',
+ "wikidata_id": 'Q239303',
+ "official_api_documentation": 'http://api.artic.edu/docs/',
+ "use_official_api": True,
+ "require_api_key": False,
+ "results": 'JSON',
+}
+
+
+# if there is a need for globals, use a leading underline
+_my_online_engine = None
+
+def init(engine_settings):
+ """Initialization of the (online) engine. If no initialization is needed, drop
+ this init function.
+
+ """
+ global _my_online_engine # pylint: disable=global-statement
+ _my_online_engine = engine_settings.get('name')
+
+def request(query, params):
+ """Build up the ``params`` for the online request. In this example we build a
+ URL to fetch images from `artic.edu <https://artic.edu>`__
+
+ """
+ args = urlencode({
+ 'q' : query,
+ 'page' : params['pageno'],
+ 'fields' : 'id,title,artist_display,medium_display,image_id,date_display,dimensions,artist_titles',
+ 'limit' : page_size,
+ })
+ params['url'] = search_api + args
+ return params
+
+def response(resp):
+ """Parse out the result items from the response. In this example we parse the
+ response from `api.artic.edu <https://artic.edu>`__ and filter out all
+ images.
+
+ """
+ results = []
+ json_data = loads(resp.text)
+
+ for result in json_data['data']:
+
+ if not result['image_id']:
+ continue
+
+ results.append({
+ 'url': 'https://artic.edu/artworks/%(id)s' % result,
+ 'title': result['title'] + " (%(date_display)s) // %(artist_display)s" % result,
+ 'content': result['medium_display'],
+ 'author': ', '.join(result['artist_titles']),
+ 'img_src': image_api + '/%(image_id)s/full/843,/0/default.jpg' % result,
+ 'img_format': result['dimensions'],
+ 'template': 'images.html'
+ })
+
+ return results
diff --git a/searx/engines/dictzone.py b/searx/engines/dictzone.py
index eaa8b6ab4..4a92a22c3 100644
--- a/searx/engines/dictzone.py
+++ b/searx/engines/dictzone.py
@@ -17,7 +17,7 @@ about = {
"results": 'HTML',
}
-engine_type = 'online_dictionnary'
+engine_type = 'online_dictionary'
categories = ['general']
url = 'https://dictzone.com/{from_lang}-{to_lang}-dictionary/{query}'
weight = 100
diff --git a/searx/engines/translated.py b/searx/engines/translated.py
index 9c53d70ad..8d67ca0bb 100644
--- a/searx/engines/translated.py
+++ b/searx/engines/translated.py
@@ -13,7 +13,7 @@ about = {
"results": 'JSON',
}
-engine_type = 'online_dictionnary'
+engine_type = 'online_dictionary'
categories = ['general']
url = 'https://api.mymemory.translated.net/get?q={query}&langpair={from_lang}|{to_lang}{key}'
web_url = 'https://mymemory.translated.net/en/{from_lang}/{to_lang}/{query}'
diff --git a/searx/search/processors/online_dictionary.py b/searx/search/processors/online_dictionary.py
index 11ca0335d..72941d57a 100644
--- a/searx/search/processors/online_dictionary.py
+++ b/searx/search/processors/online_dictionary.py
@@ -12,9 +12,9 @@ from .online import OnlineProcessor
parser_re = re.compile('.*?([a-z]+)-([a-z]+) ([^ ]+)$', re.I)
class OnlineDictionaryProcessor(OnlineProcessor):
- """Processor class used by ``online_dictionnary`` engines."""
+ """Processor class used by ``online_dictionary`` engines."""
- engine_type = 'online_dictionnary'
+ engine_type = 'online_dictionary'
def get_params(self, search_query, engine_category):
params = super().get_params(search_query, engine_category)