Revert "Align EU project author counts with person details"
This reverts commit 167913aa85.
This commit is contained in:
@@ -859,7 +859,7 @@ async def _top_eu_project_publication_authors(
|
||||
return []
|
||||
|
||||
publication_response = await elasticsearch.search(
|
||||
index=ESIndex.CORDIS_EU_PUBLICATIONS_WILDCARD,
|
||||
index=ESIndex.CORDIS_EU_FP7_PUBLICATIONS,
|
||||
body={
|
||||
"size": 10000,
|
||||
"_source": ["projectID", "doi", "qaProcessedDoi"],
|
||||
|
||||
@@ -215,15 +215,13 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
|
||||
"author": {
|
||||
"id": "https://openalex.org/A2",
|
||||
"display_name": "Grace Example",
|
||||
},
|
||||
"institutions": [{"id": ORG_INSTITUTION_ID}],
|
||||
}
|
||||
},
|
||||
{
|
||||
"author": {
|
||||
"id": "https://openalex.org/A1",
|
||||
"display_name": "Ada Example",
|
||||
},
|
||||
"institutions": [{"id": ORG_INSTITUTION_ID}],
|
||||
}
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -236,8 +234,7 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
|
||||
"author": {
|
||||
"id": "https://openalex.org/A2",
|
||||
"display_name": "Grace Example",
|
||||
},
|
||||
"institutions": [{"id": ORG_INSTITUTION_ID}],
|
||||
}
|
||||
}
|
||||
],
|
||||
}
|
||||
@@ -329,7 +326,7 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
|
||||
]
|
||||
assert len(works_calls) == 1
|
||||
works_body = works_calls[0].kwargs["body"]
|
||||
assert works_body["query"]["bool"]["filter"][0]["terms"]["doi"] == [
|
||||
assert works_body["query"]["terms"]["doi"] == [
|
||||
"https://doi.org/10.1234/p1",
|
||||
"https://doi.org/10.1234/p2",
|
||||
]
|
||||
@@ -337,7 +334,6 @@ async def test_top_authors_maps_works_patents_news_and_eu_projects():
|
||||
"doi",
|
||||
"authorships.author.id",
|
||||
"authorships.author.display_name",
|
||||
"authorships.institutions.id",
|
||||
]
|
||||
|
||||
|
||||
@@ -362,7 +358,7 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i
|
||||
}
|
||||
|
||||
if kwargs["index"] == config.settings.openalex_works_search_index:
|
||||
assert kwargs["body"]["query"]["bool"]["filter"][0]["terms"]["doi"] == [
|
||||
assert kwargs["body"]["query"]["terms"]["doi"] == [
|
||||
"https://doi.org/10.1/p1-a",
|
||||
"https://doi.org/10.1/p1-b",
|
||||
"https://doi.org/10.1/p2",
|
||||
@@ -378,15 +374,13 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i
|
||||
"author": {
|
||||
"id": "https://openalex.org/A1",
|
||||
"display_name": "Ada Example",
|
||||
},
|
||||
"institutions": [{"id": ORG_INSTITUTION_ID}],
|
||||
}
|
||||
},
|
||||
{
|
||||
"author": {
|
||||
"id": "https://openalex.org/A2",
|
||||
"display_name": "Grace Example",
|
||||
},
|
||||
"institutions": [{"id": ORG_INSTITUTION_ID}],
|
||||
}
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -399,8 +393,7 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i
|
||||
"author": {
|
||||
"id": "https://openalex.org/A1",
|
||||
"display_name": "Ada Example",
|
||||
},
|
||||
"institutions": [{"id": ORG_INSTITUTION_ID}],
|
||||
}
|
||||
}
|
||||
],
|
||||
}
|
||||
@@ -413,8 +406,7 @@ async def test_top_eu_project_authors_count_filtered_projects_by_stable_author_i
|
||||
"author": {
|
||||
"id": "https://openalex.org/A1",
|
||||
"display_name": "Ada Example",
|
||||
},
|
||||
"institutions": [{"id": ORG_INSTITUTION_ID}],
|
||||
}
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
@@ -488,17 +488,12 @@ def _get_raw_doi(doi: str) -> str:
|
||||
Returns:
|
||||
str: The raw DOI string.
|
||||
"""
|
||||
normalized = doi.strip().lower()
|
||||
for prefix in (
|
||||
"https://doi.org/",
|
||||
"http://doi.org/",
|
||||
"https://dx.doi.org/",
|
||||
"http://dx.doi.org/",
|
||||
"doi.org/",
|
||||
):
|
||||
if normalized.startswith(prefix):
|
||||
return normalized.removeprefix(prefix)
|
||||
return normalized
|
||||
if doi.startswith("https://doi.org/"):
|
||||
return doi[len("https://doi.org/") :]
|
||||
elif doi.startswith("http://dx.doi.org/"):
|
||||
return doi[len("http://dx.doi.org/") :]
|
||||
else:
|
||||
return doi
|
||||
|
||||
|
||||
async def get_cordis_eu_publications_by_dois(dois: List[str]):
|
||||
@@ -510,29 +505,12 @@ async def get_cordis_eu_publications_by_dois(dois: List[str]):
|
||||
Returns:
|
||||
_type_: The retrieved publications.
|
||||
"""
|
||||
raw_dois = sorted({_get_raw_doi(doi) for doi in dois if doi.strip()})
|
||||
canonical_dois = [f"https://doi.org/{doi}" for doi in raw_dois]
|
||||
doi_values = sorted(set(raw_dois + canonical_dois))
|
||||
query = {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{
|
||||
"bool": {
|
||||
"should": [
|
||||
{"terms": {"doi": doi_values}},
|
||||
{"terms": {"qaProcessedDoi": doi_values}},
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
raw_dois = [_get_raw_doi(doi) for doi in dois]
|
||||
query = {"bool": {"filter": [{"terms": {"qaProcessedDoi": raw_dois}}]}}
|
||||
|
||||
response = await elasticsearch.search(
|
||||
query=query,
|
||||
index=ESIndex.CORDIS_EU_PUBLICATIONS_WILDCARD,
|
||||
size=10000,
|
||||
cluster=ESCluster.INSE,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from inse import config
|
||||
from inse.model import ESCluster, ESIndex
|
||||
from inse.projects.projects_search_client import (
|
||||
get_cordis_eu_project_ids_by_dois,
|
||||
)
|
||||
from inse.works.logic import get_publication_dois_of_author
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def anyio_backend():
|
||||
return "asyncio"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_project_ids_match_raw_and_processed_cordis_dois():
|
||||
response = {
|
||||
"hits": {
|
||||
"hits": [
|
||||
{"_source": {"projectID": "P1", "doi": "10.1/first"}},
|
||||
{
|
||||
"_source": {
|
||||
"projectID": "P2",
|
||||
"qaProcessedDoi": "10.1/second",
|
||||
}
|
||||
},
|
||||
{"_source": {"projectID": "P2", "doi": "10.1/second"}},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
with patch(
|
||||
"inse.projects.projects_search_client.elasticsearch.search",
|
||||
new=AsyncMock(return_value=response),
|
||||
) as search:
|
||||
project_ids = await get_cordis_eu_project_ids_by_dois(
|
||||
["https://doi.org/10.1/FIRST", "doi.org/10.1/SECOND"]
|
||||
)
|
||||
|
||||
assert set(project_ids) == {"P1", "P2"}
|
||||
search.assert_awaited_once_with(
|
||||
query={
|
||||
"bool": {
|
||||
"filter": [
|
||||
{
|
||||
"bool": {
|
||||
"should": [
|
||||
{
|
||||
"terms": {
|
||||
"doi": [
|
||||
"10.1/first",
|
||||
"10.1/second",
|
||||
"https://doi.org/10.1/first",
|
||||
"https://doi.org/10.1/second",
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"terms": {
|
||||
"qaProcessedDoi": [
|
||||
"10.1/first",
|
||||
"10.1/second",
|
||||
"https://doi.org/10.1/first",
|
||||
"https://doi.org/10.1/second",
|
||||
]
|
||||
}
|
||||
},
|
||||
],
|
||||
"minimum_should_match": 1,
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
index=ESIndex.CORDIS_EU_PUBLICATIONS_WILDCARD,
|
||||
size=10000,
|
||||
cluster=ESCluster.INSE,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_author_dois_use_the_same_configured_works_index_as_dashboard():
|
||||
with patch(
|
||||
"inse.works.logic.elasticsearch.search",
|
||||
new=AsyncMock(
|
||||
return_value={
|
||||
"hits": {
|
||||
"hits": [
|
||||
{"_source": {"doi": "https://doi.org/10.1/example"}}
|
||||
]
|
||||
}
|
||||
}
|
||||
),
|
||||
) as search:
|
||||
dois = await get_publication_dois_of_author("a123")
|
||||
|
||||
assert dois == ["https://doi.org/10.1/example"]
|
||||
assert search.await_args.kwargs["index"] == (
|
||||
config.settings.openalex_works_search_index
|
||||
)
|
||||
assert search.await_args.kwargs["query"]["bool"]["must"][0]["nested"][
|
||||
"query"
|
||||
]["term"] == {
|
||||
"authorships.author.id": "https://openalex.org/A123"
|
||||
}
|
||||
@@ -1015,7 +1015,7 @@ async def get_publication_dois_of_author(
|
||||
|
||||
try:
|
||||
response = await elasticsearch.search(
|
||||
index=config.settings.openalex_works_search_index,
|
||||
index="openalex-works",
|
||||
source=["doi"],
|
||||
size=10000,
|
||||
query=query,
|
||||
|
||||
Reference in New Issue
Block a user