Browse Source

Merge pull request #660 from davidar/ma

Add Microsoft Academic search engine
Adam Tauber 8 years ago
parent
commit
d6fe37f9ff
2 changed files with 33 additions and 8 deletions
  1. 20
    8
      searx/engines/json_engine.py
  2. 13
    0
      searx/settings.yml

+ 20
- 8
searx/engines/json_engine.py View File

6
 url_query = None
6
 url_query = None
7
 content_query = None
7
 content_query = None
8
 title_query = None
8
 title_query = None
9
-# suggestion_xpath = ''
9
+suggestion_query = ''
10
+results_query = ''
10
 
11
 
11
 # parameters for engines with paging support
12
 # parameters for engines with paging support
12
 #
13
 #
90
 
91
 
91
 def response(resp):
92
 def response(resp):
92
     results = []
93
     results = []
93
-
94
     json = loads(resp.text)
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
     return results
113
     return results

+ 13
- 0
searx/settings.yml View File

287
     timeout : 6.0
287
     timeout : 6.0
288
     disabled : True
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
   - name : mixcloud
303
   - name : mixcloud
291
     engine : mixcloud
304
     engine : mixcloud
292
     shortcut : mc
305
     shortcut : mc