add citation count

This commit is contained in:
Steven Tischer
2026-07-08 14:24:25 +02:00
parent 164e79978f
commit ccade53358
2 changed files with 22 additions and 0 deletions
+19
View File
@@ -95,6 +95,14 @@ def _build_query(keywords: List[str], operator: KeywordOperator, uni_id: str) ->
"size": 1,
},
},
"to_work": {
"reverse_nested": {},
"aggs": {
"citations": {
"sum": {"field": "cited_by_count"},
},
},
},
},
},
},
@@ -111,11 +119,22 @@ def _display_name_from_bucket(author_bucket: dict) -> str:
return ""
def _citations_from_bucket(author_bucket: dict) -> int:
"""Reads the summed citations out of the reverse_nested sub-aggregation."""
citations_value = (
author_bucket.get("to_work", {})
.get("citations", {})
.get("value", 0)
)
return int(citations_value)
def _bucket_to_ranked_author(author_bucket: dict) -> RankedAuthor:
return RankedAuthor(
author_id=author_bucket.get("key", ""),
display_name=_display_name_from_bucket(author_bucket),
works_count=author_bucket.get("doc_count", 0),
citations_count=_citations_from_bucket(author_bucket),
)
+3
View File
@@ -40,3 +40,6 @@ class RankedAuthor(BaseModel):
author_id: str = Field(description="The OpenAlex ID of the author.")
display_name: str = Field(description="The name of the author.")
works_count: int = Field(description="Number of matching works by this author.")
citations_count: int = Field(
description="Total citations across this author's matching works.",
)