.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.core 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
str api_key = ""
list categories = ["science", "scientific publications"]
bool paging = True
int nb_per_page = 10
str base_url = "https://api.core.ac.uk/v3/search/works/"

Detailed Description

CORE_ (COnnecting REpositories) provides a comprehensive bibliographic
database of the world’s scholarly literature, collecting and indexing
research from repositories and journals.

.. _CORE: https://core.ac.uk/about

.. note::

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

.. _core engine config:

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

The engine has the following additional settings:

- :py:obj:`api_key`

.. code:: yaml

  - name: core.ac.uk
    api_key: "..."
    inactive: false

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

Function Documentation

◆ request()

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

Definition at line 75 of file core.py.

75def request(query: str, params: "OnlineParams") -> None:
76
77 # API v3 uses different parameters
78 search_params = {
79 "q": query,
80 "offset": (params["pageno"] - 1) * nb_per_page,
81 "limit": nb_per_page,
82 "sort": "relevance",
83 }
84
85 params["url"] = base_url + "?" + urlencode(search_params)
86 params["headers"] = {"Authorization": f"Bearer {api_key}"}
87
88

◆ response()

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

Definition at line 89 of file core.py.

89def response(resp: "SXNG_Response") -> EngineResults:
90 # pylint: disable=too-many-branches
91 res = EngineResults()
92 json_data = resp.json()
93
94 for result in json_data.get("results", []):
95 # Get title
96 if not result.get("title"):
97 continue
98
99 # Get URL - try different options
100 url: str | None = None
101
102 # Try DOI first
103 doi: str = result.get("doi")
104 if doi:
105 url = f"https://doi.org/{doi}"
106
107 if url is None and result.get("doi"):
108 # use the DOI reference
109 url = "https://doi.org/" + str(result["doi"])
110 elif result.get("id"):
111 url = "https://core.ac.uk/works/" + str(result["id"])
112 elif result.get("downloadUrl"):
113 url = result["downloadUrl"]
114 elif result.get("sourceFulltextUrls"):
115 url = result["sourceFulltextUrls"]
116 else:
117 continue
118
119 # Published date
120 published_date = None
121
122 raw_date = result.get("publishedDate") or result.get("depositedDate")
123 if raw_date:
124 try:
125 published_date = datetime.fromisoformat(result["publishedDate"].replace("Z", "+00:00"))
126 except (ValueError, AttributeError):
127 pass
128
129 # Handle journals
130 journals = []
131 if result.get("journals"):
132 journals = [j.get("title") for j in result["journals"] if j.get("title")]
133
134 # Handle publisher
135 publisher = result.get("publisher", "").strip("'")
136
137 # Handle authors
138 authors: set[str] = set()
139 for i in result.get("authors", []):
140 name: str | None = i.get("name")
141 if name:
142 authors.add(name)
143
144 res.add(
145 res.types.Paper(
146 title=result.get("title"),
147 url=url,
148 content=result.get("fullText", "") or "",
149 tags=result.get("fieldOfStudy", []),
150 publishedDate=published_date,
151 type=result.get("documentType", "") or "",
152 authors=authors,
153 editor=", ".join(result.get("contributors", [])),
154 publisher=publisher,
155 journal=", ".join(journals),
156 doi=result.get("doi"),
157 pdf_url=result.get("downloadUrl", {}) or result.get("sourceFulltextUrls", {}),
158 )
159 )
160
161 return res

◆ setup()

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

Definition at line 63 of file core.py.

63def setup(engine_settings: dict[str, t.Any]) -> bool:
64 """Initialization of the CORE_ engine, checks whether the :py:obj:`api_key`
65 is set, otherwise the engine is inactive.
66 """
67
68 key: str = engine_settings.get("api_key", "")
69 if key and key not in ("unset", "unknown", "..."):
70 return True
71 logger.error("CORE's API key is not set or invalid.")
72 return False
73
74

Variable Documentation

◆ about

dict searx.engines.core.about
Initial value:
1= {
2 "website": "https://core.ac.uk",
3 "wikidata_id": "Q22661180",
4 "official_api_documentation": "https://api.core.ac.uk/docs/v3",
5 "use_official_api": True,
6 "require_api_key": True,
7 "results": "JSON",
8}

Definition at line 44 of file core.py.

◆ api_key

str searx.engines.core.api_key = ""

Definition at line 53 of file core.py.

◆ base_url

str searx.engines.core.base_url = "https://api.core.ac.uk/v3/search/works/"

Definition at line 60 of file core.py.

◆ categories

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

Definition at line 57 of file core.py.

◆ nb_per_page

int searx.engines.core.nb_per_page = 10

Definition at line 59 of file core.py.

◆ paging

bool searx.engines.core.paging = True

Definition at line 58 of file core.py.