From e9d931fe74b5e01f45d6d1e8386a26f251a5fca4 Mon Sep 17 00:00:00 2001 From: genja Date: Tue, 9 Jun 2026 18:20:11 +0200 Subject: [PATCH 01/10] UI adjusted --- .../person-list/person-list.component.scss | 4 +-- .../app-searchbar.component.html | 1 + webapp/src/styles.scss | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/webapp/src/app/modules/person-list/person-list.component.scss b/webapp/src/app/modules/person-list/person-list.component.scss index a605117a..5b958d69 100644 --- a/webapp/src/app/modules/person-list/person-list.component.scss +++ b/webapp/src/app/modules/person-list/person-list.component.scss @@ -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; } diff --git a/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html b/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html index 145c976a..cc3cefd5 100644 --- a/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html +++ b/webapp/src/app/shared/ui/app-searchbar/app-searchbar.component.html @@ -16,6 +16,7 @@ @for (person of filteredPersons.results; track person.id) { + person {{ person.display_name }} } diff --git a/webapp/src/styles.scss b/webapp/src/styles.scss index 0a3a5f8d..7bc24191 100644 --- a/webapp/src/styles.scss +++ b/webapp/src/styles.scss @@ -190,4 +190,29 @@ h3 { @keyframes sk-shimmer { 0% { background-position: -600px 0; } 100% { 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); } \ No newline at end of file -- 2.56.1 From bc99b6deb84e100b18b37ec31618ebb89f5965d7 Mon Sep 17 00:00:00 2001 From: genja Date: Tue, 9 Jun 2026 18:21:16 +0200 Subject: [PATCH 02/10] moved sorting logic to backend --- service/src/main/inse/persons/logic.py | 32 ++------ service/src/main/inse/persons/service.py | 8 ++ webapp/src/app/api/api/persons.service.ts | 28 +++++-- .../app/api/api/persons.serviceInterface.ts | 8 +- webapp/src/app/app.routes.ts | 2 + .../person-list/person-list.component.html | 17 ++-- .../person-list/person-list.component.ts | 82 ++++++++++++++----- .../src/app/resolvers/person-list.resolver.ts | 4 + 8 files changed, 117 insertions(+), 64 deletions(-) diff --git a/service/src/main/inse/persons/logic.py b/service/src/main/inse/persons/logic.py index a4dc5c0f..199548fa 100644 --- a/service/src/main/inse/persons/logic.py +++ b/service/src/main/inse/persons/logic.py @@ -19,7 +19,7 @@ from inse.models.authors_list_response import AuthorsListResponse from inse import util from inse.integrations import elasticsearch from inse.models.meta import Meta -from inse.persons.query_builder import build_authors_search +from inse.persons.query_builder import build_authors_search, build_authors_search_rescored from inse.persons.model import CustomAuthor, CustomAuthorsListResponse, PersonSearchRequest logger = logging.getLogger(__name__) INDEX_NAME="openalex-authors" @@ -122,30 +122,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: @@ -358,6 +334,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, @@ -367,9 +345,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, diff --git a/service/src/main/inse/persons/service.py b/service/src/main/inse/persons/service.py index c442b578..5f04bd02 100644 --- a/service/src/main/inse/persons/service.py +++ b/service/src/main/inse/persons/service.py @@ -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, diff --git a/webapp/src/app/api/api/persons.service.ts b/webapp/src/app/api/api/persons.service.ts index b93da20a..7efacfa9 100644 --- a/webapp/src/app/api/api/persons.service.ts +++ b/webapp/src/app/api/api/persons.service.ts @@ -723,6 +723,8 @@ export class PersonsService extends BaseService implements PersonsServiceInterfa * @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 @@ -733,16 +735,20 @@ export class PersonsService extends BaseService implements PersonsServiceInterfa * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ - public searchPersonsList(query?: string, institutionName?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public searchPersonsList(query?: string, institutionName?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public searchPersonsList(query?: string, institutionName?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public searchPersonsList(query?: string, institutionName?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + public searchPersonsList(query?: string, institutionName?: string, sortBy?: string, sortOrder?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public searchPersonsList(query?: string, institutionName?: string, sortBy?: string, sortOrder?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public searchPersonsList(query?: string, institutionName?: string, sortBy?: string, sortOrder?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public searchPersonsList(query?: string, institutionName?: string, sortBy?: string, sortOrder?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { let localVarQueryParameters = new HttpParams({encoder: this.encoder}); localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, query, 'query'); localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, institutionName, 'institutionName'); + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + sortBy, 'sortBy'); + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + sortOrder, 'sortOrder'); if (topic) { topic.forEach((element) => { localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, @@ -808,6 +814,8 @@ export class PersonsService extends BaseService implements PersonsServiceInterfa * @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 @@ -818,16 +826,20 @@ export class PersonsService extends BaseService implements PersonsServiceInterfa * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ - public searchPersonsList_5(query?: string, institutionName?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public searchPersonsList_5(query?: string, institutionName?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public searchPersonsList_5(query?: string, institutionName?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public searchPersonsList_5(query?: string, institutionName?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + public searchPersonsList_5(query?: string, institutionName?: string, sortBy?: string, sortOrder?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public searchPersonsList_5(query?: string, institutionName?: string, sortBy?: string, sortOrder?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public searchPersonsList_5(query?: string, institutionName?: string, sortBy?: string, sortOrder?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public searchPersonsList_5(query?: string, institutionName?: string, sortBy?: string, sortOrder?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { let localVarQueryParameters = new HttpParams({encoder: this.encoder}); localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, query, 'query'); localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, institutionName, 'institutionName'); + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + sortBy, 'sortBy'); + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + sortOrder, 'sortOrder'); if (topic) { topic.forEach((element) => { localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, diff --git a/webapp/src/app/api/api/persons.serviceInterface.ts b/webapp/src/app/api/api/persons.serviceInterface.ts index 0c634b4d..2b68be3a 100644 --- a/webapp/src/app/api/api/persons.serviceInterface.ts +++ b/webapp/src/app/api/api/persons.serviceInterface.ts @@ -130,6 +130,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 @@ -138,7 +140,7 @@ export interface PersonsServiceInterface { * @param filterMode Filter mode: \'in\' or \'from\' * @param filterYear Filter year */ - searchPersonsList(query?: string, institutionName?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, extraHttpRequestParams?: any): Observable; + searchPersonsList(query?: string, institutionName?: string, sortBy?: string, sortOrder?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, extraHttpRequestParams?: any): Observable; /** * Searches for persons with advanced filters (Topic & Institution) and pagination. @@ -146,6 +148,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 @@ -154,6 +158,6 @@ export interface PersonsServiceInterface { * @param filterMode Filter mode: \'in\' or \'from\' * @param filterYear Filter year */ - searchPersonsList_5(query?: string, institutionName?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, extraHttpRequestParams?: any): Observable; + searchPersonsList_5(query?: string, institutionName?: string, sortBy?: string, sortOrder?: string, topic?: Array, page?: number, pageSize?: number, include?: string, strict?: boolean, filterMode?: string, filterYear?: number, extraHttpRequestParams?: any): Observable; } diff --git a/webapp/src/app/app.routes.ts b/webapp/src/app/app.routes.ts index 19a5df19..f3912e15 100644 --- a/webapp/src/app/app.routes.ts +++ b/webapp/src/app/app.routes.ts @@ -35,6 +35,8 @@ export const routes: Routes = [ 'page', 'pageSize', 'institutionName', + 'sortBy', + 'sortOrder', 'yearFilterEnabled', 'filterMode', 'filterYear', diff --git a/webapp/src/app/modules/person-list/person-list.component.html b/webapp/src/app/modules/person-list/person-list.component.html index 789862a8..e34d6123 100644 --- a/webapp/src/app/modules/person-list/person-list.component.html +++ b/webapp/src/app/modules/person-list/person-list.component.html @@ -50,10 +50,15 @@
Sortierung:
- + + + + + +
@@ -66,9 +71,9 @@ Sortiert nach Publikationen und Zitierungen--> - @if (sortedPersons.length) { + @if (getPersons().length) {
- @for (person of sortedPersons; track person.id) { + @for (person of getPersons(); track person.id) { diff --git a/webapp/src/app/modules/person-list/person-list.component.ts b/webapp/src/app/modules/person-list/person-list.component.ts index b1afc0f0..1cee49fc 100644 --- a/webapp/src/app/modules/person-list/person-list.component.ts +++ b/webapp/src/app/modules/person-list/person-list.component.ts @@ -12,14 +12,30 @@ import { MatButtonModule } from '@angular/material/button'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatRadioModule } from '@angular/material/radio'; -import { CustomAuthor, DehydratedInstitution, PersonsService, InstitutionsService } from '../../api'; +import { + CustomAuthor, + DehydratedInstitution, + PersonsService, + InstitutionsService, +} from '../../api'; import { TopicsService } from '../../api/api/topics.service'; import { TopicHierarchyComponent } from '../topic-hierarchy/topic-hierarchy.component'; import { PersonCardComponent } from '../person-card/person-card.component'; import { SharedStateService } from '../../shared/services/shared-state.service'; import { PaginationService } from '../../shared/services/pagination.service'; -import { finalize, debounceTime, distinctUntilChanged, switchMap, map, of, catchError } from 'rxjs'; -import { MatAutocompleteModule, MatAutocompleteSelectedEvent } from '@angular/material/autocomplete'; +import { + finalize, + debounceTime, + distinctUntilChanged, + switchMap, + map, + of, + catchError, +} from 'rxjs'; +import { + MatAutocompleteModule, + MatAutocompleteSelectedEvent, +} from '@angular/material/autocomplete'; import { MatSnackBar } from '@angular/material/snack-bar'; import { SkTextDirective } from '../../custom-directives/sk-text.directive'; import { @@ -71,6 +87,8 @@ export class PersonListComponent { readonly institutionOptions = signal([]); readonly institutionLookupLoading = signal(false); + defaultOrderValue = 'desc'; + // Selected filter states selectedTopics = new Set(); searchValue = signal(null); @@ -82,7 +100,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 }); @@ -138,6 +162,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' @@ -149,16 +175,21 @@ 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; + this.sortValueControl.setValue(sortBy); + this.sortOrderControl.setValue(sortOrder); // Sync search box & institution input if (this.searchValue() !== query) { this.searchValue.set(query || null); } if (this.institutionControl.value !== institutionName) { - this.institutionControl.setValue(institutionName, { emitEvent: false }); + this.institutionControl.setValue(institutionName, { + emitEvent: false, + }); this.updateYearFilterState(institutionName); } if (this.yearFilterEnabledControl.value !== yearFilterEnabled) { @@ -186,20 +217,24 @@ export class PersonListComponent { this.total = persons.meta?.count; this.loadingState.set(false); }); + // listen for sorting selectors changes + this.sortValueControl.valueChanges.subscribe((value) => { + if (!value) { + this.sortOrderControl.setValue(this.defaultOrderValue) + this.sortOrderControl.disable(); + } else { + this.sortOrderControl.enable(); + } + this.applySidebarFilters(); + }); + this.sortOrderControl.valueChanges.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), - ); - } - return sorted; + getPersons(): CustomAuthor[] { + return this.persons; } get loading(): boolean { @@ -211,6 +246,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); @@ -280,6 +319,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' @@ -317,8 +358,6 @@ export class PersonListComponent { return `${start}-${end} von ${this.total} Personen`; } - - // Bookmarks toggleBookmark(person: CustomAuthor): void { if (!person.id) return; @@ -353,12 +392,10 @@ export class PersonListComponent { this.searchValue.set(null); this.router.navigate([], { queryParams: { query: null, page: 1 }, - queryParamsHandling:"merge", + queryParamsHandling: 'merge', }); } - - private setupInstitutionAutocomplete(): void { this.institutionControl.valueChanges .pipe( @@ -386,7 +423,8 @@ export class PersonListComponent { } private searchInstitutions(query: string) { - return this.institutionsService.autocompleteInstitutions(query, undefined, undefined, 10) + return this.institutionsService + .autocompleteInstitutions(query, undefined, undefined, 10) .pipe(map((response) => response.results ?? [])); } diff --git a/webapp/src/app/resolvers/person-list.resolver.ts b/webapp/src/app/resolvers/person-list.resolver.ts index a5503d67..dcf8994e 100644 --- a/webapp/src/app/resolvers/person-list.resolver.ts +++ b/webapp/src/app/resolvers/person-list.resolver.ts @@ -26,6 +26,8 @@ export const personListResolver: ResolveFn = ( : 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 = ( return personsService.searchPersonsList( query, institutionName, + sortBy, + sortOrder, topics, page, pageSize, -- 2.56.1 From f0a83635364aee51e4497402f4fceae5af210a4b Mon Sep 17 00:00:00 2001 From: genja Date: Tue, 9 Jun 2026 18:23:59 +0200 Subject: [PATCH 03/10] added relevancy rescoring for persons search based on publications, citations, h_index, mean_citations and name quality --- .../src/main/inse/persons/query_builder.py | 331 +++++++++++++++++- 1 file changed, 324 insertions(+), 7 deletions(-) diff --git a/service/src/main/inse/persons/query_builder.py b/service/src/main/inse/persons/query_builder.py index 279bfb98..f4f52a5c 100644 --- a/service/src/main/inse/persons/query_builder.py +++ b/service/src/main/inse/persons/query_builder.py @@ -1,11 +1,13 @@ # -*- 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, @@ -13,7 +15,7 @@ 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, ) -> dict: """ Builds an Elasticsearch search request query body for authors as a dictionary. @@ -167,7 +169,7 @@ def build_authors_search( ] } }) - + if topics: for t in topics: if t: @@ -220,11 +222,326 @@ 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 + + +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, + 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, + 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. + """ + # 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 + } + } + + # 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 + } + } + } + }) + 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 functions: + inner_query = None + if query_clause: + if filter_clauses: + inner_query = { + "bool": { + "must": [query_clause], + "filter": filter_clauses + } + } + else: + inner_query = query_clause + else: + if filter_clauses: + inner_query = { + "bool": { + "filter": filter_clauses + } + } + else: + inner_query = {"match_all": {}} + + body["query"] = { + "function_score": { + "query": inner_query, + "functions": functions, + "score_mode": "multiply", + "boost_mode": "replace" + } + } + else: + 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 -- 2.56.1 From aa28aa0e025304c616cb618a7f019621e20356ec Mon Sep 17 00:00:00 2001 From: genja Date: Tue, 9 Jun 2026 19:00:11 +0200 Subject: [PATCH 04/10] sorting logic in UI fixed --- .../person-list/person-list.component.ts | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/webapp/src/app/modules/person-list/person-list.component.ts b/webapp/src/app/modules/person-list/person-list.component.ts index 1cee49fc..24648ef7 100644 --- a/webapp/src/app/modules/person-list/person-list.component.ts +++ b/webapp/src/app/modules/person-list/person-list.component.ts @@ -162,7 +162,7 @@ export class PersonListComponent { ? Number.parseInt(params['pageSize'], 10) : 10; const institutionName = params['institutionName'] || ''; - const sortBy = params['sortBy'] || null + const sortBy = params['sortBy'] || null; const sortOrder = params['sortOrder'] || this.defaultOrderValue; const yearFilterEnabled = params['yearFilterEnabled'] === 'true'; const filterMode = @@ -179,8 +179,13 @@ export class PersonListComponent { this.selectedTopics = new Set(topics); this.currentPage = page; this.paginationService.selection = pageSize; - this.sortValueControl.setValue(sortBy); - this.sortOrderControl.setValue(sortOrder); + + 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) { @@ -217,21 +222,40 @@ export class PersonListComponent { this.total = persons.meta?.count; this.loadingState.set(false); }); - // listen for sorting selectors changes - this.sortValueControl.valueChanges.subscribe((value) => { - if (!value) { - this.sortOrderControl.setValue(this.defaultOrderValue) - this.sortOrderControl.disable(); - } else { - this.sortOrderControl.enable(); - } + + // 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.subscribe(() => { + }); + + this.sortOrderControl.valueChanges + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe(() => { this.applySidebarFilters(); - }); + }); } + private updateSortOrderState(value: any) { + if (!value) { + this.sortOrderControl.setValue(this.defaultOrderValue, { + emitEvent: false, + }); + this.sortOrderControl.disable({ emitEvent: false }); + } else { + this.sortOrderControl.enable({ emitEvent: false }); + } + } // Getters for filtered results getPersons(): CustomAuthor[] { return this.persons; -- 2.56.1 From 58156025e90f517f9edf05f16ae69a7cbac463b7 Mon Sep 17 00:00:00 2001 From: genja Date: Tue, 9 Jun 2026 19:02:31 +0200 Subject: [PATCH 05/10] replaced old person search logic by the new rescored logic --- service/src/main/inse/persons/logic.py | 2 +- .../src/main/inse/persons/query_builder.py | 448 +++++++++--------- 2 files changed, 225 insertions(+), 225 deletions(-) diff --git a/service/src/main/inse/persons/logic.py b/service/src/main/inse/persons/logic.py index 199548fa..8b6cd643 100644 --- a/service/src/main/inse/persons/logic.py +++ b/service/src/main/inse/persons/logic.py @@ -19,7 +19,7 @@ from inse.models.authors_list_response import AuthorsListResponse from inse import util from inse.integrations import elasticsearch from inse.models.meta import Meta -from inse.persons.query_builder import build_authors_search, build_authors_search_rescored +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" diff --git a/service/src/main/inse/persons/query_builder.py b/service/src/main/inse/persons/query_builder.py index f4f52a5c..01bd9343 100644 --- a/service/src/main/inse/persons/query_builder.py +++ b/service/src/main/inse/persons/query_builder.py @@ -1,232 +1,232 @@ # -*- 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( +# 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 +# } +# } - # 2. Build Filters - filter_clauses = [] +# # 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" - } - } - } - } +# # 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" +# ], +# "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 +# 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 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 - } - } - } - }) +# 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": {} - } +# # 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 +# # 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 +# # 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 +# # 5. Sorting +# if sort_by and sort_order: +# body["sort"] = [ +# {sort_by: {"order": sort_order}}, +# ] +# return body def build_authors_search_rescored( @@ -275,14 +275,14 @@ def build_authors_search_rescored( } } }, - { - "match": { - "display_name": { - "query": query, - "fuzziness": 1 - } - } - } + # { + # "match": { + # "display_name": { + # "query": query, + # "fuzziness": 1 + # } + # } + # } ], "minimum_should_match": 1 } -- 2.56.1 From 0f212d189ea17c734466c0a0c72b9930a0022f2e Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 10 Jun 2026 14:13:28 +0200 Subject: [PATCH 06/10] removed fuzziness from person names matching + added applying rescoring strategy when query is empty --- .../src/main/inse/persons/query_builder.py | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/service/src/main/inse/persons/query_builder.py b/service/src/main/inse/persons/query_builder.py index 01bd9343..a258b99a 100644 --- a/service/src/main/inse/persons/query_builder.py +++ b/service/src/main/inse/persons/query_builder.py @@ -275,14 +275,13 @@ def build_authors_search_rescored( } } }, - # { - # "match": { - # "display_name": { - # "query": query, - # "fuzziness": 1 - # } - # } - # } + { + "match": { + "display_name": { + "query": query + } + } + } ], "minimum_should_match": 1 } @@ -473,7 +472,7 @@ def build_authors_search_rescored( functions.append(works_count_boost_query) # Combine query and filters body = {} - + if functions: inner_query = None if query_clause: @@ -486,6 +485,15 @@ def build_authors_search_rescored( } 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: if filter_clauses: inner_query = { @@ -495,15 +503,15 @@ def build_authors_search_rescored( } else: inner_query = {"match_all": {}} - - body["query"] = { - "function_score": { - "query": inner_query, - "functions": functions, - "score_mode": "multiply", - "boost_mode": "replace" + # 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 query_clause: if filter_clauses: -- 2.56.1 From abe96098b5161a585cd799cb7c18bda440dd27f3 Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 10 Jun 2026 14:13:58 +0200 Subject: [PATCH 07/10] increased timeout for elastic rqeuests up to 30 seconds --- service/src/main/inse/integrations/elasticsearch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/src/main/inse/integrations/elasticsearch.py b/service/src/main/inse/integrations/elasticsearch.py index 2bb78629..654cf455 100644 --- a/service/src/main/inse/integrations/elasticsearch.py +++ b/service/src/main/inse/integrations/elasticsearch.py @@ -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, -- 2.56.1 From 6979aaef8d7f15f5f545202362ce02059579044b Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 10 Jun 2026 14:22:03 +0200 Subject: [PATCH 08/10] fixed loading component --- .../app/modules/person/person.component.html | 20 ++++++++----------- .../shared/ui/loading/loading.component.html | 4 +++- .../shared/ui/loading/loading.component.ts | 5 +++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/webapp/src/app/modules/person/person.component.html b/webapp/src/app/modules/person/person.component.html index 065b3638..ad1e8518 100644 --- a/webapp/src/app/modules/person/person.component.html +++ b/webapp/src/app/modules/person/person.component.html @@ -50,10 +50,10 @@
@if (isBioLoading()) { + [size]="150" + [diameter]="150"> } @else if (personBio() != null) {

Biografie

{{ personBio() }}

@@ -86,15 +86,11 @@ } @if (isNetworkResolving()) { -
-
- - - graph_3 - -
- Das Netzwerk wird gebaut, kleinen Moment... -
+ } @else { } diff --git a/webapp/src/app/shared/ui/loading/loading.component.html b/webapp/src/app/shared/ui/loading/loading.component.html index c85ce5c1..e8f07ec6 100644 --- a/webapp/src/app/shared/ui/loading/loading.component.html +++ b/webapp/src/app/shared/ui/loading/loading.component.html @@ -1,6 +1,8 @@
- + {{ icon }} diff --git a/webapp/src/app/shared/ui/loading/loading.component.ts b/webapp/src/app/shared/ui/loading/loading.component.ts index 4e658d55..2a317fd4 100644 --- a/webapp/src/app/shared/ui/loading/loading.component.ts +++ b/webapp/src/app/shared/ui/loading/loading.component.ts @@ -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; } -- 2.56.1 From 8e284916e65b921992228f2b5b47a9a6e08785e4 Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 10 Jun 2026 14:25:20 +0200 Subject: [PATCH 09/10] added resolver for person component --- webapp/src/app/app.routes.ts | 2 ++ .../app/modules/person/person.component.ts | 17 +++----------- webapp/src/app/resolvers/person.resolver.ts | 23 +++++++++++++++++++ .../ui/app-layout/app-layout.component.html | 12 +++++++--- 4 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 webapp/src/app/resolvers/person.resolver.ts diff --git a/webapp/src/app/app.routes.ts b/webapp/src/app/app.routes.ts index 07e09215..c19c5b60 100644 --- a/webapp/src/app/app.routes.ts +++ b/webapp/src/app/app.routes.ts @@ -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 = [ { @@ -75,6 +76,7 @@ export const routes: Routes = [ (mod) => mod.PersonComponent, ), resolve: { + personData: personResolver, personBio: personBioResolver, }, runGuardsAndResolvers: (from, to) => from.params['id'] !== to.params['id'], diff --git a/webapp/src/app/modules/person/person.component.ts b/webapp/src/app/modules/person/person.component.ts index 0d975d90..2dd189ec 100644 --- a/webapp/src/app/modules/person/person.component.ts +++ b/webapp/src/app/modules/person/person.component.ts @@ -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 }, diff --git a/webapp/src/app/resolvers/person.resolver.ts b/webapp/src/app/resolvers/person.resolver.ts new file mode 100644 index 00000000..a20198f2 --- /dev/null +++ b/webapp/src/app/resolvers/person.resolver.ts @@ -0,0 +1,23 @@ +import { ResolveFn } from '@angular/router'; +import { inject } from '@angular/core'; +import { AuthorsListResponse, PersonsService } from '../api'; + +export const personResolver: ResolveFn = ( + 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); +}; diff --git a/webapp/src/app/shared/ui/app-layout/app-layout.component.html b/webapp/src/app/shared/ui/app-layout/app-layout.component.html index b0149b11..1c3a8d9b 100644 --- a/webapp/src/app/shared/ui/app-layout/app-layout.component.html +++ b/webapp/src/app/shared/ui/app-layout/app-layout.component.html @@ -39,12 +39,18 @@
- @if (resolverState.isResolvingPersonsFromOutside()) { + @if (resolverState.isResolvingFromOutside('/persons')) { + [size]="200" + [diameter]="200" /> + } @else if (resolverState.isResolvingFromOutside('/person/')) { + } @else { } -- 2.56.1 From 560af6a1eb906d01176a892e146c117acefb005b Mon Sep 17 00:00:00 2001 From: genja Date: Wed, 10 Jun 2026 14:28:37 +0200 Subject: [PATCH 10/10] updated loadingState computing --- .../person-list/person-list.component.ts | 37 ++++--------------- .../shared/services/resolver-state.service.ts | 21 ++++++++--- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/webapp/src/app/modules/person-list/person-list.component.ts b/webapp/src/app/modules/person-list/person-list.component.ts index 24648ef7..12e84ef7 100644 --- a/webapp/src/app/modules/person-list/person-list.component.ts +++ b/webapp/src/app/modules/person-list/person-list.component.ts @@ -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,10 +69,13 @@ 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(false); + readonly loadingState = computed(() => + this.resolverStateService.isResolvingInside('/persons'), + ); persons: CustomAuthor[] = []; total = 0; currentPage = 1; @@ -124,22 +119,6 @@ export class PersonListComponent { // Bookmarking bookmarkedIds = new Set(); 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(); } @@ -185,7 +164,6 @@ export class PersonListComponent { this.sortOrderControl.setValue(sortOrder, { emitEvent: false }); this.updateSortOrderState(this.sortValueControl.value); } - // Sync search box & institution input if (this.searchValue() !== query) { @@ -220,9 +198,8 @@ 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)) diff --git a/webapp/src/app/shared/services/resolver-state.service.ts b/webapp/src/app/shared/services/resolver-state.service.ts index f3a3b79c..d992ae74 100644 --- a/webapp/src/app/shared/services/resolver-state.service.ts +++ b/webapp/src/app/shared/services/resolver-state.service.ts @@ -15,12 +15,6 @@ export class ResolverStateService { readonly previousUrl = signal(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; + } } -- 2.56.1