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

Functions

bool setup (dict[str, t.Any] engine_settings)
None request (str query, "OnlineParams" params)
EngineResults response ("SXNG_Response" resp)

Variables

dict about
list categories = ["science", "scientific publications"]
bool paging = True
str base_url = "https://api.adsabs.harvard.edu/v1/search/query"
str api_key = "unset"
list ads_field_list
int ads_rows = 10
str ads_sort = "read_count desc"

Detailed Description

The Astrophysics Data System (ADS_) is a digital library portal for
researchers in astronomy and physics, operated by the Smithsonian Astrophysical
Observatory (SAO) under a NASA grant.  The ADS_ is a solr instance, but not with
the standard API paths.

.. note::

   The ADS_ engine requires an :py:obj:`API key <api_key>`.

This engine uses the `search/query`_ API endpoint.  Since the user's search term
is passed through, the `search syntax`_ of ADS can be used (at least to some
extent).

.. _ADS: https://ui.adsabs.harvard.edu
.. _search/query: https://ui.adsabs.harvard.edu/help/api/api-docs.html#get-/search/query
.. _search syntax: https://ui.adsabs.harvard.edu/help/search/search-syntax


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

The engine has the following additional settings:

- :py:obj:`api_key`
- :py:obj:`ads_sort`

.. code:: yaml

  - name: astrophysics data system
    api_key: "..."
    inactive: false


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

Function Documentation

◆ request()

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

Definition at line 110 of file astrophysics_data_system.py.

110def request(query: str, params: "OnlineParams") -> None:
111
112 args: dict[str, str | int] = {
113 "q": query,
114 "fl": ",".join(ads_field_list),
115 "rows": ads_rows,
116 "start": ads_rows * (params["pageno"] - 1),
117 }
118 if ads_sort:
119 args["sort"] = ads_sort
120
121 params["headers"]["Authorization"] = f"Bearer {api_key}"
122 params["url"] = f"{base_url}?{urlencode(args)}"
123
124

◆ response()

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

Definition at line 125 of file astrophysics_data_system.py.

125def response(resp: "SXNG_Response") -> EngineResults:
126
127 res = EngineResults()
128 json_data: dict[str, dict[str, t.Any]] = resp.json()
129
130 if "error" in json_data:
131 raise SearxEngineAPIException(json_data["error"]["msg"])
132
133 def _str(k: str) -> str:
134 return str(doc.get(k, ""))
135
136 def _list(k: str) -> list[str]:
137 return doc.get(k, [])
138
139 for doc in json_data["response"]["docs"]:
140 authors: list[str] = doc["author"]
141 if len(authors) > 15:
142 # There are articles with hundreds of authors
143 authors = authors[:15] + ["et al."]
144
145 paper = res.types.Paper(
146 url=f"https://ui.adsabs.harvard.edu/abs/{doc.get('bibcode')}/",
147 title=html_to_text(_list("title")[0]),
148 authors=authors,
149 content=html_to_text(_str("abstract")),
150 doi=_list("doi")[0],
151 issn=_list("issn"),
152 isbn=_list("isbn"),
153 tags=_list("keyword"),
154 pages=",".join(_list("page")),
155 publisher=_str("pub") + " " + _str("year"),
156 publishedDate=datetime.fromisoformat(_str("date")),
157 volume=_str("volume"),
158 views=_str("read_count"),
159 comments=" / ".join(_list("pubnote")),
160 )
161 res.add(paper)
162
163 return res

◆ setup()

bool searx.engines.astrophysics_data_system.setup ( dict[str, t.Any] engine_settings)
Initialization of the ADS_ engine, checks whether the :py:obj:`api_key`
is set, otherwise the engine is inactive.

Definition at line 99 of file astrophysics_data_system.py.

99def setup(engine_settings: dict[str, t.Any]) -> bool:
100 """Initialization of the ADS_ engine, checks whether the :py:obj:`api_key`
101 is set, otherwise the engine is inactive.
102 """
103 key: str = engine_settings.get("api_key", "")
104 if key and key not in ("unset", "unknown", "..."):
105 return True
106 logger.error("Astrophysics Data System (ADS) API key is not set or invalid.")
107 return False
108
109

Variable Documentation

◆ about

dict searx.engines.astrophysics_data_system.about
Initial value:
1= {
2 "website": "https://ui.adsabs.harvard.edu/",
3 "wikidata_id": "Q752099",
4 "official_api_documentation": "https://ui.adsabs.harvard.edu/help/api/api-docs.html",
5 "use_official_api": True,
6 "require_api_key": True,
7 "results": "JSON",
8}

Definition at line 52 of file astrophysics_data_system.py.

◆ ads_field_list

list searx.engines.astrophysics_data_system.ads_field_list
Initial value:
1= [
2 "abstract",
3 "author",
4 "bibcode",
5 "comment",
6 "date",
7 "doi",
8 "isbn",
9 "issn",
10 "keyword",
11 "page",
12 "page_count",
13 "page_range",
14 "pub",
15 "pubdate",
16 "pubnote",
17 "read_count",
18 "title",
19 "volume",
20 "year",
21]

Definition at line 68 of file astrophysics_data_system.py.

◆ ads_rows

int searx.engines.astrophysics_data_system.ads_rows = 10

Definition at line 91 of file astrophysics_data_system.py.

◆ ads_sort

str searx.engines.astrophysics_data_system.ads_sort = "read_count desc"

Definition at line 94 of file astrophysics_data_system.py.

◆ api_key

str searx.engines.astrophysics_data_system.api_key = "unset"

Definition at line 65 of file astrophysics_data_system.py.

◆ base_url

str searx.engines.astrophysics_data_system.base_url = "https://api.adsabs.harvard.edu/v1/search/query"

Definition at line 63 of file astrophysics_data_system.py.

◆ categories

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

Definition at line 61 of file astrophysics_data_system.py.

◆ paging

bool searx.engines.astrophysics_data_system.paging = True

Definition at line 62 of file astrophysics_data_system.py.