Merge branch 'dev' of https://project.nes.uni-due.de/gitea/lbs/smartguide into feature/keyword_search_rework
LocationBasedServices/smartguide/pipeline/pr-dev This commit looks good

This commit is contained in:
Kazgatari
2026-06-22 09:07:55 +02:00
18 changed files with 274 additions and 218 deletions
@@ -22,14 +22,13 @@ class CompanyConnectionsSearchClient:
self.base_url = (
base_url
or config.settings.elasticsearch_url
or config.settings.openalex_works_search_base_url
or ""
).rstrip("/")
self.api_key = (
api_key
if api_key is not None
else config.settings.elasticsearch_api_key
or config.settings.openalex_works_api_key
)
)
self.openalex_index = openalex_index
self.handelsregister_index = handelsregister_index
self.timeout = timeout
+5 -12
View File
@@ -26,22 +26,18 @@ class Settings(BaseSettings):
auth_disabled: bool = False
auth_standalone: bool = True
auth_secret: str = "change-me-to-a-secure-secret-key"
# OpenAlex works search config
openalex_works_search_base_url: str = "https://project.nes.uni-due.de/elastic"
# IMPORTANT: wildcard * needed to query all work indices
openalex_works_search_index: str = "openalex-works*"
openalex_works_api_key: str = (
"am1wWXBaMEJEVWJoZkE5MnBaUlk6TWlvbW1LRlMzNjdDUHgzYmVkUmI5UQ=="
)
openalex_works_search_timeout_seconds: float = 30.0
# OpenAlex public API config
openalex_api_base_url: str = "https://api.openalex.org"
openalex_api_key: Optional[str] = None
openalex_api_timeout_seconds: float = 30.0
# Patent elasticsearch config
# Patent Elasticsearch config
patent_elasticsearch_url: str = "https://inse.nes.uni-due.de/elastic"
patent_elasticsearch_api_key: str = ""
patent_elasticsearch_api_key: Optional[str] = None
# LLM config
@@ -52,8 +48,8 @@ class Settings(BaseSettings):
# Sentence Transformers config
sentence_transformers_model_name: str = "paraphrase-multilingual-mpnet-base-v2"
# elasticsearch config
elasticsearch_url: Optional[str] = None
# Elasticsearch config
elasticsearch_url: str = "https://project.nes.uni-due.de/elastic"
elasticsearch_api_key: Optional[str] = None
elasticsearch_inse_url: Optional[str] = None
elasticsearch_inse_api_key: Optional[str] = None
@@ -66,9 +62,6 @@ class Settings(BaseSettings):
{"url": "http://localhost:8000", "description": "Local development server"},
]
elasticsearch_inse_url: Optional[str] = None
elasticsearch_inse_api_key: Optional[str] = None
logging_level: str = "DEBUG"
@@ -23,9 +23,9 @@ class FundedPublicationsSearchClient:
timeout: float | None = None,
transport: httpx.AsyncBaseTransport | None = None,
):
self.base_url = (base_url or config.settings.openalex_works_search_base_url).rstrip("/")
self.base_url = (base_url or config.settings.elasticsearch_url or "").rstrip("/")
self.index = index or config.settings.openalex_works_search_index
self.api_key = api_key if api_key is not None else config.settings.openalex_works_api_key
self.api_key = api_key if api_key is not None else config.settings.elasticsearch_api_key
self.timeout = timeout if timeout is not None else config.settings.openalex_works_search_timeout_seconds
self.transport = transport
+3 -2
View File
@@ -26,12 +26,13 @@ class OpenAlexWorksSearchClient:
timeout: float | None = None,
transport: httpx.AsyncBaseTransport | None = None,
):
self.base_url = (base_url or config.settings.openalex_works_search_base_url).rstrip("/")
self.base_url = (base_url or config.settings.elasticsearch_url or "").rstrip("/")
self.index = index or config.settings.openalex_works_search_index
self.api_key = api_key if api_key is not None else config.settings.openalex_works_api_key
self.api_key = api_key if api_key is not None else config.settings.elasticsearch_api_key
self.timeout = timeout if timeout is not None else config.settings.openalex_works_search_timeout_seconds
self.transport = transport
def author_works_query(
self,
author_id: str,
@@ -4,34 +4,19 @@
<mat-divider />
<div class="search-and-sorting">
<mat-form-field style="width: 100%">
<mat-label>Suche nach Namen</mat-label>
<input
matInput
type="search"
[debounceTime]="300"
[(debouncedValue)]="urlSearchTerm"
(debouncedValueChange)="handleSearchTermChange($event)" />
<mat-icon matPrefix>search</mat-icon>
<button matIconButton matSuffix (click)="clearSearchTerm()">
<mat-icon>clear</mat-icon>
</button>
</mat-form-field>
<app-query-param-input
[label]="'Suche nach Namen'"
[debounceTime]="400"
[queryParamKey]="'search'" />
<div class="sorting">
<select (change)="handleSortFieldChange($event)" [value]="urlSortBy()">
<option value="relevance">Relevanz</option>
<option value="name">Name</option>
<option value="works_count">Anzahl Publikationen</option>
<option value="citations_count">Anzahl Zitationen</option>
</select>
<app-query-param-selector
[options]="sortingOptions"
[queryParamKey]="'sort_by'" />
<select
(change)="handleSortOrderChange($event)"
[value]="urlSortingOrder()">
<option value="desc">Absteigend</option>
<option value="asc">Aufsteigend</option>
</select>
<app-query-param-selector
[options]="sortingDirectionOptions"
[queryParamKey]="'sorting_order'" />
</div>
</div>
@@ -106,11 +91,7 @@
<mat-divider />
<mat-paginator
[length]="institutionPageValue.total"
[pageSize]="institutionPageValue.size"
[pageSizeOptions]="[10, 20, 50]"
[pageIndex]="institutionPageValue.page"
(page)="handlePageChange($event)">
</mat-paginator>
<app-query-param-paginator
[total]="institutionPageValue.total ?? 0"
[pageSizeOptions]="[10, 20, 50]" />
</div>
@@ -41,10 +41,6 @@
}
}
mat-paginator {
background-color: var(--sg-background);
}
.card {
padding: 0.5rem;
background-color: var(--sg-background);
@@ -1,26 +1,28 @@
import { Component, effect, input, signal } from '@angular/core';
import { Component, input } from '@angular/core';
import { Institution, InstitutionPage } from '../../api';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatInputModule } from '@angular/material/input';
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { RouterModule } from '@angular/router';
import { MatIconModule } from '@angular/material/icon';
import { DebounceDirective } from '../../directives/debounce.directive';
import { MatPaginator, PageEvent } from '@angular/material/paginator';
import { MatDividerModule } from '@angular/material/divider';
import { QueryParamPaginatorComponent } from '../../shared/ui/query-param-paginator/query-param-paginator.component';
import {
QueryParamSelectorComponent,
SelectorOption,
} from '../../shared/ui/query-param-selector/query-param-selector.component';
import { QueryParamInputComponent } from '../../shared/ui/query-param-input/query-param-input.component';
@Component({
selector: 'app-institutions',
imports: [
MatButtonModule,
MatCardModule,
MatInputModule,
MatIconModule,
DebounceDirective,
MatPaginator,
MatDividerModule,
RouterModule,
QueryParamPaginatorComponent,
QueryParamSelectorComponent,
QueryParamInputComponent,
],
templateUrl: './institutions.component.html',
styleUrl: './institutions.component.scss',
@@ -28,74 +30,21 @@ import { MatDividerModule } from '@angular/material/divider';
export class InstitutionsComponent {
institutionPage = input.required<InstitutionPage>();
urlSearchTerm = signal<string>('');
urlSortBy = signal<string>('relevance');
urlSortingOrder = signal<string>('desc');
constructor(
private readonly activatedRoute: ActivatedRoute,
private readonly router: Router,
) {
this.activatedRoute.queryParams
.pipe(takeUntilDestroyed())
.subscribe((params) => {
this.urlSearchTerm.set(params['search'] || '');
this.urlSortBy.set(params['sort_by'] || 'relevance');
this.urlSortingOrder.set(params['sorting_order'] || 'desc');
});
effect(() => {
const searchTerm = this.urlSearchTerm();
this.router.navigate([], {
queryParams: { search: searchTerm },
queryParamsHandling: 'merge',
});
});
}
handleSearchTermChange(newTerm: string): void {
this.router.navigate([], {
queryParams: { search: newTerm },
queryParamsHandling: 'merge',
});
}
clearSearchTerm(): void {
this.router.navigate([], {
queryParams: { search: null },
queryParamsHandling: 'merge',
});
}
handlePageChange(event: PageEvent): void {
this.router.navigate([], {
queryParams: { page: event.pageIndex, size: event.pageSize },
queryParamsHandling: 'merge',
});
}
sortingOptions: SelectorOption[] = [
{ value: 'relevance', display_name: 'Relevanz' },
{ value: 'name', display_name: 'Name' },
{ value: 'works_count', display_name: 'Anzahl Publikationen' },
{ value: 'citations_count', display_name: 'Anzahl Zitationen' },
];
sortingDirectionOptions: SelectorOption[] = [
{ value: 'asc', display_name: 'Aufsteigend' },
{ value: 'desc', display_name: 'Absteigend' },
];
extractInstitutionId(institution: Institution): string {
return institution.id?.split('/').pop() ?? '';
}
handleSortFieldChange(event: Event): void {
const selectElement = event.target as HTMLSelectElement;
const sortField = selectElement.value;
this.router.navigate([], {
queryParams: { sort_by: sortField },
queryParamsHandling: 'merge',
});
}
handleSortOrderChange(event: Event): void {
const selectElement = event.target as HTMLSelectElement;
const sortOrder = selectElement.value;
this.router.navigate([], {
queryParams: { sorting_order: sortOrder },
queryParamsHandling: 'merge',
});
}
getDisplayName(institution: Institution): string {
const primary = institution.display_name?.trim();
if (primary && primary.length > 0) return primary;
@@ -4,19 +4,11 @@
<mat-divider />
<div style="padding: 0 1rem">
<mat-form-field style="width: 100%">
<mat-label>Suche nach Namen</mat-label>
<input
matInput
type="search"
[debounceTime]="300"
[(debouncedValue)]="urlSearchTerm"
(debouncedValueChange)="handleSearchTermChange($event)" />
<mat-icon matPrefix>search</mat-icon>
<button matIconButton matSuffix (click)="clearSearchTerm()">
<mat-icon>clear</mat-icon>
</button>
</mat-form-field>
<app-query-param-input
label="Suche nach Namen"
[debounceTime]="400"
queryParamKey="search">
</app-query-param-input>
<div
style="
@@ -34,16 +26,13 @@
</mat-chip-listbox>
<div class="sorting">
<select (change)="handleSortFieldChange($event)" [value]="urlSortBy()">
<option value="title">Name</option>
</select>
<app-query-param-selector
[options]="sortingOptions"
queryParamKey="sort_by" />
<select
(change)="handleSortOrderChange($event)"
[value]="urlSortingOrder()">
<option value="desc">Absteigend</option>
<option value="asc">Aufsteigend</option>
</select>
<app-query-param-selector
[options]="sortingDirectionOptions"
queryParamKey="sorting_order" />
</div>
</div>
</div>
@@ -102,11 +91,7 @@
<mat-divider />
<mat-paginator
[length]="fundingProjectPageValue.total"
[pageSize]="fundingProjectPageValue.size"
[pageSizeOptions]="[10, 20, 50]"
[pageIndex]="fundingProjectPageValue.page"
(page)="handlePageChange($event)">
</mat-paginator>
<app-query-param-paginator
[total]="fundingProjectPageValue.total || 0"
[pageSizeOptions]="[10, 25, 50]" />
</div>
@@ -1,33 +1,34 @@
import { Component, effect, input, signal } from '@angular/core';
import { Component, input, signal } from '@angular/core';
import { FundingProject, FundingProjectPage, ProjectType } from '../../api';
import { MatDividerModule } from '@angular/material/divider';
import { MatFormFieldModule } from '@angular/material/form-field';
import { DebounceDirective } from '../../directives/debounce.directive';
import { MatIconModule } from '@angular/material/icon';
import { MatCardModule } from '@angular/material/card';
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { MatPaginator, PageEvent } from '@angular/material/paginator';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { MatInputModule } from '@angular/material/input';
import { MatButtonModule } from '@angular/material/button';
import { DatePipe, UpperCasePipe } from '@angular/common';
import { MatChipListboxChange, MatChipsModule } from '@angular/material/chips';
import { QueryParamInputComponent } from '../../shared/ui/query-param-input/query-param-input.component';
import { QueryParamPaginatorComponent } from '../../shared/ui/query-param-paginator/query-param-paginator.component';
import {
QueryParamSelectorComponent,
SelectorOption,
} from '../../shared/ui/query-param-selector/query-param-selector.component';
@Component({
selector: 'app-projects',
imports: [
MatDividerModule,
MatFormFieldModule,
DebounceDirective,
MatIconModule,
MatCardModule,
RouterModule,
MatPaginator,
MatInputModule,
MatButtonModule,
UpperCasePipe,
DatePipe,
MatChipsModule,
QueryParamInputComponent,
QueryParamPaginatorComponent,
QueryParamSelectorComponent,
],
templateUrl: './projects.component.html',
styleUrl: './projects.component.scss',
@@ -35,11 +36,14 @@ import { MatChipListboxChange, MatChipsModule } from '@angular/material/chips';
export class ProjectsComponent {
fundingProjectPage = input.required<FundingProjectPage>();
urlSearchTerm = signal<string>('');
urlSortBy = signal<string>('relevance');
urlSortingOrder = signal<string>('desc');
urlChips = signal<ProjectType[]>(['eu', 'bund', 'dfg']);
sortingOptions: SelectorOption[] = [{ value: 'title', display_name: 'Name' }];
sortingDirectionOptions: SelectorOption[] = [
{ value: 'asc', display_name: 'Aufsteigend' },
{ value: 'desc', display_name: 'Absteigend' },
];
constructor(
private readonly activatedRoute: ActivatedRoute,
private readonly router: Router,
@@ -47,60 +51,10 @@ export class ProjectsComponent {
this.activatedRoute.queryParams
.pipe(takeUntilDestroyed())
.subscribe((params) => {
this.urlSearchTerm.set(params['search'] || '');
this.urlSortBy.set(params['sort_by'] || 'relevance');
this.urlSortingOrder.set(params['sorting_order'] || 'desc');
this.urlChips.set(
(params['selected_project_types'] || 'eu,bund,dfg').split(','),
);
});
effect(() => {
const searchTerm = this.urlSearchTerm();
this.router.navigate([], {
queryParams: { search: searchTerm },
queryParamsHandling: 'merge',
});
});
}
handleSearchTermChange(newTerm: string): void {
this.router.navigate([], {
queryParams: { search: newTerm, page: 0, size: 10 },
queryParamsHandling: 'merge',
});
}
clearSearchTerm(): void {
this.router.navigate([], {
queryParams: { search: null },
queryParamsHandling: 'merge',
});
}
handlePageChange(event: PageEvent): void {
this.router.navigate([], {
queryParams: { page: event.pageIndex, size: event.pageSize },
queryParamsHandling: 'merge',
});
}
handleSortFieldChange(event: Event): void {
const selectElement = event.target as HTMLSelectElement;
const sortField = selectElement.value;
this.router.navigate([], {
queryParams: { sort_by: sortField },
queryParamsHandling: 'merge',
});
}
handleSortOrderChange(event: Event): void {
const selectElement = event.target as HTMLSelectElement;
const sortOrder = selectElement.value;
this.router.navigate([], {
queryParams: { sorting_order: sortOrder },
queryParamsHandling: 'merge',
});
}
handleChipBoxChange(change: MatChipListboxChange): void {
@@ -0,0 +1,13 @@
<mat-form-field style="width: 100%">
<mat-label>{{ this.label() }}</mat-label>
<input
matInput
type="search"
[debounceTime]="this.debounceTime()"
(debouncedValueChange)="this._handleValueChange($event)"
[ngModel]="this._urlValue()" />
<mat-icon matPrefix>search</mat-icon>
<button matIconButton matSuffix type="button" (click)="clearInput()">
<mat-icon>clear</mat-icon>
</button>
</mat-form-field>
@@ -0,0 +1,63 @@
import { Component, computed, inject, input, output } from '@angular/core';
import { MatFormFieldModule } from '@angular/material/form-field';
import { DebounceDirective } from '../../../directives/debounce.directive';
import { MatInputModule } from '@angular/material/input';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { ActivatedRoute, Router } from '@angular/router';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'app-query-param-input',
imports: [
FormsModule,
MatInputModule,
MatButtonModule,
MatIconModule,
MatFormFieldModule,
DebounceDirective,
],
templateUrl: './query-param-input.component.html',
styleUrl: './query-param-input.component.scss',
})
export class QueryParamInputComponent {
queryParamKey = input.required<string>();
queryParamPageKey = input<string>('page');
label = input<string>('Suchen');
debounceTime = input<number>(300);
handleValueChange = output<string>();
private readonly activatedRouter = inject(ActivatedRoute);
private readonly router = inject(Router);
private readonly queryParams = toSignal(
this.activatedRouter.queryParams.pipe(takeUntilDestroyed()),
);
_urlValue = computed<string>(() => {
const params = this.queryParams();
const key = this.queryParamKey();
return params && key ? params[key] || '' : '';
});
clearInput(): void {
this.router.navigate([], {
queryParams: { [this.queryParamKey()]: null },
queryParamsHandling: 'merge',
});
}
_handleValueChange(newValue: string): void {
this.handleValueChange?.emit(newValue);
this.router.navigate([], {
queryParams: {
[this.queryParamKey()]: newValue || null,
[this.queryParamPageKey()]: 0,
},
queryParamsHandling: 'merge',
});
}
}
@@ -0,0 +1,6 @@
<mat-paginator
[length]="total()"
[pageSize]="_urlSize()"
[pageIndex]="_urlPage()"
[pageSizeOptions]="pageSizeOptions()"
(page)="_handlePageChange($event)" />
@@ -0,0 +1,3 @@
mat-paginator {
background-color: var(--sg-background);
}
@@ -0,0 +1,52 @@
import { Component, computed, inject, input, output } from '@angular/core';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator';
import { ActivatedRoute, Router } from '@angular/router';
@Component({
selector: 'app-query-param-paginator',
imports: [MatPaginatorModule],
templateUrl: './query-param-paginator.component.html',
styleUrl: './query-param-paginator.component.scss',
})
export class QueryParamPaginatorComponent {
queryParamPageKey = input<string>('page');
queryParamSizeKey = input<string>('size');
pageSizeOptions = input<number[]>([10, 25, 50]);
total = input.required<number>();
handlePageChange = output<PageEvent>();
private readonly activatedRoute = inject(ActivatedRoute);
private readonly router = inject(Router);
private readonly queryParams = toSignal(
this.activatedRoute.queryParams.pipe(takeUntilDestroyed()),
);
_urlPage = computed<number>(() => {
const params = this.queryParams();
const key = this.queryParamPageKey();
return params && key ? +params[key] || 0 : 0;
});
_urlSize = computed<number>(() => {
const params = this.queryParams();
const key = this.queryParamSizeKey();
return params && key ? +params[key] || 10 : 10;
});
_handlePageChange(event: PageEvent): void {
this.handlePageChange?.emit(event);
this.router.navigate([], {
queryParams: {
[this.queryParamPageKey()]: event.pageIndex || null,
[this.queryParamSizeKey()]: event.pageSize || null,
},
queryParamsHandling: 'merge',
});
}
}
@@ -0,0 +1,5 @@
<select (change)="_handleSelectionChange($event)" [ngModel]="_urlValue()">
@for (option of options(); track $index) {
<option [value]="option.value">{{ option.display_name }}</option>
}
</select>
@@ -0,0 +1,10 @@
select {
padding: 0.75rem;
border: 1px solid var(--sg-border);
border-radius: var(--sg-radius-sm);
font-size: 1rem;
}
select:hover {
cursor: pointer;
}
@@ -0,0 +1,46 @@
import { Component, computed, inject, input, output } from '@angular/core';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { FormsModule } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
export type SelectorOption = {
value: string;
display_name: string;
};
@Component({
selector: 'app-query-param-selector',
imports: [FormsModule],
templateUrl: './query-param-selector.component.html',
styleUrl: './query-param-selector.component.scss',
})
export class QueryParamSelectorComponent {
options = input.required<SelectorOption[]>();
queryParamKey = input.required<string>();
handleSelectionChange = output<Event>();
private readonly activatedRoute = inject(ActivatedRoute);
private readonly router = inject(Router);
private readonly queryParams = toSignal(
this.activatedRoute.queryParams.pipe(takeUntilDestroyed()),
);
_urlValue = computed<string>(() => {
const params = this.queryParams();
const key = this.queryParamKey();
return params && key ? params[key] || '' : '';
});
_handleSelectionChange(event: Event): void {
const newValue = (event.target as HTMLSelectElement).value;
this.router.navigate([], {
queryParams: { [this.queryParamKey()]: newValue },
queryParamsHandling: 'merge',
});
this.handleSelectionChange.emit(event);
}
}