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

Functions

None request (str query, "OnlineParams" params)
EngineResults response ("SXNG_Response" resp)

Variables

dict about
list categories = ["science", "scientific publications"]
str eutils_api = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils"
int number_of_results = 10
str pubmed_url = "https://www.ncbi.nlm.nih.gov/pubmed/"

Detailed Description

PubMed_ comprises more than 39 million citations for biomedical literature
from MEDLINE, life science journals, and online books. Citations may include
links to full text content from PubMed Central and publisher web sites.

.. _PubMed: https://pubmed.ncbi.nlm.nih.gov/

Configuration
=============

.. code:: yaml

   - name: pubmed
     engine: pubmed
     shortcut: pub

Implementations
===============

Function Documentation

◆ request()

None searx.engines.pubmed.request ( str query,
"OnlineParams" params )

Definition at line 64 of file pubmed.py.

64def request(query: str, params: "OnlineParams") -> None:
65
66 args = urlencode(
67 {
68 "db": "pubmed",
69 "term": query,
70 "retstart": (params["pageno"] - 1) * number_of_results,
71 "hits": number_of_results,
72 }
73 )
74 esearch_url = f"{eutils_api}/esearch.fcgi?{args}"
75 # DTD: https://eutils.ncbi.nlm.nih.gov/eutils/dtd/20060628/esearch.dtd
76 esearch_resp: "SXNG_Response" = get(esearch_url)
77 pmids_results = etree.XML(esearch_resp.content)
78 pmids: list[str] = [i.text for i in pmids_results.xpath("//eSearchResult/IdList/Id")]
79
80 # send efetch request with the IDs from esearch response
81 args = urlencode(
82 {
83 "db": "pubmed",
84 "retmode": "xml",
85 "id": ",".join(pmids),
86 }
87 )
88 efetch_url = f"{eutils_api}/efetch.fcgi?{args}"
89 params["url"] = efetch_url
90
91

◆ response()

EngineResults searx.engines.pubmed.response ( "SXNG_Response" resp)

Definition at line 92 of file pubmed.py.

92def response(resp: "SXNG_Response") -> EngineResults: # pylint: disable=too-many-locals
93
94 # DTD: https://dtd.nlm.nih.gov/ncbi/pubmed/out/pubmed_250101.dtd
95
96 # parse efetch response
97 efetch_xml = etree.XML(resp.content)
98 res = EngineResults()
99
100 def _field_txt(xml: ElementType, xpath_str: str) -> str:
101 elem = eval_xpath_getindex(xml, xpath_str, 0, default="")
102 return extract_text(elem, allow_none=True) or ""
103
104 for pubmed_article in eval_xpath_list(efetch_xml, "//PubmedArticle"):
105
106 medline_citation: ElementType = eval_xpath_getindex(pubmed_article, "./MedlineCitation", 0)
107 pubmed_data: ElementType = eval_xpath_getindex(pubmed_article, "./PubmedData", 0)
108
109 title: str = eval_xpath_getindex(medline_citation, ".//Article/ArticleTitle", 0).text
110 pmid: str = eval_xpath_getindex(medline_citation, ".//PMID", 0).text
111 url: str = pubmed_url + pmid
112 content = _field_txt(medline_citation, ".//Abstract/AbstractText//text()")
113 doi = _field_txt(medline_citation, ".//ELocationID[@EIdType='doi']/text()")
114 journal = _field_txt(medline_citation, "./Article/Journal/Title/text()")
115 issn = _field_txt(medline_citation, "./Article/Journal/ISSN/text()")
116
117 authors: list[str] = []
118
119 for author in eval_xpath_list(medline_citation, "./Article/AuthorList/Author"):
120 f = eval_xpath_getindex(author, "./ForeName", 0, default=None)
121 l = eval_xpath_getindex(author, "./LastName", 0, default=None)
122 author_name = f"{f.text if f is not None else ''} {l.text if l is not None else ''}".strip()
123 if author_name:
124 authors.append(author_name)
125
126 accepted_date = eval_xpath_getindex(
127 pubmed_data, "./History//PubMedPubDate[@PubStatus='accepted']", 0, default=None
128 )
129 pub_date = None
130 if accepted_date is not None:
131 year = eval_xpath_getindex(accepted_date, "./Year", 0)
132 month = eval_xpath_getindex(accepted_date, "./Month", 0)
133 day = eval_xpath_getindex(accepted_date, "./Day", 0)
134 try:
135 pub_date = datetime(year=int(year.text), month=int(month.text), day=int(day.text))
136 except ValueError:
137 pass
138
139 res.add(
140 res.types.Paper(
141 url=url,
142 title=title,
143 content=content,
144 journal=journal,
145 issn=[issn],
146 authors=authors,
147 doi=doi,
148 publishedDate=pub_date,
149 )
150 )
151 return res

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 43 of file pubmed.py.

◆ categories

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

Definition at line 55 of file pubmed.py.

◆ eutils_api

str searx.engines.pubmed.eutils_api = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils"

Definition at line 57 of file pubmed.py.

◆ number_of_results

int searx.engines.pubmed.number_of_results = 10

Definition at line 60 of file pubmed.py.

◆ pubmed_url

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

Definition at line 61 of file pubmed.py.