Merge branch 'dev' of nes.uni-due.de:lbs/smartguide into feature/keywords-analysis
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/pr-dev Build queued...

This commit is contained in:
2026-08-03 20:45:19 +02:00
3 changed files with 72 additions and 17 deletions
@@ -142,20 +142,55 @@ async def autocomplete_institutions(
if not query:
return InstitutionPageV2(elements=[], total=0, page=0, size=0)
stripped = query.strip()
fields = [("display_name", 1.0), ("display_name_alternatives", 0.8)]
should_clauses = []
for field, weight in fields:
should_clauses.extend([
{
"prefix": {
f"{field}.keyword": {
"value": stripped,
"case_insensitive": True,
"boost": 10.0 * weight,
}
}
},
{"match_phrase_prefix": {field: {"query": stripped, "boost": 5.0 * weight, "slop": 3}}},
{"match_bool_prefix": {field: {"query": stripped, "boost": 2.0 * weight}}},
{
"constant_score": {
"filter": {
"wildcard": {
f"{field}.keyword": {
"value": f"*{stripped}*",
"case_insensitive": True,
}
}
},
"boost": 1.0 * weight,
}
},
])
return await search_institutions(
page=page,
size=size,
query={
"bool": {
"should": [
{"match_phrase_prefix": {"display_name": query}},
{"match_phrase_prefix": {"display_name_alternatives": query}},
]
"function_score": {
"query": {"bool": {"should": should_clauses, "minimum_should_match": 1}},
"field_value_factor": {
"field": "works_count",
"modifier": "log1p",
"factor": 0.05,
"missing": 1.0,
},
"boost_mode": "multiply",
}
},
source=source,
)
async def autocomplete_institutions_for_selector(
query: str, page: int = 0, size: int = 10
@@ -19,6 +19,7 @@ import {
DehydratedInstitution,
PersonsService,
InstitutionsService,
InstitutionsV2Service,
WorkTopic,
} from '../../api';
import { TopicsService } from '../../api/api/topics.service';
@@ -75,6 +76,7 @@ export class PersonListComponent {
private readonly personsService = inject(PersonsService);
private readonly topicsService = inject(TopicsService);
private readonly institutionsService = inject(InstitutionsService);
private readonly institutionsV2Service = inject(InstitutionsV2Service);
private readonly destroyRef = inject(DestroyRef);
private readonly bookmarkService = inject(BookmarkService);
public readonly state = inject(SharedStateService);
@@ -643,9 +645,16 @@ export class PersonListComponent {
}
private searchInstitutions(query: string) {
return this.institutionsService
.autocompleteInstitutions(query, undefined, undefined, 10)
.pipe(map((response) => response.results ?? []));
return this.institutionsV2Service
.getInstitutionAutocompleteForSelector(query)
.pipe(
map((response) =>
(response.elements ?? []).map((inst) => ({
...inst,
hint: [inst.country_code, inst.type].filter(Boolean).join(' · '),
})),
),
);
}
updateYearFilterState(institution: DehydratedInstitution | null): void {
@@ -40,6 +40,8 @@ import {
AutocompleteResponseResultsInner,
UniversityRankingsService,
InstitutionsService,
InstitutionsV2Service,
InstitutionPageV2,
PersonsService,
OrganizationService,
Author,
@@ -105,6 +107,7 @@ export class UniTrendParentComponent implements OnInit {
private readonly apiService = inject(UniversityRankingsService);
private readonly topicsService = inject(TopicsService);
private readonly institutionsApiService = inject(InstitutionsService);
private readonly institutionsV2Service = inject(InstitutionsV2Service);
private readonly personsApiService = inject(PersonsService);
private readonly trendDataService = inject(TrendDataService);
private readonly organizationService = inject(OrganizationService, {
@@ -1306,11 +1309,15 @@ export class UniTrendParentComponent implements OnInit {
onSearchChange(query: string) {
this.searchQuery.set(query);
if (query.trim().length >= 3) {
this.institutionsApiService
.autocompleteInstitutions(query, undefined, 'education', 10)
this.institutionsV2Service
.getInstitutionAutocompleteForSelector(query)
.subscribe({
next: (res: AutocompleteResponse) => {
this.searchResults.set(res.results || []);
next: (res: InstitutionPageV2) => {
const mapped = (res.elements || []).map((inst) => ({
...inst,
hint: [inst.country_code, inst.type].filter(Boolean).join(' · '),
}));
this.searchResults.set(mapped);
},
error: () => {
this.searchResults.set([]);
@@ -1365,11 +1372,15 @@ export class UniTrendParentComponent implements OnInit {
onAuthorInstSearchChange(query: string) {
this.authorInstSearchQuery.set(query);
if (query.trim().length >= 3) {
this.institutionsApiService
.autocompleteInstitutions(query, undefined, 'education', 10)
this.institutionsV2Service
.getInstitutionAutocompleteForSelector(query)
.subscribe({
next: (res: AutocompleteResponse) => {
this.authorInstSearchResults.set(res.results || []);
next: (res: InstitutionPageV2) => {
const mapped = (res.elements || []).map((inst) => ({
...inst,
hint: [inst.country_code, inst.type].filter(Boolean).join(' · '),
}));
this.authorInstSearchResults.set(mapped);
},
error: () => {
this.authorInstSearchResults.set([]);