Explorar el Código

Merge pull request #660 from davidar/ma

Add Microsoft Academic search engine
Adam Tauber hace 8 años
padre
commit
d6fe37f9ff
Se han modificado 2 ficheros con 33 adiciones y 8 borrados
  1. 20
    8
      searx/engines/json_engine.py
  2. 13
    0
      searx/settings.yml

+ 20
- 8
searx/engines/json_engine.py Ver fichero

@@ -6,7 +6,8 @@ search_url = None
6 6
 url_query = None
7 7
 content_query = None
8 8
 title_query = None
9
-# suggestion_xpath = ''
9
+suggestion_query = ''
10
+results_query = ''
10 11
 
11 12
 # parameters for engines with paging support
12 13
 #
@@ -90,12 +91,23 @@ def request(query, params):
90 91
 
91 92
 def response(resp):
92 93
     results = []
93
-
94 94
     json = loads(resp.text)
95
-
96
-    urls = query(json, url_query)
97
-    contents = query(json, content_query)
98
-    titles = query(json, title_query)
99
-    for url, title, content in zip(urls, titles, contents):
100
-        results.append({'url': url, 'title': title, 'content': content})
95
+    if results_query:
96
+        for result in query(json, results_query)[0]:
97
+            url = query(result, url_query)[0]
98
+            title = query(result, title_query)[0]
99
+            content = query(result, content_query)[0]
100
+            results.append({'url': url, 'title': title, 'content': content})
101
+    else:
102
+        for url, title, content in zip(
103
+            query(json, url_query),
104
+            query(json, title_query),
105
+            query(json, content_query)
106
+        ):
107
+            results.append({'url': url, 'title': title, 'content': content})
108
+
109
+    if not suggestion_query:
110
+        return results
111
+    for suggestion in query(json, suggestion_query):
112
+        results.append({'suggestion': suggestion})
101 113
     return results

+ 13
- 0
searx/settings.yml Ver fichero

@@ -287,6 +287,19 @@ engines:
287 287
     timeout : 6.0
288 288
     disabled : True
289 289
 
290
+  - name : microsoft academic
291
+    engine : json_engine
292
+    paging : True
293
+    search_url : https://academic.microsoft.com/api/search/GetEntityResults?query=%40{query}%40&filters=&offset={pageno}&limit=8&correlationId=undefined
294
+    results_query : results
295
+    url_query : u
296
+    title_query : dn
297
+    content_query : d
298
+    page_size : 8
299
+    first_page_num : 0
300
+    categories : science
301
+    shortcut : ma
302
+
290 303
   - name : mixcloud
291 304
     engine : mixcloud
292 305
     shortcut : mc