diff --git a/service/src/main/inse/logic.py b/service/src/main/inse/logic.py index 1ca95754..42c32923 100644 --- a/service/src/main/inse/logic.py +++ b/service/src/main/inse/logic.py @@ -366,6 +366,14 @@ def search_persons_by_name(author_name: str, limit: Optional[int] = 10) -> model } } }, + { + "match_phrase_prefix": { + "display_name": { + "query": author_name, + "boost": 3 + } + } + }, { "match": { "display_name": { 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 221648c9..820c062b 100644 --- a/webapp/src/app/modules/person-list/person-list.component.html +++ b/webapp/src/app/modules/person-list/person-list.component.html @@ -1,3 +1,7 @@ +@if (!isPersonsLoading && state.persons().length > 0) { +

{{ state.persons().length }} Ergebnisse

+} + @if (!isPersonsLoading){ @for (person of state.persons(); track person.id) { @@ -14,6 +18,7 @@

{{ person.name }}

+

{{ getDistinguishingId(person) }}

@if (person.affiliations!=undefined){

{{ person.affiliations[0]?.institution }} 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 e12337d7..10174b2e 100644 --- a/webapp/src/app/modules/person-list/person-list.component.scss +++ b/webapp/src/app/modules/person-list/person-list.component.scss @@ -1,3 +1,9 @@ +.result-count { + margin: 0 0 12px; + font-size: 14px; + color: #666; +} + .person-card { width: 100%; height: 100%; @@ -35,6 +41,12 @@ margin: 0; } +.person-id { + font-size: 11px; + color: #aaa; + margin: 0; +} + .affiliation { color: #666; margin: 0; 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 8a69628f..38469f7a 100644 --- a/webapp/src/app/modules/person-list/person-list.component.ts +++ b/webapp/src/app/modules/person-list/person-list.component.ts @@ -43,7 +43,7 @@ export class PersonListComponent implements OnInit{ this.personsService.searchPersonsByName(author_name).subscribe({ next: (result) => { - this.state.persons.set(result.persons ?? []); + this.state.persons.set(this.sortByRanking(result.persons ?? [])); this.state.hasSearched.set(true); this.isPersonsLoading = false }, @@ -71,5 +71,65 @@ export class PersonListComponent implements OnInit{ console.log(id) this.router.navigate(['/persons',id]); } - + + sortByRanking(persons: Person[]): Person[] { + const personsByRank = new Map(); + + for (const person of persons) { + const rank = this.getSortRank(person); + if (!personsByRank.has(rank)) { + personsByRank.set(rank, []); + } + personsByRank.get(rank)!.push(person); + } + + const sortedRanks = Array.from(personsByRank.keys()).sort((a, b) => a - b); + const sortedPersons: Person[] = []; + + for (const rank of sortedRanks) { + sortedPersons.push(...personsByRank.get(rank)!); + } + + return sortedPersons; + } + + getSortRank(person: Person): number { + if (this.hasInstitution(person) && this.hasOrcid(person)) { + return 0; + } + if (this.hasInstitution(person)) { + return 1; + } + if (this.hasOrcid(person)) { + return 2; + } + return 3; + } + + hasInstitution(person: Person): boolean { + if (!person.affiliations) { + return false; + } + for (const affiliation of person.affiliations) { + if (affiliation.institution) { + return true; + } + } + return false; + } + + hasOrcid(person: Person): boolean { + const ids = person.ids as { orcid?: string } | null | undefined; + return !!ids?.orcid; + } + + // if a person has an ORCID, use it as the distinguishing ID, otherwise use the regular ID + getDistinguishingId(person: Person): string { + const ids = person.ids as { orcid?: string } | null | undefined; + const orcid = ids?.orcid; + if (orcid) { + return 'ORCID: ' + orcid.replace('https://orcid.org/', ''); + } + return 'OpenAlexID: ' + person.id; + } }