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

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['science', 'scientific publications']
 
tuple base_url
 
int number_of_results = 10
 
str pubmed_url = 'https://www.ncbi.nlm.nih.gov/pubmed/'
 

Detailed Description

PubMed (Scholar publications)

Function Documentation

◆ request()

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

Definition at line 41 of file pubmed.py.

41def request(query, params):
42 # basic search
43 offset = (params['pageno'] - 1) * number_of_results
44
45 string_args = {
46 'query': urlencode({'term': query}),
47 'offset': offset,
48 'hits': number_of_results,
49 }
50
51 params['url'] = base_url.format(**string_args)
52
53 return params
54
55

◆ response()

searx.engines.pubmed.response ( resp)

Definition at line 56 of file pubmed.py.

56def response(resp): # pylint: disable=too-many-locals
57 results = []
58
59 # First retrieve notice of each result
60 pubmed_retrieve_api_url = (
61 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?' + 'db=pubmed&retmode=xml&id={pmids_string}'
62 )
63
64 pmids_results = etree.XML(resp.content)
65 pmids = pmids_results.xpath('//eSearchResult/IdList/Id')
66 pmids_string = ''
67
68 for item in pmids:
69 pmids_string += item.text + ','
70
71 retrieve_notice_args = {'pmids_string': pmids_string}
72
73 retrieve_url_encoded = pubmed_retrieve_api_url.format(**retrieve_notice_args)
74
75 search_results_response = get(retrieve_url_encoded).content
76 search_results = etree.XML(search_results_response)
77 for entry in eval_xpath_list(search_results, '//PubmedArticle'):
78 medline = eval_xpath_getindex(entry, './MedlineCitation', 0)
79
80 title = eval_xpath_getindex(medline, './/Article/ArticleTitle', 0).text
81 pmid = eval_xpath_getindex(medline, './/PMID', 0).text
82 url = pubmed_url + pmid
83 content = extract_text(
84 eval_xpath_getindex(medline, './/Abstract/AbstractText//text()', 0, default=None), allow_none=True
85 )
86 doi = extract_text(
87 eval_xpath_getindex(medline, './/ELocationID[@EIdType="doi"]/text()', 0, default=None), allow_none=True
88 )
89 journal = extract_text(
90 eval_xpath_getindex(medline, './Article/Journal/Title/text()', 0, default=None), allow_none=True
91 )
92 issn = extract_text(
93 eval_xpath_getindex(medline, './Article/Journal/ISSN/text()', 0, default=None), allow_none=True
94 )
95 authors = []
96 for author in eval_xpath_list(medline, './Article/AuthorList/Author'):
97 f = eval_xpath_getindex(author, './ForeName', 0, default=None)
98 l = eval_xpath_getindex(author, './LastName', 0, default=None)
99 f = '' if f is None else f.text
100 l = '' if l is None else l.text
101 authors.append((f + ' ' + l).strip())
102
103 res_dict = {
104 'template': 'paper.html',
105 'url': url,
106 'title': title,
107 'content': content or "",
108 'journal': journal,
109 'issn': [issn],
110 'authors': authors,
111 'doi': doi,
112 }
113
114 accepted_date = eval_xpath_getindex(
115 entry, './PubmedData/History//PubMedPubDate[@PubStatus="accepted"]', 0, default=None
116 )
117 if accepted_date is not None:
118 year = eval_xpath_getindex(accepted_date, './Year', 0)
119 month = eval_xpath_getindex(accepted_date, './Month', 0)
120 day = eval_xpath_getindex(accepted_date, './Day', 0)
121 try:
122 publishedDate = datetime.strptime(
123 year.text + '-' + month.text + '-' + day.text,
124 '%Y-%m-%d',
125 )
126 res_dict['publishedDate'] = publishedDate
127 except Exception as e: # pylint: disable=broad-exception-caught
128 print(e)
129
130 results.append(res_dict)
131
132 return results

Variable Documentation

◆ about

dict searx.engines.pubmed.about
Initial value:
1= {
2 "website": 'https://www.ncbi.nlm.nih.gov/pubmed/',
3 "wikidata_id": 'Q1540899',
4 "official_api_documentation": {
5 'url': 'https://www.ncbi.nlm.nih.gov/home/develop/api/',
6 'comment': 'More info on api: https://www.ncbi.nlm.nih.gov/books/NBK25501/',
7 },
8 "use_official_api": True,
9 "require_api_key": False,
10 "results": 'XML',
11}

Definition at line 18 of file pubmed.py.

◆ base_url

tuple searx.engines.pubmed.base_url
Initial value:
1= (
2 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi' + '?db=pubmed&{query}&retstart={offset}&retmax={hits}'
3)

Definition at line 32 of file pubmed.py.

◆ categories

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

Definition at line 30 of file pubmed.py.

◆ number_of_results

int searx.engines.pubmed.number_of_results = 10

Definition at line 37 of file pubmed.py.

◆ pubmed_url

str searx.engines.pubmed.pubmed_url = 'https://www.ncbi.nlm.nih.gov/pubmed/'

Definition at line 38 of file pubmed.py.