From cf9a5df4e94b2fa7b323ea96b49cb55bb9df7646 Mon Sep 17 00:00:00 2001 From: louis-19041904 Date: Tue, 7 Jul 2026 01:08:14 +0200 Subject: [PATCH] works: count interesting-for topics like the publications filter --- service/src/main/inse/works/logic.py | 26 ++++++++++++++++++- .../person-interesting.component.ts | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/service/src/main/inse/works/logic.py b/service/src/main/inse/works/logic.py index 41375cfe..96bf0ef2 100644 --- a/service/src/main/inse/works/logic.py +++ b/service/src/main/inse/works/logic.py @@ -167,6 +167,15 @@ async def _get_primary_topic_counts_from_es(author_id: str) -> list[dict]: "primary_topics": { "terms": {"field": "primary_topic.id", "size": 1000}, }, + "all_topics": { + "nested": {"path": "topics"}, + "aggs": { + "topic_ids": { + "terms": {"field": "topics.id", "size": 1000}, + "aggs": {"works": {"reverse_nested": {}}}, + }, + }, + }, }, } @@ -181,10 +190,25 @@ async def _get_primary_topic_counts_from_es(author_id: str) -> list[dict]: aggregations = response.get("aggregations", {}) buckets = aggregations.get("primary_topics", {}).get("buckets", []) + topic_buckets = ( + aggregations.get("all_topics", {}).get("topic_ids", {}).get("buckets", []) + ) + + broad_counts = { + bucket["key"]: bucket.get("works", {}).get("doc_count", bucket["doc_count"]) + for bucket in topic_buckets + } + counts = [] for bucket in buckets: - counts.append({"id": bucket["key"], "count": bucket["doc_count"]}) + topic_id = bucket["key"] + counts.append( + { + "id": topic_id, + "count": max(broad_counts.get(topic_id, 0), bucket["doc_count"]), + } + ) return counts diff --git a/webapp/src/app/modules/person-interesting/person-interesting.component.ts b/webapp/src/app/modules/person-interesting/person-interesting.component.ts index 2f1d807a..2d4dc1e3 100644 --- a/webapp/src/app/modules/person-interesting/person-interesting.component.ts +++ b/webapp/src/app/modules/person-interesting/person-interesting.component.ts @@ -106,7 +106,7 @@ export class PersonInterestingComponent implements OnInit { }); } - return tags.sort((a, b) => b.count - a.count).slice(0, MAX_TAGS); + return tags.slice(0, MAX_TAGS).sort((a, b) => b.count - a.count); }); readonly legendGroups = computed(() =>