.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.semantic_scholar Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['science', 'scientific publications']
 
bool paging = True
 
str search_url = 'https://www.semanticscholar.org/api/1/search'
 
str paper_url = 'https://www.semanticscholar.org/paper'
 

Detailed Description

Semantic Scholar (Science)

Function Documentation

◆ request()

searx.engines.semantic_scholar.request ( query,
params )

Definition at line 25 of file semantic_scholar.py.

25def request(query, params):
26 params['url'] = search_url
27 params['method'] = 'POST'
28 params['headers']['content-type'] = 'application/json'
29 params['data'] = dumps(
30 {
31 "queryString": query,
32 "page": params['pageno'],
33 "pageSize": 10,
34 "sort": "relevance",
35 "getQuerySuggestions": False,
36 "authors": [],
37 "coAuthors": [],
38 "venues": [],
39 "performTitleMatch": True,
40 }
41 )
42 return params
43
44

◆ response()

searx.engines.semantic_scholar.response ( resp)

Definition at line 45 of file semantic_scholar.py.

45def response(resp):
46 res = loads(resp.text)
47 results = []
48 for result in res['results']:
49 url = result.get('primaryPaperLink', {}).get('url')
50 if not url and result.get('links'):
51 url = result.get('links')[0]
52 if not url:
53 alternatePaperLinks = result.get('alternatePaperLinks')
54 if alternatePaperLinks:
55 url = alternatePaperLinks[0].get('url')
56 if not url:
57 url = paper_url + '/%s' % result['id']
58
59 # publishedDate
60 if 'pubDate' in result:
61 publishedDate = datetime.strptime(result['pubDate'], "%Y-%m-%d")
62 else:
63 publishedDate = None
64
65 # authors
66 authors = [author[0]['name'] for author in result.get('authors', [])]
67
68 # pick for the first alternate link, but not from the crawler
69 pdf_url = None
70 for doc in result.get('alternatePaperLinks', []):
71 if doc['linkType'] not in ('crawler', 'doi'):
72 pdf_url = doc['url']
73 break
74
75 # comments
76 comments = None
77 if 'citationStats' in result:
78 comments = gettext(
79 '{numCitations} citations from the year {firstCitationVelocityYear} to {lastCitationVelocityYear}'
80 ).format(
81 numCitations=result['citationStats']['numCitations'],
82 firstCitationVelocityYear=result['citationStats']['firstCitationVelocityYear'],
83 lastCitationVelocityYear=result['citationStats']['lastCitationVelocityYear'],
84 )
85
86 results.append(
87 {
88 'template': 'paper.html',
89 'url': url,
90 'title': result['title']['text'],
91 'content': result['paperAbstract']['text'],
92 'journal': result.get('venue', {}).get('text') or result.get('journal', {}).get('name'),
93 'doi': result.get('doiInfo', {}).get('doi'),
94 'tags': result.get('fieldsOfStudy'),
95 'authors': authors,
96 'pdf_url': pdf_url,
97 'publishedDate': publishedDate,
98 'comments': comments,
99 }
100 )
101
102 return results

References searx.format.

Variable Documentation

◆ about

dict searx.engines.semantic_scholar.about
Initial value:
1= {
2 "website": 'https://www.semanticscholar.org/',
3 "wikidata_id": 'Q22908627',
4 "official_api_documentation": 'https://api.semanticscholar.org/',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 10 of file semantic_scholar.py.

◆ categories

list searx.engines.semantic_scholar.categories = ['science', 'scientific publications']

Definition at line 19 of file semantic_scholar.py.

◆ paging

bool searx.engines.semantic_scholar.paging = True

Definition at line 20 of file semantic_scholar.py.

◆ paper_url

str searx.engines.semantic_scholar.paper_url = 'https://www.semanticscholar.org/paper'

Definition at line 22 of file semantic_scholar.py.

◆ search_url

str searx.engines.semantic_scholar.search_url = 'https://www.semanticscholar.org/api/1/search'

Definition at line 21 of file semantic_scholar.py.