works: count interesting-for topics like the publications filter

This commit is contained in:
2026-07-07 01:08:14 +02:00
parent 213edf8a5f
commit cf9a5df4e9
2 changed files with 26 additions and 2 deletions
+25 -1
View File
@@ -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
@@ -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(() =>