Browse Source

Open Semantic Search Engine

Nicholas Kegler 6 years ago
parent
commit
7761feed99
2 changed files with 51 additions and 0 deletions
  1. 47
    0
      searx/engines/opensemantic.py
  2. 4
    0
      searx/settings.yml

+ 47
- 0
searx/engines/opensemantic.py View File

@@ -0,0 +1,47 @@
1
+"""
2
+Open Semantic Search
3
+
4
+ @website    https://www.opensemanticsearch.org/
5
+ @provide-api yes (https://www.opensemanticsearch.org/dev)
6
+
7
+ @using-api  yes
8
+ @results    JSON
9
+ @stable     yes
10
+ @parse      url, title, content, publishedDate
11
+"""
12
+from dateutil import parser
13
+from json import loads
14
+from searx.url_utils import quote
15
+
16
+# If your OSS is hosted on another machine you would need to change
17
+# your base_url.
18
+base_url = 'http://localhost:8983/solr/opensemanticsearch/'
19
+search_string = 'query?q={query}'
20
+
21
+
22
+def request(query, params):
23
+    search_path = search_string.format(
24
+        query=quote(query),
25
+    )
26
+    params['url'] = base_url + search_path
27
+    return params
28
+
29
+
30
+def response(resp):
31
+    results = []
32
+    data = loads(resp.text)
33
+    docs = data.get('response', {}).get('docs', [])
34
+
35
+    for current in docs:
36
+        item = {}
37
+        item['url'] = current['id']
38
+        item['title'] = current['title_txt_txt_en']
39
+        if current.get('content_txt'):
40
+            item['content'] = current['content_txt'][0]
41
+        item['publishedDate'] = parser.parse(
42
+            current['file_modified_dt']
43
+        )
44
+        item['originalData'] = current
45
+        results.append(item)
46
+
47
+    return results

+ 4
- 0
searx/settings.yml View File

@@ -464,6 +464,10 @@ engines:
464 464
     shortcut : oap
465 465
     timeout: 5.0
466 466
 
467
+  - name : opensemanticsearch
468
+    engine : opensemantic
469
+    shortcut : oss
470
+
467 471
   - name : openstreetmap
468 472
     engine : openstreetmap
469 473
     shortcut : osm