ts-82-author-overview-and-description #134
@@ -45,7 +45,7 @@ def search(
|
||||
}
|
||||
}
|
||||
|
||||
with httpx.Client() as client:
|
||||
with httpx.Client(timeout=httpx.Timeout(30.0)) as client:
|
||||
response = client.post(
|
||||
f"{config.settings.elasticsearch_url}/{index}/_search",
|
||||
json=payload,
|
||||
|
||||
@@ -19,7 +19,7 @@ from inse.models.openalex.authors_list_response import AuthorsListResponse
|
||||
from inse import util
|
||||
from inse.integrations import elasticsearch
|
||||
from inse.models.openalex.meta import Meta
|
||||
from inse.persons.query_builder import build_authors_search
|
||||
from inse.persons.query_builder import build_authors_search_rescored
|
||||
from inse.persons.model import CustomAuthor, CustomAuthorsListResponse, PersonSearchRequest
|
||||
logger = logging.getLogger(__name__)
|
||||
INDEX_NAME="openalex-authors"
|
||||
@@ -237,30 +237,6 @@ def get_person_by_id(author_id: str, include: Optional[str] = None) -> AuthorsLi
|
||||
return AuthorsListResponse(results=persons)
|
||||
|
||||
|
||||
|
||||
def get_person_by_id(author_id: str, include: Optional[str] = None) -> AuthorsListResponse:
|
||||
body = {
|
||||
"_source":include.split(",") if include else True,
|
||||
}
|
||||
|
||||
try:
|
||||
hit = elasticsearch.get(
|
||||
index="openalex-authors",
|
||||
body=body,
|
||||
doc_id=author_id
|
||||
)
|
||||
except NotFoundError:
|
||||
raise HTTPException(
|
||||
status_code=404, detail=f"Person with id {author_id} not found"
|
||||
)
|
||||
|
||||
except ApiError as e:
|
||||
raise HTTPException(status_code=500, detail=f"Elasticsearch error: {str(e)}")
|
||||
persons = [util.get_persons_data(hit)]
|
||||
|
||||
return AuthorsListResponse(results=persons)
|
||||
|
||||
|
||||
def search_persons_by_name(
|
||||
author_name: str, limit: Optional[int] = 10, page_offset: Optional[int] = 0, include: Optional[str] = None
|
||||
) -> AuthorsListResponse:
|
||||
@@ -473,6 +449,8 @@ def _enrich_author_data(author_data) -> Optional[CustomAuthor]:
|
||||
def advanced_search_persons(
|
||||
query: Optional[str] = None,
|
||||
institution_name: Optional[str] = None,
|
||||
sort_by: Optional[str] = None,
|
||||
sort_order: Optional[str] = None,
|
||||
topics: Optional[List[str]] = None,
|
||||
page: int = 1,
|
||||
page_size: int = 10,
|
||||
@@ -482,9 +460,11 @@ def advanced_search_persons(
|
||||
filter_year: Optional[int] = None,
|
||||
) -> CustomAuthorsListResponse:
|
||||
try:
|
||||
query_body = build_authors_search(
|
||||
query_body = build_authors_search_rescored(
|
||||
query=query,
|
||||
institution_name=institution_name,
|
||||
sort_by=sort_by,
|
||||
sort_order=sort_order,
|
||||
topics=topics,
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
|
||||
@@ -1,11 +1,241 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from typing import List, Optional, Set, Any
|
||||
import json
|
||||
# def build_authors_search(
|
||||
# using: Any = None,
|
||||
# index: Optional[str] = None,
|
||||
# query: Optional[str] = None,
|
||||
# institution_name: Optional[str] = None,
|
||||
# sort_by: Optional[str] = None,
|
||||
# sort_order: Optional[str] = None,
|
||||
# topics: Optional[List[str]] = None,
|
||||
# page: int = 1,
|
||||
# page_size: int = 10,
|
||||
# include: Optional[Set[str]] = None,
|
||||
# strict: Optional[bool] = False,
|
||||
# track_total_hits: Optional[bool] = False,
|
||||
# filter_mode: Optional[str] = "from",
|
||||
# filter_year: Optional[int] = None,
|
||||
# ) -> dict:
|
||||
# """
|
||||
# Builds an Elasticsearch search request query body for authors as a dictionary.
|
||||
# """
|
||||
# # 1. Build Query Clauses
|
||||
# query_clause = None
|
||||
# if query:
|
||||
# query_clause = {
|
||||
# "bool": {
|
||||
# "should": [
|
||||
# {
|
||||
# "match_phrase": {
|
||||
# "display_name": {
|
||||
# "query": query,
|
||||
# "boost": 5
|
||||
# }
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "match_phrase_prefix": {
|
||||
# "display_name": {
|
||||
# "query": query,
|
||||
# "boost": 3
|
||||
# }
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "match": {
|
||||
# "display_name": {
|
||||
# "query": query,
|
||||
# "fuzziness": 1
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# ],
|
||||
# "minimum_should_match": 1
|
||||
# }
|
||||
# }
|
||||
|
||||
def build_authors_search(
|
||||
# # 2. Build Filters
|
||||
# filter_clauses = []
|
||||
|
||||
# # Filter against false entries (nested ((Works > 2 AND Year > 2020) OR has last_known_institution))
|
||||
# filter_clauses.append({
|
||||
# "bool": {
|
||||
# "should": [
|
||||
# {
|
||||
# "bool": {
|
||||
# "filter": [
|
||||
# {
|
||||
# "range": { "works_count": { "gt": 2 } }
|
||||
# },
|
||||
# {
|
||||
# "nested": {
|
||||
# "path": "counts_by_year",
|
||||
# "query": {
|
||||
# "range": { "counts_by_year.year": { "gt": 2020 } } # hardcoded for now
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "nested": {
|
||||
# "path": "last_known_institutions",
|
||||
# "query": {
|
||||
# "exists": {
|
||||
# "field": "last_known_institutions.id"
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
|
||||
# ],
|
||||
# "minimum_should_match": 1
|
||||
# }
|
||||
# })
|
||||
# # Institution filter with optional year-based filtering
|
||||
# if institution_name:
|
||||
# if filter_year is not None:
|
||||
# target_year = filter_year
|
||||
# mode = filter_mode or "from"
|
||||
# else:
|
||||
# from datetime import datetime
|
||||
# current_year = datetime.now().year
|
||||
# target_year = current_year - 1
|
||||
# mode = "from"
|
||||
|
||||
# range_query = {"gte": target_year}
|
||||
# if mode == "in":
|
||||
# range_query["lte"] = target_year
|
||||
|
||||
# if strict:
|
||||
# filter_clauses.append({
|
||||
# "nested": {
|
||||
# "path": "affiliations",
|
||||
# "query": {
|
||||
# "bool": {
|
||||
# "filter": [
|
||||
# {
|
||||
# "match_phrase": {
|
||||
# "affiliations.institution.display_name": institution_name
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "range": {
|
||||
# "affiliations.years": range_query
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# })
|
||||
# else:
|
||||
# filter_clauses.append({
|
||||
# "bool": {
|
||||
# "filter": [
|
||||
# {
|
||||
# "nested": {
|
||||
# "path": "last_known_institutions",
|
||||
# "query": {
|
||||
# "match_phrase": {
|
||||
# "last_known_institutions.display_name": institution_name
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "nested": {
|
||||
# "path": "affiliations",
|
||||
# "query": {
|
||||
# "bool": {
|
||||
# "filter": [
|
||||
# {
|
||||
# "match_phrase": {
|
||||
# "affiliations.institution.display_name": institution_name
|
||||
# }
|
||||
# },
|
||||
# {
|
||||
# "range": {
|
||||
# "affiliations.years": range_query
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# })
|
||||
|
||||
# if topics:
|
||||
# for t in topics:
|
||||
# if t:
|
||||
# filter_clauses.append({
|
||||
# "nested": {
|
||||
# "path": "topics",
|
||||
# "query": {
|
||||
# "match_phrase": {
|
||||
# "topics.display_name": t
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# })
|
||||
|
||||
# # Combine query and filters
|
||||
# body = {}
|
||||
# if query_clause:
|
||||
# if filter_clauses:
|
||||
# body["query"] = {
|
||||
# "bool": {
|
||||
# "must": [query_clause],
|
||||
# "filter": filter_clauses
|
||||
# }
|
||||
# }
|
||||
# else:
|
||||
# body["query"] = query_clause
|
||||
# else:
|
||||
# if filter_clauses:
|
||||
# body["query"] = {
|
||||
# "bool": {
|
||||
# "filter": filter_clauses
|
||||
# }
|
||||
# }
|
||||
# else:
|
||||
# body["query"] = {
|
||||
# "match_all": {}
|
||||
# }
|
||||
|
||||
# # 3. Source Filtering
|
||||
# if include:
|
||||
# body["_source"] = list(include)
|
||||
# else:
|
||||
# body["_source"] = True
|
||||
|
||||
# # 4. Pagination
|
||||
# es_size = page_size
|
||||
# es_from = (page - 1) * page_size
|
||||
# body["from"] = es_from
|
||||
# body["size"] = es_size
|
||||
# body["track_total_hits"] = track_total_hits
|
||||
|
||||
# # 5. Sorting
|
||||
# if sort_by and sort_order:
|
||||
# body["sort"] = [
|
||||
# {sort_by: {"order": sort_order}},
|
||||
# ]
|
||||
# return body
|
||||
|
||||
|
||||
def build_authors_search_rescored(
|
||||
using: Any = None,
|
||||
index: Optional[str] = None,
|
||||
query: Optional[str] = None,
|
||||
institution_name: Optional[str] = None,
|
||||
sort_by: Optional[str] = None,
|
||||
sort_order: Optional[str] = None,
|
||||
topics: Optional[List[str]] = None,
|
||||
page: int = 1,
|
||||
page_size: int = 10,
|
||||
@@ -13,7 +243,12 @@ def build_authors_search(
|
||||
strict: Optional[bool] = False,
|
||||
track_total_hits: Optional[bool] = False,
|
||||
filter_mode: Optional[str] = "from",
|
||||
filter_year: Optional[int] = None
|
||||
filter_year: Optional[int] = None,
|
||||
name_quality_boost = True,
|
||||
h_index_boost = True,
|
||||
citations_boost =True,
|
||||
works_boost = True,
|
||||
_2yr_mean_citedness_boost = True,
|
||||
) -> dict:
|
||||
"""
|
||||
Builds an Elasticsearch search request query body for authors as a dictionary.
|
||||
@@ -43,8 +278,7 @@ def build_authors_search(
|
||||
{
|
||||
"match": {
|
||||
"display_name": {
|
||||
"query": query,
|
||||
"fuzziness": 1
|
||||
"query": query
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,7 +401,7 @@ def build_authors_search(
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
if topics:
|
||||
for t in topics:
|
||||
if t:
|
||||
@@ -181,30 +415,123 @@ def build_authors_search(
|
||||
}
|
||||
}
|
||||
})
|
||||
functions = []
|
||||
if not sort_by:
|
||||
|
||||
if (name_quality_boost): # Name quality boost, boost names which are not "Value Value"
|
||||
name_boost_query={
|
||||
"script_score": {
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"source": "String name = doc['display_name.keyword'].value.toLowerCase(); String[] parts = name.splitOnToken(' ');Set unique = new HashSet();for (String p : parts) { unique.add(p); }return unique.size() > 1 ? 1.0 : 0.3;"
|
||||
}
|
||||
}
|
||||
}
|
||||
functions.append(name_boost_query)
|
||||
if (h_index_boost): # h_index boost
|
||||
h_index_boost_query={
|
||||
"script_score": {
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"source": "if (!doc.containsKey('summary_stats.h_index') || doc['summary_stats.h_index'].empty) return 1.0;double h = doc['summary_stats.h_index'].value;return 1.0 + Math.log1p(h) / 5.0;"
|
||||
}
|
||||
}
|
||||
}
|
||||
functions.append(h_index_boost_query)
|
||||
if (citations_boost): # cited_by_count boost
|
||||
cited_by_count_boost_query = {
|
||||
"script_score": {
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"source": "if (!doc.containsKey('cited_by_count') || doc['cited_by_count'].empty) return 1.0;double citations = doc['cited_by_count'].value;return 1.0 + Math.log1p(citations) / 10.0;"
|
||||
}
|
||||
}
|
||||
}
|
||||
functions.append(cited_by_count_boost_query)
|
||||
|
||||
if (_2yr_mean_citedness_boost): # 2yr mean citedness boost
|
||||
mean_citedness_boost_query = {
|
||||
"script_score": {
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"source": "if (!doc.containsKey('summary_stats.2yr_mean_citedness') || doc['summary_stats.2yr_mean_citedness'].empty) return 1.0;double recent = doc['summary_stats.2yr_mean_citedness'].value;return 1.0 + Math.log1p(recent) / 8.0;"
|
||||
}
|
||||
}
|
||||
}
|
||||
functions.append(mean_citedness_boost_query)
|
||||
|
||||
if (works_boost): # works_count boost
|
||||
works_count_boost_query = {
|
||||
"script_score": {
|
||||
"script": {
|
||||
"lang": "painless",
|
||||
"source": "if (!doc.containsKey('works_count') || doc['works_count'].empty) return 1.0;double works = doc['works_count'].value;return 1.0 + Math.log1p(works) / 8.0;"
|
||||
}
|
||||
}
|
||||
}
|
||||
functions.append(works_count_boost_query)
|
||||
# Combine query and filters
|
||||
body = {}
|
||||
if query_clause:
|
||||
if filter_clauses:
|
||||
body["query"] = {
|
||||
"bool": {
|
||||
"must": [query_clause],
|
||||
"filter": filter_clauses
|
||||
|
||||
if functions:
|
||||
inner_query = None
|
||||
if query_clause:
|
||||
if filter_clauses:
|
||||
inner_query = {
|
||||
"bool": {
|
||||
"must": [query_clause],
|
||||
"filter": filter_clauses
|
||||
}
|
||||
}
|
||||
else:
|
||||
inner_query = query_clause
|
||||
# if query not null then multiply with name matching
|
||||
body["query"] = {
|
||||
"function_score": {
|
||||
"query": inner_query,
|
||||
"functions": functions,
|
||||
"score_mode": "multiply",
|
||||
"boost_mode": "multiply"
|
||||
}
|
||||
}
|
||||
else:
|
||||
body["query"] = query_clause
|
||||
if filter_clauses:
|
||||
inner_query = {
|
||||
"bool": {
|
||||
"filter": filter_clauses
|
||||
}
|
||||
}
|
||||
else:
|
||||
inner_query = {"match_all": {}}
|
||||
# if the query is null, replace the scoring completely
|
||||
body["query"] = {
|
||||
"function_score": {
|
||||
"query": inner_query,
|
||||
"functions": functions,
|
||||
"score_mode": "multiply",
|
||||
"boost_mode": "replace"
|
||||
}
|
||||
}
|
||||
else:
|
||||
if filter_clauses:
|
||||
body["query"] = {
|
||||
"bool": {
|
||||
"filter": filter_clauses
|
||||
if query_clause:
|
||||
if filter_clauses:
|
||||
body["query"] = {
|
||||
"bool": {
|
||||
"must": [query_clause],
|
||||
"filter": filter_clauses
|
||||
}
|
||||
}
|
||||
}
|
||||
else:
|
||||
body["query"] = query_clause
|
||||
else:
|
||||
body["query"] = {
|
||||
"match_all": {}
|
||||
}
|
||||
if filter_clauses:
|
||||
body["query"] = {
|
||||
"bool": {
|
||||
"filter": filter_clauses
|
||||
}
|
||||
}
|
||||
else:
|
||||
body["query"] = {"match_all": {}}
|
||||
|
||||
# 3. Source Filtering
|
||||
if include:
|
||||
@@ -220,11 +547,9 @@ def build_authors_search(
|
||||
body["track_total_hits"] = track_total_hits
|
||||
|
||||
# 5. Sorting
|
||||
if not query:
|
||||
if sort_by and sort_order:
|
||||
body["sort"] = [
|
||||
{"cited_by_count": {"order": "desc"}},
|
||||
{"works_count": {"order": "desc"}}
|
||||
{sort_by: {"order": sort_order}},
|
||||
]
|
||||
|
||||
return body
|
||||
|
||||
|
||||
@@ -190,6 +190,12 @@ def search_persons_list(
|
||||
institution_name: Annotated[
|
||||
Optional[str], Query(alias="institutionName", description="Filter by institution name")
|
||||
] = None,
|
||||
sort_by: Annotated[
|
||||
Optional[str], Query(alias="sortBy", description="Value to sort by")
|
||||
] = None,
|
||||
sort_order: Annotated[
|
||||
Optional[str], Query(alias="sortOrder", description="asc or desc?")
|
||||
] = None,
|
||||
topic: Annotated[
|
||||
Optional[List[str]], Query(description="Filter by topic display names")
|
||||
] = None,
|
||||
@@ -224,6 +230,8 @@ def search_persons_list(
|
||||
return logic.advanced_search_persons(
|
||||
query=query,
|
||||
institution_name=institution_name,
|
||||
sort_by=sort_by,
|
||||
sort_order=sort_order,
|
||||
topics=topic,
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
|
||||
@@ -1371,6 +1371,8 @@ export class PersonsService
|
||||
* @endpoint get /api/inse-service/persons/search-list
|
||||
* @param query Search query (e.g., Arman AND Arzani)
|
||||
* @param institutionName Filter by institution name
|
||||
* @param sortBy Value to sort by
|
||||
* @param sortOrder asc or desc?
|
||||
* @param topic Filter by topic display names
|
||||
* @param page Page number (1-indexed)
|
||||
* @param pageSize Results per page
|
||||
@@ -1384,6 +1386,8 @@ export class PersonsService
|
||||
public searchPersonsList(
|
||||
query?: string,
|
||||
institutionName?: string,
|
||||
sortBy?: string,
|
||||
sortOrder?: string,
|
||||
topic?: Array<string>,
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
@@ -1402,6 +1406,8 @@ export class PersonsService
|
||||
public searchPersonsList(
|
||||
query?: string,
|
||||
institutionName?: string,
|
||||
sortBy?: string,
|
||||
sortOrder?: string,
|
||||
topic?: Array<string>,
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
@@ -1420,6 +1426,8 @@ export class PersonsService
|
||||
public searchPersonsList(
|
||||
query?: string,
|
||||
institutionName?: string,
|
||||
sortBy?: string,
|
||||
sortOrder?: string,
|
||||
topic?: Array<string>,
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
@@ -1438,6 +1446,8 @@ export class PersonsService
|
||||
public searchPersonsList(
|
||||
query?: string,
|
||||
institutionName?: string,
|
||||
sortBy?: string,
|
||||
sortOrder?: string,
|
||||
topic?: Array<string>,
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
@@ -1464,6 +1474,16 @@ export class PersonsService
|
||||
<any>institutionName,
|
||||
'institutionName',
|
||||
);
|
||||
localVarQueryParameters = this.addToHttpParams(
|
||||
localVarQueryParameters,
|
||||
<any>sortBy,
|
||||
'sortBy',
|
||||
);
|
||||
localVarQueryParameters = this.addToHttpParams(
|
||||
localVarQueryParameters,
|
||||
<any>sortOrder,
|
||||
'sortOrder',
|
||||
);
|
||||
if (topic) {
|
||||
topic.forEach((element) => {
|
||||
localVarQueryParameters = this.addToHttpParams(
|
||||
@@ -1559,6 +1579,8 @@ export class PersonsService
|
||||
* @endpoint get /api/inse-service/persons/search-list
|
||||
* @param query Search query (e.g., Arman AND Arzani)
|
||||
* @param institutionName Filter by institution name
|
||||
* @param sortBy Value to sort by
|
||||
* @param sortOrder asc or desc?
|
||||
* @param topic Filter by topic display names
|
||||
* @param page Page number (1-indexed)
|
||||
* @param pageSize Results per page
|
||||
@@ -1572,6 +1594,8 @@ export class PersonsService
|
||||
public searchPersonsList_5(
|
||||
query?: string,
|
||||
institutionName?: string,
|
||||
sortBy?: string,
|
||||
sortOrder?: string,
|
||||
topic?: Array<string>,
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
@@ -1590,6 +1614,8 @@ export class PersonsService
|
||||
public searchPersonsList_5(
|
||||
query?: string,
|
||||
institutionName?: string,
|
||||
sortBy?: string,
|
||||
sortOrder?: string,
|
||||
topic?: Array<string>,
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
@@ -1608,6 +1634,8 @@ export class PersonsService
|
||||
public searchPersonsList_5(
|
||||
query?: string,
|
||||
institutionName?: string,
|
||||
sortBy?: string,
|
||||
sortOrder?: string,
|
||||
topic?: Array<string>,
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
@@ -1626,6 +1654,8 @@ export class PersonsService
|
||||
public searchPersonsList_5(
|
||||
query?: string,
|
||||
institutionName?: string,
|
||||
sortBy?: string,
|
||||
sortOrder?: string,
|
||||
topic?: Array<string>,
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
@@ -1652,6 +1682,16 @@ export class PersonsService
|
||||
<any>institutionName,
|
||||
'institutionName',
|
||||
);
|
||||
localVarQueryParameters = this.addToHttpParams(
|
||||
localVarQueryParameters,
|
||||
<any>sortBy,
|
||||
'sortBy',
|
||||
);
|
||||
localVarQueryParameters = this.addToHttpParams(
|
||||
localVarQueryParameters,
|
||||
<any>sortOrder,
|
||||
'sortOrder',
|
||||
);
|
||||
if (topic) {
|
||||
topic.forEach((element) => {
|
||||
localVarQueryParameters = this.addToHttpParams(
|
||||
|
||||
@@ -176,6 +176,8 @@ export interface PersonsServiceInterface {
|
||||
* @endpoint get /api/inse-service/persons/search-list
|
||||
* @param query Search query (e.g., Arman AND Arzani)
|
||||
* @param institutionName Filter by institution name
|
||||
* @param sortBy Value to sort by
|
||||
* @param sortOrder asc or desc?
|
||||
* @param topic Filter by topic display names
|
||||
* @param page Page number (1-indexed)
|
||||
* @param pageSize Results per page
|
||||
@@ -187,6 +189,8 @@ export interface PersonsServiceInterface {
|
||||
searchPersonsList(
|
||||
query?: string,
|
||||
institutionName?: string,
|
||||
sortBy?: string,
|
||||
sortOrder?: string,
|
||||
topic?: Array<string>,
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
@@ -203,6 +207,8 @@ export interface PersonsServiceInterface {
|
||||
* @endpoint get /api/inse-service/persons/search-list
|
||||
* @param query Search query (e.g., Arman AND Arzani)
|
||||
* @param institutionName Filter by institution name
|
||||
* @param sortBy Value to sort by
|
||||
* @param sortOrder asc or desc?
|
||||
* @param topic Filter by topic display names
|
||||
* @param page Page number (1-indexed)
|
||||
* @param pageSize Results per page
|
||||
@@ -214,6 +220,8 @@ export interface PersonsServiceInterface {
|
||||
searchPersonsList_5(
|
||||
query?: string,
|
||||
institutionName?: string,
|
||||
sortBy?: string,
|
||||
sortOrder?: string,
|
||||
topic?: Array<string>,
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { userGuard } from './shared/guards/user.guard';
|
||||
import { collaborationNetworkResolver } from './resolvers/collaboration-network.resolver';
|
||||
import { personListResolver } from './resolvers/person-list.resolver';
|
||||
import { personBioResolver } from './resolvers/person-bio.resolver';
|
||||
import { personResolver } from './resolvers/person.resolver';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
@@ -36,6 +37,8 @@ export const routes: Routes = [
|
||||
'page',
|
||||
'pageSize',
|
||||
'institutionName',
|
||||
'sortBy',
|
||||
'sortOrder',
|
||||
'yearFilterEnabled',
|
||||
'filterMode',
|
||||
'filterYear',
|
||||
@@ -73,6 +76,7 @@ export const routes: Routes = [
|
||||
(mod) => mod.PersonComponent,
|
||||
),
|
||||
resolve: {
|
||||
personData: personResolver,
|
||||
personBio: personBioResolver,
|
||||
},
|
||||
runGuardsAndResolvers: (from, to) => from.params['id'] !== to.params['id'],
|
||||
|
||||
@@ -56,10 +56,15 @@
|
||||
<div class="sort-selector">
|
||||
<span class="sort-label">Sortierung:</span>
|
||||
<div class="select-wrapper">
|
||||
<select [formControl]="sortControl">
|
||||
<option value="relevance">Beste Treffer (Relevanz)</option>
|
||||
<option value="works">Publikationen (absteigend)</option>
|
||||
<option value="citations">Zitierungen (absteigend)</option>
|
||||
<select [formControl]="sortValueControl">
|
||||
<option [ngValue]="null">Beste Treffer (Relevanz)</option>
|
||||
<option value="works_count">Publikationen</option>
|
||||
<option value="cited_by_count">Zitierungen</option>
|
||||
</select>
|
||||
|
||||
<select [formControl]="sortOrderControl">
|
||||
<option value="desc">Absteigend</option>
|
||||
<option value="asc">Aufsteigend</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -74,9 +79,9 @@
|
||||
<!--><span>Sortiert nach Publikationen und Zitierungen</span>-->
|
||||
</div>
|
||||
|
||||
@if (sortedPersons.length) {
|
||||
@if (getPersons().length) {
|
||||
<div class="person-grid">
|
||||
@for (person of sortedPersons; track person.id) {
|
||||
@for (person of getPersons(); track person.id) {
|
||||
<app-person-card
|
||||
[loading]="loading"
|
||||
[person]="person"
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
|
||||
.layout-container {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 280px;
|
||||
grid-template-columns: 1fr 360px;
|
||||
gap: 24px;
|
||||
align-items: start;
|
||||
max-width: 1200px;
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, inject, signal, DestroyRef, Signal } from '@angular/core';
|
||||
import { Component, inject, signal, DestroyRef, computed } from '@angular/core';
|
||||
import { Router, RouterLink, ActivatedRoute } from '@angular/router';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
@@ -11,10 +11,10 @@ import { MatInputModule } from '@angular/material/input';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatRadioModule } from '@angular/material/radio';
|
||||
import { ResolverStateService } from '../../shared/services/resolver-state.service';
|
||||
|
||||
import {
|
||||
CustomAuthor,
|
||||
DehydratedInstitution,
|
||||
PersonsService,
|
||||
InstitutionsService,
|
||||
} from '../../api';
|
||||
@@ -36,15 +36,7 @@ import {
|
||||
MatAutocompleteModule,
|
||||
MatAutocompleteSelectedEvent,
|
||||
} from '@angular/material/autocomplete';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { SkTextDirective } from '../../custom-directives/sk-text.directive';
|
||||
import {
|
||||
NavigationError,
|
||||
NavigationEnd,
|
||||
NavigationStart,
|
||||
NavigationCancel,
|
||||
} from '@angular/router';
|
||||
import { createLoadError } from '../../shared/utils/errorHandler';
|
||||
|
||||
@Component({
|
||||
selector: 'app-person-list',
|
||||
@@ -77,16 +69,21 @@ export class PersonListComponent {
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
public readonly state = inject(SharedStateService);
|
||||
public readonly paginationService = inject(PaginationService);
|
||||
public readonly resolverStateService = inject(ResolverStateService);
|
||||
private readonly defaultIncludes =
|
||||
'display_name,works_count,cited_by_count,topics,orcid,relevance_rating,last_known_institutions,affiliations';
|
||||
|
||||
readonly loadingState = signal<boolean>(false);
|
||||
readonly loadingState = computed(() =>
|
||||
this.resolverStateService.isResolvingInside('/persons'),
|
||||
);
|
||||
persons: CustomAuthor[] = [];
|
||||
total = 0;
|
||||
currentPage = 1;
|
||||
readonly institutionOptions = signal<any[]>([]);
|
||||
readonly institutionLookupLoading = signal<boolean>(false);
|
||||
|
||||
defaultOrderValue = 'desc';
|
||||
|
||||
// Selected filter states
|
||||
selectedTopics = new Set<string>();
|
||||
searchValue = signal<string | null>(null);
|
||||
@@ -98,7 +95,13 @@ export class PersonListComponent {
|
||||
appliedFilterYear = new Date().getFullYear() - 1;
|
||||
|
||||
// Forms
|
||||
sortControl = new FormControl('works', { nonNullable: true });
|
||||
sortValueControl = new FormControl(null, {
|
||||
nonNullable: true,
|
||||
});
|
||||
sortOrderControl = new FormControl(
|
||||
{ value: this.defaultOrderValue, disabled: this.isRelevanceSelected() },
|
||||
{ nonNullable: true },
|
||||
);
|
||||
topicSearchControl = new FormControl('', { nonNullable: true });
|
||||
institutionControl = new FormControl('', { nonNullable: true });
|
||||
yearFilterEnabledControl = new FormControl(false, { nonNullable: true });
|
||||
@@ -116,22 +119,6 @@ export class PersonListComponent {
|
||||
// Bookmarking
|
||||
bookmarkedIds = new Set<string>();
|
||||
constructor() {
|
||||
this.router.events
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((event) => {
|
||||
if (event instanceof NavigationStart) {
|
||||
this.loadingState.set(true);
|
||||
}
|
||||
|
||||
if (
|
||||
event instanceof NavigationEnd ||
|
||||
event instanceof NavigationCancel ||
|
||||
event instanceof NavigationError
|
||||
) {
|
||||
this.loadingState.set(false);
|
||||
}
|
||||
});
|
||||
|
||||
if (!this.institutionControl.value) {
|
||||
this.yearFilterEnabledControl.disable();
|
||||
}
|
||||
@@ -154,6 +141,8 @@ export class PersonListComponent {
|
||||
? Number.parseInt(params['pageSize'], 10)
|
||||
: 10;
|
||||
const institutionName = params['institutionName'] || '';
|
||||
const sortBy = params['sortBy'] || null;
|
||||
const sortOrder = params['sortOrder'] || this.defaultOrderValue;
|
||||
const yearFilterEnabled = params['yearFilterEnabled'] === 'true';
|
||||
const filterMode =
|
||||
params['filterMode'] === 'in' || params['filterMode'] === 'from'
|
||||
@@ -165,10 +154,17 @@ export class PersonListComponent {
|
||||
|
||||
const topics = this.parseQueryParamArray(params['topic']);
|
||||
|
||||
// restore values from query params
|
||||
this.selectedTopics = new Set(topics);
|
||||
this.currentPage = page;
|
||||
this.paginationService.selection = pageSize;
|
||||
|
||||
if (this.sortValueControl.value !== sortBy) {
|
||||
this.sortValueControl.setValue(sortBy, { emitEvent: false });
|
||||
this.sortOrderControl.setValue(sortOrder, { emitEvent: false });
|
||||
this.updateSortOrderState(this.sortValueControl.value);
|
||||
}
|
||||
|
||||
// Sync search box & institution input
|
||||
if (this.searchValue() !== query) {
|
||||
this.searchValue.set(query || null);
|
||||
@@ -202,22 +198,44 @@ export class PersonListComponent {
|
||||
.subscribe(({ persons }) => {
|
||||
this.persons = (persons.results ?? []) as CustomAuthor[];
|
||||
this.total = persons.meta?.count;
|
||||
this.loadingState.set(false);
|
||||
});
|
||||
|
||||
// listen for sorting selectors changes
|
||||
this.sortValueControl.valueChanges
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((value) => {
|
||||
if (!value) {
|
||||
this.sortOrderControl.setValue(this.defaultOrderValue, {
|
||||
emitEvent: false,
|
||||
});
|
||||
this.sortOrderControl.disable();
|
||||
} else {
|
||||
this.sortOrderControl.enable();
|
||||
}
|
||||
|
||||
this.applySidebarFilters();
|
||||
});
|
||||
|
||||
this.sortOrderControl.valueChanges
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe(() => {
|
||||
this.applySidebarFilters();
|
||||
});
|
||||
}
|
||||
|
||||
// Getters for filtered results
|
||||
get sortedPersons(): CustomAuthor[] {
|
||||
const sorted = [...this.persons];
|
||||
const val = this.sortControl.value;
|
||||
if (val === 'works') {
|
||||
return sorted.sort((a, b) => (b.works_count ?? 0) - (a.works_count ?? 0));
|
||||
} else if (val === 'citations') {
|
||||
return sorted.sort(
|
||||
(a, b) => (b.cited_by_count ?? 0) - (a.cited_by_count ?? 0),
|
||||
);
|
||||
private updateSortOrderState(value: any) {
|
||||
if (!value) {
|
||||
this.sortOrderControl.setValue(this.defaultOrderValue, {
|
||||
emitEvent: false,
|
||||
});
|
||||
this.sortOrderControl.disable({ emitEvent: false });
|
||||
} else {
|
||||
this.sortOrderControl.enable({ emitEvent: false });
|
||||
}
|
||||
return sorted;
|
||||
}
|
||||
// Getters for filtered results
|
||||
getPersons(): CustomAuthor[] {
|
||||
return this.persons;
|
||||
}
|
||||
|
||||
get loading(): boolean {
|
||||
@@ -229,6 +247,10 @@ export class PersonListComponent {
|
||||
return this.selectedTopics.has(topic);
|
||||
}
|
||||
|
||||
isRelevanceSelected(): boolean {
|
||||
return !this.sortValueControl.value;
|
||||
}
|
||||
|
||||
toggleTopic(topic: string): void {
|
||||
if (this.selectedTopics.has(topic)) {
|
||||
this.selectedTopics.delete(topic);
|
||||
@@ -298,6 +320,8 @@ export class PersonListComponent {
|
||||
? Array.from(this.selectedTopics)
|
||||
: null,
|
||||
institutionName: this.institutionControl.value || null,
|
||||
sortBy: this.sortValueControl.value || null,
|
||||
sortOrder: this.sortOrderControl.value || null,
|
||||
yearFilterEnabled:
|
||||
this.institutionControl.value && this.yearFilterEnabledControl.value
|
||||
? 'true'
|
||||
|
||||
@@ -50,10 +50,10 @@
|
||||
<div class="bio-card">
|
||||
@if (isBioLoading()) {
|
||||
<app-loading
|
||||
text="Biografie wird geladen"
|
||||
text="Biografie wird geladen..."
|
||||
icon="description"
|
||||
size="200"
|
||||
diameter="200"></app-loading>
|
||||
[size]="150"
|
||||
[diameter]="150"></app-loading>
|
||||
} @else if (personBio() != null) {
|
||||
<h3>Biografie</h3>
|
||||
<p>{{ personBio() }}</p>
|
||||
@@ -86,15 +86,11 @@
|
||||
}
|
||||
<mat-tab-nav-panel #tabPanel class="person-panel">
|
||||
@if (isNetworkResolving()) {
|
||||
<div class="loading-container">
|
||||
<div class="spinner-container" style="--spinner-size: 150px">
|
||||
<mat-spinner diameter="150"></mat-spinner>
|
||||
<mat-icon class="spinner-icon" fontSet="material-symbols-outlined">
|
||||
graph_3
|
||||
</mat-icon>
|
||||
</div>
|
||||
<span>Das Netzwerk wird gebaut, kleinen Moment...</span>
|
||||
</div>
|
||||
<app-loading
|
||||
text="Das Netzwerk wird gebaut, kleinen Moment..."
|
||||
icon="graph_3"
|
||||
[size]="150"
|
||||
[diameter]="150" />
|
||||
} @else {
|
||||
<router-outlet></router-outlet>
|
||||
}
|
||||
|
||||
@@ -93,20 +93,9 @@ export class PersonComponent {
|
||||
readonly isBioLoading = signal(false);
|
||||
|
||||
readonly person = toSignal(
|
||||
toObservable(this.authorId).pipe(
|
||||
switchMap((id) => {
|
||||
if (!id) return of(null);
|
||||
this.isPersonLoading.set(true);
|
||||
return this.personsApi
|
||||
.searchPersons(id, undefined, PERSON_INCLUDE_TAGS)
|
||||
.pipe(
|
||||
map((result) => result.results?.[0] ?? null),
|
||||
catchError((err) => {
|
||||
console.error('Failed to load person:', err);
|
||||
return of(null);
|
||||
}),
|
||||
finalize(() => this.isPersonLoading.set(false)),
|
||||
);
|
||||
this.activatedRoute.data.pipe(
|
||||
map(({ personData }) => {
|
||||
return personData?.results[0] ?? null;
|
||||
}),
|
||||
),
|
||||
{ initialValue: null },
|
||||
|
||||
@@ -26,6 +26,8 @@ export const personListResolver: ResolveFn<CustomAuthorsListResponse> = (
|
||||
: 10;
|
||||
|
||||
const institutionName = params.get('institutionName') || undefined;
|
||||
const sortBy= params.get('sortBy') || undefined;
|
||||
const sortOrder= params.get('sortOrder') || undefined;
|
||||
|
||||
const topicsParam = params.getAll('topic');
|
||||
|
||||
@@ -47,6 +49,8 @@ export const personListResolver: ResolveFn<CustomAuthorsListResponse> = (
|
||||
return personsService.searchPersonsList(
|
||||
query,
|
||||
institutionName,
|
||||
sortBy,
|
||||
sortOrder,
|
||||
topics,
|
||||
page,
|
||||
pageSize,
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ResolveFn } from '@angular/router';
|
||||
import { inject } from '@angular/core';
|
||||
import { AuthorsListResponse, PersonsService } from '../api';
|
||||
|
||||
export const personResolver: ResolveFn<AuthorsListResponse> = (
|
||||
route,
|
||||
state,
|
||||
) => {
|
||||
const parseQueryParamArray = (val: any): string[] => {
|
||||
if (!val) return [];
|
||||
if (Array.isArray(val)) return val;
|
||||
return [val];
|
||||
};
|
||||
const PERSON_INCLUDE_TAGS =
|
||||
'topics_full,topic_share,summary_stats,ids,last_known_institutions,' +
|
||||
'sources,counts_by_year,works_api_url,dates,cited_by_count_boost';
|
||||
const params = route.paramMap;
|
||||
|
||||
const query = params.get('id') || undefined;
|
||||
const personsService = inject(PersonsService);
|
||||
|
||||
return personsService.searchPersons(query, undefined, PERSON_INCLUDE_TAGS);
|
||||
};
|
||||
@@ -15,12 +15,6 @@ export class ResolverStateService {
|
||||
readonly previousUrl = signal<string | null>(null);
|
||||
|
||||
readonly isResolving = computed(() => this.resolvingUrl() !== null);
|
||||
readonly isResolvingPersonsFromOutside = computed(() => {
|
||||
const from = this.previousUrl();
|
||||
const to = this.resolvingUrl();
|
||||
if (!to?.startsWith('/persons')) return false;
|
||||
return !from?.startsWith('/persons'); // came from outside
|
||||
});
|
||||
|
||||
constructor() {
|
||||
this.router.events.subscribe((event) => {
|
||||
@@ -38,4 +32,19 @@ export class ResolverStateService {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
isResolvingFromOutside(path: string) {
|
||||
const from = this.previousUrl();
|
||||
const to = this.resolvingUrl();
|
||||
if (!to?.startsWith(path)) return false;
|
||||
return !from?.startsWith(path); // came from outside
|
||||
}
|
||||
|
||||
isResolvingInside(path: string) {
|
||||
const from = this.previousUrl();
|
||||
const to = this.resolvingUrl();
|
||||
console.log(from, to, to?.startsWith(path) && from?.startsWith(path));
|
||||
if (to?.startsWith(path) && from?.startsWith(path)) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,12 +39,18 @@
|
||||
</mat-toolbar>
|
||||
|
||||
<main class="content">
|
||||
@if (resolverState.isResolvingPersonsFromOutside()) {
|
||||
@if (resolverState.isResolvingFromOutside('/persons')) {
|
||||
<app-loading
|
||||
text="Personenliste wird geladen..."
|
||||
icon="group"
|
||||
size="200"
|
||||
diameter="200"></app-loading>
|
||||
[size]="200"
|
||||
[diameter]="200" />
|
||||
} @else if (resolverState.isResolvingFromOutside('/person/')) {
|
||||
<app-loading
|
||||
text="Personendaten werden geladen..."
|
||||
icon="person"
|
||||
[size]="200"
|
||||
[diameter]="200" />
|
||||
} @else {
|
||||
<ng-content></ng-content>
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<mat-option
|
||||
[value]="person.display_name"
|
||||
(click)="selectPerson(person.display_name)">
|
||||
<mat-icon>person</mat-icon>
|
||||
<span>{{ person.display_name }}</span>
|
||||
</mat-option>
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<div class="loading-container">
|
||||
<div class="spinner-container" style="--spinner-size: {{ size }}px">
|
||||
<mat-progress-spinner diameter="{{ diameter }}"></mat-progress-spinner>
|
||||
<mat-progress-spinner
|
||||
[diameter]="diameter"
|
||||
[mode]="'indeterminate'"></mat-progress-spinner>
|
||||
<mat-icon class="spinner-icon" fontSet="material-symbols-outlined">
|
||||
{{ icon }}
|
||||
</mat-icon>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { MatProgressSpinner } from '@angular/material/progress-spinner';
|
||||
import { MatIcon } from '@angular/material/icon';
|
||||
import { numberAttribute } from '@angular/core';
|
||||
@Component({
|
||||
selector: 'app-loading',
|
||||
imports: [MatProgressSpinner, MatIcon],
|
||||
@@ -10,6 +11,6 @@ import { MatIcon } from '@angular/material/icon';
|
||||
export class LoadingComponent {
|
||||
@Input() text = 'Laden...';
|
||||
@Input() icon = 'graph_3';
|
||||
@Input() size = '150';
|
||||
@Input() diameter = '150';
|
||||
@Input({ transform: numberAttribute }) size = 150;
|
||||
@Input({ transform: numberAttribute }) diameter = 150;
|
||||
}
|
||||
|
||||
@@ -195,3 +195,27 @@ h3 {
|
||||
background-position: 600px 0;
|
||||
}
|
||||
}
|
||||
.cdk-overlay-pane {
|
||||
color: var(--sg-text);
|
||||
}
|
||||
|
||||
.cdk-overlay-pane .mat-mdc-option {
|
||||
padding: 0 18px;
|
||||
font-size: 13px;
|
||||
background: var(--sg-surface-muted);
|
||||
border-bottom: 1px solid var(--sg-border);
|
||||
}
|
||||
|
||||
.cdk-overlay-pane .mat-mdc-option:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.cdk-overlay-pane .mat-mdc-option mat-icon {
|
||||
margin-right: 12px;
|
||||
color: var(--sg-text-soft);
|
||||
}
|
||||
|
||||
.cdk-overlay-pane .mat-mdc-option:hover,
|
||||
.cdk-overlay-pane .mat-mdc-option.mdc-list-item--focused {
|
||||
background: rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
Reference in New Issue
Block a user