Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Enable fields for openalex
  • Loading branch information
whitead committed Nov 2, 2025
commit f6189b151beea615092cafb5ac9ed88cb44111ed
16 changes: 13 additions & 3 deletions src/paperqa/clients/openalex.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ async def get_doc_details_from_openalex(

if fields:
params["select"] = ",".join(fields)
print("OpenAlex request URL:", url, "with params:", params)
response = await client.get(
url, params=params, timeout=OPENALEX_API_REQUEST_TIMEOUT
)
Expand Down Expand Up @@ -210,31 +211,36 @@ class OpenAlexProvider(DOIOrTitleBasedProvider):
"""

async def get_doc_details(
self, doi: str, client: httpx.AsyncClient
self, doi: str, client: httpx.AsyncClient, fields: Collection[str] | None = None
) -> DocDetails | None:
"""Get document details by DOI.

Args:
doi: The DOI of the document.
client: Async HTTP client for any requests.
fields: Specific fields to include in the request.

Returns:
The document details if found, otherwise None.
"""
return await get_doc_details_from_openalex(doi=doi, client=client)
return await get_doc_details_from_openalex(
doi=doi, client=client, fields=fields
)

async def search_by_title(
self,
query: str,
client: httpx.AsyncClient,
title_similarity_threshold: float = 0.75,
fields: Collection[str] | None = None,
) -> DocDetails | None:
"""Search for document details by title.

Args:
query: The title query for the document.
client: Async HTTP client for any requests.
title_similarity_threshold: Threshold for title similarity.
fields: Specific fields to include in the request.

Returns:
The document details if found, otherwise None.
Expand All @@ -243,6 +249,7 @@ async def search_by_title(
title=query,
client=client,
title_similarity_threshold=title_similarity_threshold,
fields=fields,
)

async def _query(self, query: TitleAuthorQuery | DOIQuery) -> DocDetails | None:
Expand All @@ -256,9 +263,12 @@ async def _query(self, query: TitleAuthorQuery | DOIQuery) -> DocDetails | None:
The document details if found, otherwise None.
"""
if isinstance(query, DOIQuery):
return await self.get_doc_details(doi=query.doi, client=query.client)
return await self.get_doc_details(
doi=query.doi, client=query.client, fields=query.fields
)
return await self.search_by_title(
query=query.title,
client=query.client,
title_similarity_threshold=query.title_similarity_threshold,
fields=query.fields,
)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,6 @@ async def test_does_openalex_work(doi: str, oa: bool) -> None:
assert (
openalex_details.other["open_access"]["is_oa"] is oa
), "Open access data should match"
assert (
openalex_details.year is None
), "Year should not be populated because we set fields"
Loading