add citation count
This commit is contained in:
@@ -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),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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.",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user