Fix DFG top authors aggregation
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
@@ -660,7 +660,6 @@ async def _top_project_authors(
|
||||
page=page,
|
||||
size=size,
|
||||
person_ids=selected_person_ids,
|
||||
aliases=aliases,
|
||||
)
|
||||
|
||||
if not project_hits:
|
||||
@@ -781,7 +780,6 @@ async def _dfg_project_author_hits(
|
||||
page: int,
|
||||
size: int,
|
||||
person_ids: set[int],
|
||||
aliases: list[str],
|
||||
) -> tuple[list[dict[str, Any]], int]:
|
||||
response = await elasticsearch.search(
|
||||
index=ESIndex.DFG_PROJECTS,
|
||||
@@ -792,27 +790,13 @@ async def _dfg_project_author_hits(
|
||||
"id",
|
||||
"project_id",
|
||||
"persons",
|
||||
*DFG_INSTITUTION_FIELDS,
|
||||
],
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
|
||||
_dfg_institution_query(aliases),
|
||||
|
||||
{
|
||||
"nested": {
|
||||
"path": "persons",
|
||||
"query": {
|
||||
"terms": {
|
||||
"persons.person_id": sorted(
|
||||
person_ids
|
||||
)
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
]
|
||||
"nested": {
|
||||
"path": "persons",
|
||||
"query": {
|
||||
"terms": {"persons.person_id": sorted(person_ids)}
|
||||
},
|
||||
}
|
||||
},
|
||||
"sort": [
|
||||
@@ -853,9 +837,9 @@ async def _dfg_project_author_hits(
|
||||
return hits, total
|
||||
|
||||
def _dfg_project_id(project: dict[str, Any]) -> str | None:
|
||||
project_id = project.get("project_id")
|
||||
project_id = project.get("id")
|
||||
if project_id is None:
|
||||
project_id = project.get("id")
|
||||
project_id = project.get("project_id")
|
||||
return str(project_id) if project_id is not None else None
|
||||
|
||||
|
||||
@@ -911,4 +895,4 @@ async def _top_news_authors(authors: list[dict[str, Any]]) -> list[TopAuthor]:
|
||||
)
|
||||
for bucket in buckets
|
||||
if str(bucket.get("key", "")).casefold() in institution_authors
|
||||
][:TOP_AUTHOR_LIMIT]
|
||||
][:TOP_AUTHOR_LIMIT]
|
||||
|
||||
@@ -9,7 +9,6 @@ from sqlmodel import Session, SQLModel, create_engine
|
||||
from inse import config
|
||||
from inse.auth.model import AccessToken, Organization, UserRole
|
||||
from inse.dashboard.service import (
|
||||
DFG_INSTITUTION_FIELDS,
|
||||
get_dashboard_organization,
|
||||
get_dashboard_statistics,
|
||||
get_top_authors,
|
||||
@@ -141,7 +140,7 @@ async def test_top_authors_maps_works_and_dfg_project_aggregations():
|
||||
{
|
||||
"_source": {
|
||||
"id": "ES1",
|
||||
"project_id": "P1",
|
||||
"project_id": "legacy-P1",
|
||||
"persons": [
|
||||
{"person_id": 2, "full_name": "Grace Example"},
|
||||
{
|
||||
@@ -154,7 +153,7 @@ async def test_top_authors_maps_works_and_dfg_project_aggregations():
|
||||
{
|
||||
"_source": {
|
||||
"id": "ES2",
|
||||
"project_id": "P2",
|
||||
"project_id": "legacy-P2a",
|
||||
"persons": [
|
||||
{"person_id": 2, "full_name": "Grace Example"},
|
||||
{"person_id": 2, "full_name": "Grace Example"},
|
||||
@@ -163,8 +162,8 @@ async def test_top_authors_maps_works_and_dfg_project_aggregations():
|
||||
},
|
||||
{
|
||||
"_source": {
|
||||
"id": "ES3",
|
||||
"project_id": "P2",
|
||||
"id": "ES2",
|
||||
"project_id": "legacy-P2b",
|
||||
"persons": [
|
||||
{"person_id": 2, "full_name": "Grace Example"},
|
||||
],
|
||||
@@ -232,34 +231,21 @@ async def test_top_authors_maps_works_and_dfg_project_aggregations():
|
||||
if call.kwargs["index"] == ESIndex.DFG_PROJECTS
|
||||
]
|
||||
assert dfg_project_calls[0].kwargs["body"]["_source"] == [
|
||||
"id",
|
||||
"project_id",
|
||||
"persons",
|
||||
*DFG_INSTITUTION_FIELDS,
|
||||
"id",
|
||||
"project_id",
|
||||
"persons",
|
||||
]
|
||||
|
||||
query = dfg_project_calls[0].kwargs["body"]["query"]
|
||||
|
||||
assert query["bool"]["must"][0]["bool"]["minimum_should_match"] == 1
|
||||
assert query["bool"]["must"][0]["bool"]["should"][0]["bool"]["should"][0][
|
||||
"match"
|
||||
] == {
|
||||
"Antragstellende Institution": {
|
||||
"query": "Example Org",
|
||||
"operator": "and",
|
||||
}
|
||||
}
|
||||
|
||||
assert query["bool"]["must"][1] == {
|
||||
"nested": {
|
||||
"path": "persons",
|
||||
"query": {
|
||||
"terms": {
|
||||
"persons.person_id": [2],
|
||||
}
|
||||
assert dfg_project_calls[0].kwargs["body"]["query"] == {
|
||||
"nested": {
|
||||
"path": "persons",
|
||||
"query": {
|
||||
"terms": {
|
||||
"persons.person_id": [2],
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
||||
Reference in New Issue
Block a user