From 8c61b4d54f41bb916fdacfc708942fd3867a7b34 Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Sat, 20 Jun 2026 21:07:23 +0200 Subject: [PATCH 01/17] Changed index to vectorize each keyword & updated database topicvector --- service/sentence_transformer/index_topics.py | 142 +++++++++++++------ 1 file changed, 101 insertions(+), 41 deletions(-) diff --git a/service/sentence_transformer/index_topics.py b/service/sentence_transformer/index_topics.py index 7b506427..c1e4496d 100644 --- a/service/sentence_transformer/index_topics.py +++ b/service/sentence_transformer/index_topics.py @@ -1,17 +1,13 @@ #!/usr/bin/env python3 """ -One-time script to fetch all topics from 'openalex-topics', -vectorize display names and chunked descriptions using the sentence-transformers model, -and push them to the 'topicvectors' index with multi-vector hybrid mapping. +Script to fetch all topics from 'openalex-topics', +vectorize display names, full descriptions, and individual keywords using the sentence-transformers model, +and push them to the 'topicvectors' index with multi-vector mapping. """ -import os import sys import json -import base64 -import re from pathlib import Path import httpx -import numpy as np from dotenv import load_dotenv # Add service/src/main to python path to load settings @@ -24,8 +20,10 @@ sys.path.append(str(project_root / "service" / "src" / "main")) from inse.config import settings ELASTIC_URL = settings.elasticsearch_url +if ELASTIC_URL and not ELASTIC_URL.endswith("/"): + ELASTIC_URL += "/" API_KEY = settings.elasticsearch_api_key -MODEL_NAME = "paraphrase-multilingual-mpnet-base-v2" +MODEL_NAME = settings.sentence_transformers_model_name # Import sentence-transformers from sentence_transformers import SentenceTransformer @@ -35,14 +33,6 @@ headers = { "Content-Type": "application/json" } -def split_into_sentences(text): - if not text: - return [] - # Split on period, exclamation, or question mark followed by whitespace - sentences = re.split(r'(?<=[.!?])\s+', text.strip()) - # Filter out empty or extremely short sentences - return [s for s in sentences if len(s.strip()) > 3] - def fetch_all_topics(): print("Fetching topics from 'openalex-topics'...") topics = [] @@ -75,7 +65,67 @@ def fetch_all_topics(): print(f"Total topics fetched: {len(topics)}") return topics -def bulk_index_topics(topics, display_name_vectors, nested_description_vectors): +def update_mappings(): + print("Checking/updating mappings for 'topicvectors'...") + mapping_payload = { + "properties": { + "display_name_vector": { + "type": "dense_vector", + "dims": 768, + "index": True, + "similarity": "cosine", + "index_options": { + "type": "int8_hnsw", + "m": 16, + "ef_construction": 100 + } + }, + "description_vector": { + "type": "dense_vector", + "dims": 768, + "index": True, + "similarity": "cosine", + "index_options": { + "type": "int8_hnsw", + "m": 16, + "ef_construction": 100 + } + }, + "keyword_vectors": { + "type": "nested", + "properties": { + "vector": { + "type": "dense_vector", + "dims": 768, + "index": True, + "similarity": "cosine", + "index_options": { + "type": "int8_hnsw", + "m": 16, + "ef_construction": 100 + } + } + } + } + } + } + with httpx.Client(timeout=30.0) as client: + # Check if index exists + check_resp = client.get(f"{ELASTIC_URL}topicvectors", headers=headers) + if check_resp.status_code == 404: + print("Index 'topicvectors' does not exist. Creating it...") + create_payload = { + "mappings": mapping_payload + } + resp = client.put(f"{ELASTIC_URL}topicvectors", json=create_payload, headers=headers) + resp.raise_for_status() + else: + print("Index 'topicvectors' exists. Updating mappings...") + resp = client.put(f"{ELASTIC_URL}topicvectors/_mapping", json=mapping_payload, headers=headers) + resp.raise_for_status() + print("Mappings update process completed.") + +def bulk_index_topics(topics, display_name_vectors, description_vectors, keyword_vectors_list): print("Bulk indexing vectorized topics into 'topicvectors'...") batch_size = 500 @@ -83,22 +133,24 @@ def bulk_index_topics(topics, display_name_vectors, nested_description_vectors): for i in range(0, len(topics), batch_size): batch_topics = topics[i:i+batch_size] batch_name_vecs = display_name_vectors[i:i+batch_size] - batch_desc_vecs_list = nested_description_vectors[i:i+batch_size] + batch_desc_vecs = description_vectors[i:i+batch_size] + batch_kw_vecs_list = keyword_vectors_list[i:i+batch_size] bulk_lines = [] - for t, name_vec, desc_vecs in zip(batch_topics, batch_name_vecs, batch_desc_vecs_list): + for t, name_vec, desc_vec, kw_vecs in zip(batch_topics, batch_name_vecs, batch_desc_vecs, batch_kw_vecs_list): source = t["_source"] - # Remove deprecated single vector if present - if "vector" in source: - del source["vector"] + source.pop("siblings", None) # drop siblings field when making the copy # Assign name vector as a standard float list source["display_name_vector"] = name_vec.tolist() - # Assign nested description vectors as standard float lists - source["description_vectors"] = [ - {"vector": vec.tolist()} for vec in desc_vecs + # Assign description vector + source["description_vector"] = desc_vec.tolist() + + # Assign nested keyword vectors + source["keyword_vectors"] = [ + {"vector": vec.tolist()} for vec in kw_vecs ] # Meta line @@ -124,6 +176,8 @@ def bulk_index_topics(topics, display_name_vectors, nested_description_vectors): print(f"Indexed batch {i} to {i + len(batch_topics)}") def main(): + update_mappings() + topics = fetch_all_topics() if not topics: print("No topics found. Exiting.") @@ -133,44 +187,50 @@ def main(): model = SentenceTransformer(MODEL_NAME) # 1. Gather all texts to embed - display_names = [] - description_sentences_by_topic = [] + keywords_by_topic = [] all_texts_to_embed = [] for t in topics: source = t["_source"] + name = source.get("display_name") or "" - display_names.append(name) all_texts_to_embed.append(name) desc = source.get("description") or "" - sentences = split_into_sentences(desc) - description_sentences_by_topic.append(sentences) - all_texts_to_embed.extend(sentences) + all_texts_to_embed.append(desc) - print(f"Embedding {len(all_texts_to_embed)} texts (display names and description passages)...") + kws = source.get("keywords") or [] + if not isinstance(kws, list): + kws = [kws] if kws else [] + keywords_by_topic.append(kws) + all_texts_to_embed.extend(kws) + + print(f"Embedding {len(all_texts_to_embed)} texts (display names, descriptions, and keywords)...") all_vectors = model.encode(all_texts_to_embed, show_progress_bar=True, batch_size=32) # 2. Map embeddings back to topics display_name_vectors = [] - nested_description_vectors = [] + description_vectors = [] + keyword_vectors_list = [] vector_idx = 0 for idx, t in enumerate(topics): - # First vector is the display name + display_name_vectors.append(all_vectors[vector_idx]) vector_idx += 1 - # Next N vectors are the description chunks - sentences = description_sentences_by_topic[idx] - topic_desc_vecs = [] - for _ in range(len(sentences)): - topic_desc_vecs.append(all_vectors[vector_idx]) + description_vectors.append(all_vectors[vector_idx]) + vector_idx += 1 + + kws = keywords_by_topic[idx] + topic_kw_vecs = [] + for _ in range(len(kws)): + topic_kw_vecs.append(all_vectors[vector_idx]) vector_idx += 1 - nested_description_vectors.append(topic_desc_vecs) + keyword_vectors_list.append(topic_kw_vecs) # Bulk index - bulk_index_topics(topics, display_name_vectors, nested_description_vectors) + bulk_index_topics(topics, display_name_vectors, description_vectors, keyword_vectors_list) print("Done!") if __name__ == "__main__": From c30208e61e9152808ec72e28554a36fb30acb6ae Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Sat, 20 Jun 2026 21:08:27 +0200 Subject: [PATCH 02/17] added model to config and .env --- service/src/main/inse/.env | 4 ++++ service/src/main/inse/config.py | 3 +++ service/src/main/inse/util.py | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/service/src/main/inse/.env b/service/src/main/inse/.env index c7f128ed..55d8c5e7 100644 --- a/service/src/main/inse/.env +++ b/service/src/main/inse/.env @@ -17,3 +17,7 @@ ELASTICSEARCH_INSE_API_KEY=bG1NSWc1NEJPZ3FnTGZCZXRSSEg6VnJXRFd5SnpSTTNWc1VPT01FM LLM_API_URL=https://project.nes.uni-due.de/llm2/v1/ LLM_API_KEY=c2d5e7ccf7a4760dd3d19bed2caed9d85ff7437400e0ea82a6d6f912ebc2f212 LLM_MODEL=gemma4-e4b + +# Sentence Transformers Configuration +SENTENCE_TRANSFORMERS_MODEL_NAME=paraphrase-multilingual-mpnet-base-v2 + diff --git a/service/src/main/inse/config.py b/service/src/main/inse/config.py index 80335dab..a5ab3a47 100644 --- a/service/src/main/inse/config.py +++ b/service/src/main/inse/config.py @@ -49,6 +49,9 @@ class Settings(BaseSettings): llm_api_key: Optional[str] = None llm_model: Optional[str] = None + # Sentence Transformers config + sentence_transformers_model_name: str = "paraphrase-multilingual-mpnet-base-v2" + # elasticsearch config elasticsearch_url: Optional[str] = None elasticsearch_api_key: Optional[str] = None diff --git a/service/src/main/inse/util.py b/service/src/main/inse/util.py index 1acf6d2e..dc47d976 100644 --- a/service/src/main/inse/util.py +++ b/service/src/main/inse/util.py @@ -38,6 +38,7 @@ def get_persons_data(hit:dict): return author from sentence_transformers import SentenceTransformer +from .config import settings # Sentence Transformer Model _model: SentenceTransformer | None = None @@ -55,5 +56,6 @@ def get_model(): if os.environ.get("SENTENCE_TRANSFORMERS_HOME") == "/models": os.environ["HF_HUB_OFFLINE"] = "1" - _model = SentenceTransformer("paraphrase-multilingual-mpnet-base-v2") + model_name = settings.sentence_transformers_model_name + _model = SentenceTransformer(model_name) return _model \ No newline at end of file From 8f707df86fb2e436672421ea4b8af768ad94d300 Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Sun, 21 Jun 2026 09:33:57 +0200 Subject: [PATCH 03/17] implementing radio button option to select hybrid vs semantic --- service/src/main/inse/topics/service.py | 5 + webapp/src/app/api/api/topics.service.ts | 1147 +++++++++++------ .../topic-hierarchy.component.html | 33 + .../topic-hierarchy.component.ts | 53 +- 4 files changed, 847 insertions(+), 391 deletions(-) diff --git a/service/src/main/inse/topics/service.py b/service/src/main/inse/topics/service.py index bf6346fc..50c69fbc 100644 --- a/service/src/main/inse/topics/service.py +++ b/service/src/main/inse/topics/service.py @@ -129,9 +129,14 @@ async def vector_search_topics( int, Query(description="Maximum number of topics to return.", ge=1, le=100), ] = 25, + search_type: Annotated[ + str, + Query(alias="searchType", description="Search approach: 'hybrid' or 'semantic'."), + ] = "hybrid", ): return await logic.vector_search_topics( query=query, limit=limit, + search_type=search_type, ) diff --git a/webapp/src/app/api/api/topics.service.ts b/webapp/src/app/api/api/topics.service.ts index 4c2902a1..2b90f737 100644 --- a/webapp/src/app/api/api/topics.service.ts +++ b/webapp/src/app/api/api/topics.service.ts @@ -1,7 +1,7 @@ /** * Innovation Search Engine API * - * + * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech @@ -9,12 +9,18 @@ */ /* tslint:disable:no-unused-variable member-ordering */ -import { Inject, Injectable, Optional } from '@angular/core'; -import { HttpClient, HttpHeaders, HttpParams, - HttpResponse, HttpEvent, HttpParameterCodec, HttpContext - } from '@angular/common/http'; -import { CustomHttpParameterCodec } from '../encoder'; -import { Observable } from 'rxjs'; +import { Inject, Injectable, Optional } from '@angular/core'; +import { + HttpClient, + HttpHeaders, + HttpParams, + HttpResponse, + HttpEvent, + HttpParameterCodec, + HttpContext, +} from '@angular/common/http'; +import { CustomHttpParameterCodec } from '../encoder'; +import { Observable } from 'rxjs'; // @ts-ignore import { AutocompleteResponse } from '../model/autocompleteResponse'; @@ -24,410 +30,803 @@ import { HTTPValidationError } from '../model/hTTPValidationError'; import { TopicsListResponse } from '../model/topicsListResponse'; // @ts-ignore -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; -import { Configuration } from '../configuration'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; import { BaseService } from '../api.base.service'; - - @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class TopicsService extends BaseService { + constructor( + protected httpClient: HttpClient, + @Optional() @Inject(BASE_PATH) basePath: string | string[], + @Optional() configuration?: Configuration, + ) { + super(basePath, configuration); + } - constructor(protected httpClient: HttpClient, @Optional() @Inject(BASE_PATH) basePath: string|string[], @Optional() configuration?: Configuration) { - super(basePath, configuration); + /** + * Returns topic options for autocomplete inputs. + * @endpoint get /api/topics/autocomplete + * @param query Topic search text, for example \'machine learning\'. + * @param domainId Optional OpenAlex domain id filter. + * @param fieldId Optional OpenAlex field id filter. + * @param subfieldId Optional OpenAlex subfield id filter. + * @param limit Maximum number of autocomplete options. + * @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 autocompleteTopics( + query: string, + domainId?: string, + fieldId?: string, + subfieldId?: string, + limit?: number, + observe?: 'body', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable; + public autocompleteTopics( + query: string, + domainId?: string, + fieldId?: string, + subfieldId?: string, + limit?: number, + observe?: 'response', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public autocompleteTopics( + query: string, + domainId?: string, + fieldId?: string, + subfieldId?: string, + limit?: number, + observe?: 'events', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public autocompleteTopics( + query: string, + domainId?: string, + fieldId?: string, + subfieldId?: string, + limit?: number, + observe: any = 'body', + reportProgress: boolean = false, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable { + if (query === null || query === undefined) { + throw new Error( + 'Required parameter query was null or undefined when calling autocompleteTopics.', + ); } - /** - * Returns topic options for autocomplete inputs. - * @endpoint get /api/topics/autocomplete - * @param query Topic search text, for example \'machine learning\'. - * @param domainId Optional OpenAlex domain id filter. - * @param fieldId Optional OpenAlex field id filter. - * @param subfieldId Optional OpenAlex subfield id filter. - * @param limit Maximum number of autocomplete options. - * @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 autocompleteTopics(query: string, domainId?: string, fieldId?: string, subfieldId?: string, limit?: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public autocompleteTopics(query: string, domainId?: string, fieldId?: string, subfieldId?: string, limit?: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public autocompleteTopics(query: string, domainId?: string, fieldId?: string, subfieldId?: string, limit?: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public autocompleteTopics(query: string, domainId?: string, fieldId?: string, subfieldId?: string, limit?: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { - if (query === null || query === undefined) { - throw new Error('Required parameter query was null or undefined when calling autocompleteTopics.'); - } + let localVarQueryParameters = new HttpParams({ encoder: this.encoder }); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + query, + 'query', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + domainId, + 'domainId', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + fieldId, + 'fieldId', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + subfieldId, + 'subfieldId', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + limit, + 'limit', + ); - let localVarQueryParameters = new HttpParams({encoder: this.encoder}); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - query, 'query'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - domainId, 'domainId'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - fieldId, 'fieldId'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - subfieldId, 'subfieldId'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - limit, 'limit'); + let localVarHeaders = this.defaultHeaders; - let localVarHeaders = this.defaultHeaders; + const localVarHttpHeaderAcceptSelected: string | undefined = + options?.httpHeaderAccept ?? + this.configuration.selectHeaderAccept(['application/json']); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set( + 'Accept', + localVarHttpHeaderAcceptSelected, + ); + } - const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ - 'application/json' - ]); - if (localVarHttpHeaderAcceptSelected !== undefined) { - localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); - } + const localVarHttpContext: HttpContext = + options?.context ?? new HttpContext(); - const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); + const localVarTransferCache: boolean = options?.transferCache ?? true; - const localVarTransferCache: boolean = options?.transferCache ?? true; + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if ( + this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected) + ) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + let localVarPath = `/api/topics/autocomplete`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request( + 'get', + `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + params: localVarQueryParameters, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined + ? { transferCache: localVarTransferCache } + : {}), + reportProgress: reportProgress, + }, + ); + } - let responseType_: 'text' | 'json' | 'blob' = 'json'; - if (localVarHttpHeaderAcceptSelected) { - if (localVarHttpHeaderAcceptSelected.startsWith('text')) { - responseType_ = 'text'; - } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { - responseType_ = 'json'; - } else { - responseType_ = 'blob'; - } - } + /** + * Builds the topic hierarchy cache. + * @endpoint get /api/inse-service/topics/cache + * @param pageSize Page size for each search page. + * @param saveJson Persist cache JSON to data folder. + * @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 buildTopicCache( + pageSize?: number, + saveJson?: boolean, + observe?: 'body', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable; + public buildTopicCache( + pageSize?: number, + saveJson?: boolean, + observe?: 'response', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public buildTopicCache( + pageSize?: number, + saveJson?: boolean, + observe?: 'events', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public buildTopicCache( + pageSize?: number, + saveJson?: boolean, + 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, + pageSize, + 'page_size', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + saveJson, + 'save_json', + ); - let localVarPath = `/api/topics/autocomplete`; - const { basePath, withCredentials } = this.configuration; - return this.httpClient.request('get', `${basePath}${localVarPath}`, - { - context: localVarHttpContext, - params: localVarQueryParameters, - responseType: responseType_, - ...(withCredentials ? { withCredentials } : {}), - headers: localVarHeaders, - observe: observe, - ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), - reportProgress: reportProgress - } + let localVarHeaders = this.defaultHeaders; + + const localVarHttpHeaderAcceptSelected: string | undefined = + options?.httpHeaderAccept ?? + this.configuration.selectHeaderAccept(['application/json']); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set( + 'Accept', + localVarHttpHeaderAcceptSelected, + ); + } + + const localVarHttpContext: HttpContext = + options?.context ?? new HttpContext(); + + const localVarTransferCache: boolean = options?.transferCache ?? true; + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if ( + this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected) + ) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/api/inse-service/topics/cache`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request( + 'get', + `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + params: localVarQueryParameters, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined + ? { transferCache: localVarTransferCache } + : {}), + reportProgress: reportProgress, + }, + ); + } + + /** + * Counts topic hierarchy occurrences from cache. + * @endpoint get /api/inse-service/topics/count + * @param topic Topic names (repeat parameter). + * @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 countTopicHierarchy( + topic: Array, + observe?: 'body', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable; + public countTopicHierarchy( + topic: Array, + observe?: 'response', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public countTopicHierarchy( + topic: Array, + observe?: 'events', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public countTopicHierarchy( + topic: Array, + observe: any = 'body', + reportProgress: boolean = false, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable { + if (topic === null || topic === undefined) { + throw new Error( + 'Required parameter topic was null or undefined when calling countTopicHierarchy.', + ); + } + + let localVarQueryParameters = new HttpParams({ encoder: this.encoder }); + if (topic) { + topic.forEach((element) => { + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + element, + 'topic', ); + }); } - /** - * Builds the topic hierarchy cache. - * @endpoint get /api/inse-service/topics/cache - * @param pageSize Page size for each search page. - * @param saveJson Persist cache JSON to data folder. - * @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 buildTopicCache(pageSize?: number, saveJson?: boolean, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public buildTopicCache(pageSize?: number, saveJson?: boolean, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public buildTopicCache(pageSize?: number, saveJson?: boolean, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public buildTopicCache(pageSize?: number, saveJson?: boolean, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + let localVarHeaders = this.defaultHeaders; - let localVarQueryParameters = new HttpParams({encoder: this.encoder}); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - pageSize, 'page_size'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - saveJson, 'save_json'); - - let localVarHeaders = this.defaultHeaders; - - const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ - 'application/json' - ]); - if (localVarHttpHeaderAcceptSelected !== undefined) { - localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); - } - - const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); - - const localVarTransferCache: boolean = options?.transferCache ?? true; - - - let responseType_: 'text' | 'json' | 'blob' = 'json'; - if (localVarHttpHeaderAcceptSelected) { - if (localVarHttpHeaderAcceptSelected.startsWith('text')) { - responseType_ = 'text'; - } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { - responseType_ = 'json'; - } else { - responseType_ = 'blob'; - } - } - - let localVarPath = `/api/inse-service/topics/cache`; - const { basePath, withCredentials } = this.configuration; - return this.httpClient.request('get', `${basePath}${localVarPath}`, - { - context: localVarHttpContext, - params: localVarQueryParameters, - responseType: responseType_, - ...(withCredentials ? { withCredentials } : {}), - headers: localVarHeaders, - observe: observe, - ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), - reportProgress: reportProgress - } - ); + const localVarHttpHeaderAcceptSelected: string | undefined = + options?.httpHeaderAccept ?? + this.configuration.selectHeaderAccept(['application/json']); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set( + 'Accept', + localVarHttpHeaderAcceptSelected, + ); } - /** - * Counts topic hierarchy occurrences from cache. - * @endpoint get /api/inse-service/topics/count - * @param topic Topic names (repeat parameter). - * @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 countTopicHierarchy(topic: Array, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public countTopicHierarchy(topic: Array, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public countTopicHierarchy(topic: Array, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public countTopicHierarchy(topic: Array, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { - if (topic === null || topic === undefined) { - throw new Error('Required parameter topic was null or undefined when calling countTopicHierarchy.'); - } + const localVarHttpContext: HttpContext = + options?.context ?? new HttpContext(); - let localVarQueryParameters = new HttpParams({encoder: this.encoder}); - if (topic) { - topic.forEach((element) => { - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - element, 'topic'); - }) - } + const localVarTransferCache: boolean = options?.transferCache ?? true; - let localVarHeaders = this.defaultHeaders; - - const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ - 'application/json' - ]); - if (localVarHttpHeaderAcceptSelected !== undefined) { - localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); - } - - const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); - - const localVarTransferCache: boolean = options?.transferCache ?? true; - - - let responseType_: 'text' | 'json' | 'blob' = 'json'; - if (localVarHttpHeaderAcceptSelected) { - if (localVarHttpHeaderAcceptSelected.startsWith('text')) { - responseType_ = 'text'; - } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { - responseType_ = 'json'; - } else { - responseType_ = 'blob'; - } - } - - let localVarPath = `/api/inse-service/topics/count`; - const { basePath, withCredentials } = this.configuration; - return this.httpClient.request('get', `${basePath}${localVarPath}`, - { - context: localVarHttpContext, - params: localVarQueryParameters, - responseType: responseType_, - ...(withCredentials ? { withCredentials } : {}), - headers: localVarHeaders, - observe: observe, - ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), - reportProgress: reportProgress - } - ); + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if ( + this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected) + ) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } } - /** - * Returns the nested topic hierarchy (Domains -> Fields -> Subfields -> Topics). - * @endpoint get /api/inse-service/topics/hierarchy - * @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 getTopicHierarchy(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public getTopicHierarchy(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public getTopicHierarchy(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public getTopicHierarchy(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + let localVarPath = `/api/inse-service/topics/count`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request( + 'get', + `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + params: localVarQueryParameters, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined + ? { transferCache: localVarTransferCache } + : {}), + reportProgress: reportProgress, + }, + ); + } - let localVarHeaders = this.defaultHeaders; + /** + * Returns the nested topic hierarchy (Domains -> Fields -> Subfields -> Topics). + * @endpoint get /api/inse-service/topics/hierarchy + * @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 getTopicHierarchy( + observe?: 'body', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable; + public getTopicHierarchy( + observe?: 'response', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public getTopicHierarchy( + observe?: 'events', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public getTopicHierarchy( + observe: any = 'body', + reportProgress: boolean = false, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable { + let localVarHeaders = this.defaultHeaders; - const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ - 'application/json' - ]); - if (localVarHttpHeaderAcceptSelected !== undefined) { - localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); - } - - const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); - - const localVarTransferCache: boolean = options?.transferCache ?? true; - - - let responseType_: 'text' | 'json' | 'blob' = 'json'; - if (localVarHttpHeaderAcceptSelected) { - if (localVarHttpHeaderAcceptSelected.startsWith('text')) { - responseType_ = 'text'; - } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { - responseType_ = 'json'; - } else { - responseType_ = 'blob'; - } - } - - let localVarPath = `/api/inse-service/topics/hierarchy`; - const { basePath, withCredentials } = this.configuration; - return this.httpClient.request('get', `${basePath}${localVarPath}`, - { - context: localVarHttpContext, - responseType: responseType_, - ...(withCredentials ? { withCredentials } : {}), - headers: localVarHeaders, - observe: observe, - ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), - reportProgress: reportProgress - } - ); + const localVarHttpHeaderAcceptSelected: string | undefined = + options?.httpHeaderAccept ?? + this.configuration.selectHeaderAccept(['application/json']); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set( + 'Accept', + localVarHttpHeaderAcceptSelected, + ); } - /** - * Returns a list of OpenAlex topics. - * @endpoint get /api/topics - * @param search Full-text search, for example \'machine learning\'. - * @param filter OpenAlex filter, for example \'domain.id:1,works_count:>1000\'. - * @param sort Sort field, for example \'works_count:desc\'. - * @param groupBy OpenAlex group_by field, for example \'domain.id\'. - * @param perPage Results per page. - * @param page Page number. Use cursor for deep pagination. - * @param cursor Cursor pagination token. Use \'*\' to start. - * @param sample Random sample size. Cannot be combined with sort or page. - * @param select Comma-separated fields to return. - * @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 listTopics(search?: string, filter?: string, sort?: string, groupBy?: string, perPage?: number, page?: number, cursor?: string, sample?: number, select?: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public listTopics(search?: string, filter?: string, sort?: string, groupBy?: string, perPage?: number, page?: number, cursor?: string, sample?: number, select?: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public listTopics(search?: string, filter?: string, sort?: string, groupBy?: string, perPage?: number, page?: number, cursor?: string, sample?: number, select?: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public listTopics(search?: string, filter?: string, sort?: string, groupBy?: string, perPage?: number, page?: number, cursor?: string, sample?: number, select?: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + const localVarHttpContext: HttpContext = + options?.context ?? new HttpContext(); - let localVarQueryParameters = new HttpParams({encoder: this.encoder}); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - search, 'search'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - filter, 'filter'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - sort, 'sort'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - groupBy, 'group_by'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - perPage, 'per_page'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - page, 'page'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - cursor, 'cursor'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - sample, 'sample'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - select, 'select'); + const localVarTransferCache: boolean = options?.transferCache ?? true; - let localVarHeaders = this.defaultHeaders; - - const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ - 'application/json' - ]); - if (localVarHttpHeaderAcceptSelected !== undefined) { - localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); - } - - const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); - - const localVarTransferCache: boolean = options?.transferCache ?? true; - - - let responseType_: 'text' | 'json' | 'blob' = 'json'; - if (localVarHttpHeaderAcceptSelected) { - if (localVarHttpHeaderAcceptSelected.startsWith('text')) { - responseType_ = 'text'; - } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { - responseType_ = 'json'; - } else { - responseType_ = 'blob'; - } - } - - let localVarPath = `/api/topics`; - const { basePath, withCredentials } = this.configuration; - return this.httpClient.request('get', `${basePath}${localVarPath}`, - { - context: localVarHttpContext, - params: localVarQueryParameters, - responseType: responseType_, - ...(withCredentials ? { withCredentials } : {}), - headers: localVarHeaders, - observe: observe, - ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), - reportProgress: reportProgress - } - ); + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if ( + this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected) + ) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } } - /** - * Semantic / vector search for topics using a keyword/sentence. - * @endpoint get /api/topics/vector-search - * @param query Word or sentence to search by similarity. - * @param limit Maximum number of topics to return. - * @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 vectorSearchTopics(query: string, limit?: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public vectorSearchTopics(query: string, limit?: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public vectorSearchTopics(query: string, limit?: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public vectorSearchTopics(query: string, limit?: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { - if (query === null || query === undefined) { - throw new Error('Required parameter query was null or undefined when calling vectorSearchTopics.'); - } + let localVarPath = `/api/inse-service/topics/hierarchy`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request( + 'get', + `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined + ? { transferCache: localVarTransferCache } + : {}), + reportProgress: reportProgress, + }, + ); + } - let localVarQueryParameters = new HttpParams({encoder: this.encoder}); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - query, 'query'); - localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, - limit, 'limit'); + /** + * Returns a list of OpenAlex topics. + * @endpoint get /api/topics + * @param search Full-text search, for example \'machine learning\'. + * @param filter OpenAlex filter, for example \'domain.id:1,works_count:>1000\'. + * @param sort Sort field, for example \'works_count:desc\'. + * @param groupBy OpenAlex group_by field, for example \'domain.id\'. + * @param perPage Results per page. + * @param page Page number. Use cursor for deep pagination. + * @param cursor Cursor pagination token. Use \'*\' to start. + * @param sample Random sample size. Cannot be combined with sort or page. + * @param select Comma-separated fields to return. + * @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 listTopics( + search?: string, + filter?: string, + sort?: string, + groupBy?: string, + perPage?: number, + page?: number, + cursor?: string, + sample?: number, + select?: string, + observe?: 'body', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable; + public listTopics( + search?: string, + filter?: string, + sort?: string, + groupBy?: string, + perPage?: number, + page?: number, + cursor?: string, + sample?: number, + select?: string, + observe?: 'response', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public listTopics( + search?: string, + filter?: string, + sort?: string, + groupBy?: string, + perPage?: number, + page?: number, + cursor?: string, + sample?: number, + select?: string, + observe?: 'events', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public listTopics( + search?: string, + filter?: string, + sort?: string, + groupBy?: string, + perPage?: number, + page?: number, + cursor?: string, + sample?: number, + select?: string, + 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, + search, + 'search', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + filter, + 'filter', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + sort, + 'sort', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + groupBy, + 'group_by', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + perPage, + 'per_page', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + page, + 'page', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + cursor, + 'cursor', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + sample, + 'sample', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + select, + 'select', + ); - let localVarHeaders = this.defaultHeaders; + let localVarHeaders = this.defaultHeaders; - const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ - 'application/json' - ]); - if (localVarHttpHeaderAcceptSelected !== undefined) { - localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); - } - - const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); - - const localVarTransferCache: boolean = options?.transferCache ?? true; - - - let responseType_: 'text' | 'json' | 'blob' = 'json'; - if (localVarHttpHeaderAcceptSelected) { - if (localVarHttpHeaderAcceptSelected.startsWith('text')) { - responseType_ = 'text'; - } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { - responseType_ = 'json'; - } else { - responseType_ = 'blob'; - } - } - - let localVarPath = `/api/topics/vector-search`; - const { basePath, withCredentials } = this.configuration; - return this.httpClient.request('get', `${basePath}${localVarPath}`, - { - context: localVarHttpContext, - params: localVarQueryParameters, - responseType: responseType_, - ...(withCredentials ? { withCredentials } : {}), - headers: localVarHeaders, - observe: observe, - ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), - reportProgress: reportProgress - } - ); + const localVarHttpHeaderAcceptSelected: string | undefined = + options?.httpHeaderAccept ?? + this.configuration.selectHeaderAccept(['application/json']); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set( + 'Accept', + localVarHttpHeaderAcceptSelected, + ); } + const localVarHttpContext: HttpContext = + options?.context ?? new HttpContext(); + + const localVarTransferCache: boolean = options?.transferCache ?? true; + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if ( + this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected) + ) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/api/topics`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request( + 'get', + `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + params: localVarQueryParameters, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined + ? { transferCache: localVarTransferCache } + : {}), + reportProgress: reportProgress, + }, + ); + } + + /** + * Semantic / vector search for topics using a keyword/sentence. + * @endpoint get /api/topics/vector-search + * @param query Word or sentence to search by similarity. + * @param limit Maximum number of topics to return. + * @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 vectorSearchTopics( + query: string, + limit?: number, + searchType?: string, + observe?: 'body', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable; + public vectorSearchTopics( + query: string, + limit?: number, + searchType?: string, + observe?: 'response', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public vectorSearchTopics( + query: string, + limit?: number, + searchType?: string, + observe?: 'events', + reportProgress?: boolean, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable>; + public vectorSearchTopics( + query: string, + limit?: number, + searchType?: string, + observe: any = 'body', + reportProgress: boolean = false, + options?: { + httpHeaderAccept?: 'application/json'; + context?: HttpContext; + transferCache?: boolean; + }, + ): Observable { + if (query === null || query === undefined) { + throw new Error( + 'Required parameter query was null or undefined when calling vectorSearchTopics.', + ); + } + + let localVarQueryParameters = new HttpParams({ encoder: this.encoder }); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + query, + 'query', + ); + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + limit, + 'limit', + ); + if (searchType !== undefined && searchType !== null) { + localVarQueryParameters = this.addToHttpParams( + localVarQueryParameters, + searchType, + 'searchType', + ); + } + + let localVarHeaders = this.defaultHeaders; + + const localVarHttpHeaderAcceptSelected: string | undefined = + options?.httpHeaderAccept ?? + this.configuration.selectHeaderAccept(['application/json']); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set( + 'Accept', + localVarHttpHeaderAcceptSelected, + ); + } + + const localVarHttpContext: HttpContext = + options?.context ?? new HttpContext(); + + const localVarTransferCache: boolean = options?.transferCache ?? true; + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if ( + this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected) + ) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/api/topics/vector-search`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request( + 'get', + `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + params: localVarQueryParameters, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined + ? { transferCache: localVarTransferCache } + : {}), + reportProgress: reportProgress, + }, + ); + } } diff --git a/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.html b/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.html index 0ba8f150..08e8e6fd 100644 --- a/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.html +++ b/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.html @@ -1,4 +1,37 @@
+ @if (searchQuery) { +
+ Modus: + + + Hybrid + + + Semantisch + + +
+ } @if (loading()) {
diff --git a/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.ts b/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.ts index eb9468e3..20060484 100644 --- a/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.ts +++ b/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.ts @@ -10,6 +10,7 @@ import { CommonModule } from '@angular/common'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatIconModule } from '@angular/material/icon'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; +import { MatRadioModule } from '@angular/material/radio'; import { TopicsService } from '../../api/api/topics.service'; import { Subject, of } from 'rxjs'; import { @@ -53,6 +54,7 @@ interface FlatTopic { MatCheckboxModule, MatIconModule, MatProgressSpinnerModule, + MatRadioModule, ], templateUrl: './topic-hierarchy.component.html', styleUrl: './topic-hierarchy.component.scss', @@ -80,38 +82,47 @@ export class TopicHierarchyComponent implements OnInit { flatTopics: FlatTopic[] = []; filteredFlatTopics: FlatTopic[] = []; loading = signal(true); + searchType = signal<'hybrid' | 'semantic'>('hybrid'); // Set of names of expanded nodes (lazy content rendering) expandedDomains = new Set(); expandedFields = new Set(); expandedSubfields = new Set(); - private readonly searchSubject = new Subject(); + private readonly searchSubject = new Subject<{ + query: string; + searchType: 'hybrid' | 'semantic'; + }>(); constructor(private topicsService: TopicsService) { this.searchSubject .pipe( debounceTime(300), - distinctUntilChanged(), - switchMap((query) => { + distinctUntilChanged( + (prev, curr) => + prev.query === curr.query && prev.searchType === curr.searchType, + ), + switchMap(({ query, searchType }) => { if (!query) { this.filteredFlatTopics = []; return of({ results: [] }); } this.loading.set(true); - return this.topicsService.vectorSearchTopics(query, 50).pipe( - catchError((err) => { - console.error('Error in semantic topic search:', err); - // Fallback to local filtering - const q = query.toLowerCase(); - this.filteredFlatTopics = this.flatTopics.filter( - (t) => - t.name.toLowerCase().includes(q) || - t.path.toLowerCase().includes(q), - ); - return of({ results: [] }); - }), - ); + return this.topicsService + .vectorSearchTopics(query, 50, searchType) + .pipe( + catchError((err) => { + console.error('Error in semantic topic search:', err); + // Fallback to local filtering + const q = query.toLowerCase(); + this.filteredFlatTopics = this.flatTopics.filter( + (t) => + t.name.toLowerCase().includes(q) || + t.path.toLowerCase().includes(q), + ); + return of({ results: [] }); + }), + ); }), ) .subscribe((response) => { @@ -175,7 +186,15 @@ export class TopicHierarchyComponent implements OnInit { this.filteredFlatTopics = []; return; } - this.searchSubject.next(this.searchQuery); + this.searchSubject.next({ + query: this.searchQuery, + searchType: this.searchType(), + }); + } + + onSearchTypeChange(type: 'hybrid' | 'semantic'): void { + this.searchType.set(type); + this.filterFlatTopics(); } toggleTopic(name: string): void { From 5b37115e46e4e1eb744f1daedb3f145928d1c704 Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Sun, 21 Jun 2026 12:36:36 +0200 Subject: [PATCH 04/17] changed logic of semantic and hybrid query. Tested different boostings --- service/src/main/inse/topics/logic.py | 106 ++++++++++++++++---------- 1 file changed, 66 insertions(+), 40 deletions(-) diff --git a/service/src/main/inse/topics/logic.py b/service/src/main/inse/topics/logic.py index adc56a7a..94646f16 100644 --- a/service/src/main/inse/topics/logic.py +++ b/service/src/main/inse/topics/logic.py @@ -256,10 +256,19 @@ def _datetime_str_or_none(value: Any) -> str | None: return f"{text}T00:00:00Z" return text +# Configuration for vector search similarity thresholds and boosts +SIMILARITY_THRESHOLD = 0.62 +BOOST_LEXICAL = 1.0 +# higher values for semantic weights, because cosine similarity is between 0 and 1 +BOOST_DISPLAY_NAME_VECTOR = 30.0 +BOOST_DESCRIPTION_VECTOR = 15.0 +BOOST_KEYWORD_VECTORS = 25.0 + async def vector_search_topics( *, query: str, limit: int = 25, + search_type: str = "hybrid", ) -> TopicsListResponse: """ Perform a semantic similarity search on the topicvectors index. @@ -287,53 +296,70 @@ async def vector_search_topics( ) # 2. Query Elasticsearch using standard Bool Should hybrid search + should_clauses = [] + + # Lexical multi_match search (only in hybrid mode) + if search_type == "hybrid": + should_clauses.append({ + "multi_match": { + "query": query, + "fields": [ + "display_name^3", + "keywords^2", + "description^1" + ], + "boost": BOOST_LEXICAL + } + }) + + # Semantic KNN clauses + should_clauses.extend([ + { + "knn": { + "field": "display_name_vector", + "query_vector": query_vector, + "k": limit, + "num_candidates": 100, + "similarity": SIMILARITY_THRESHOLD, + "boost": BOOST_DISPLAY_NAME_VECTOR + } + }, + { + "knn": { + "field": "description_vector", + "query_vector": query_vector, + "k": limit, + "num_candidates": 100, + "similarity": SIMILARITY_THRESHOLD, + "boost": BOOST_DESCRIPTION_VECTOR + } + }, + { + "nested": { + "path": "keyword_vectors", + "query": { + "knn": { + "field": "keyword_vectors.vector", + "query_vector": query_vector, + "k": limit, + "num_candidates": 100, + "similarity": SIMILARITY_THRESHOLD + } + }, + "score_mode": "max", + "boost": BOOST_KEYWORD_VECTORS + } + } + ]) body = { "query": { "bool": { - "should": [ - { - "multi_match": { - "query": query, - "fields": [ - "display_name^3", - "keywords^2", - "description^1" - ], - "boost": 1.0 - } - }, - { - "knn": { - "field": "display_name_vector", - "query_vector": query_vector, - "k": limit, - "num_candidates": 100, - "similarity": 0.62, - "boost": 2.0 - } - }, - { - "nested": { - "path": "description_vectors", - "query": { - "knn": { - "field": "description_vectors.vector", - "query_vector": query_vector, - "k": limit, - "num_candidates": 100, - "similarity": 0.62 - } - }, - "score_mode": "max", - "boost": 1.0 - } - } - ] + "should": should_clauses } }, "_source": { - "excludes": ["display_name_vector", "description_vectors", "description", "siblings"] # remove unrequired fields (description, sibling currently not needed) + "excludes": ["display_name_vector", "description_vector", "keyword_vectors", "description"] # remove unrequired fields }, "size": limit } From d89d1ded98092eaac08bdbb72464abee8f4e0256 Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Sun, 21 Jun 2026 18:51:30 +0200 Subject: [PATCH 05/17] changed k and num_candidates. Low number leads to ignored Keyword vectors --- service/src/main/inse/topics/logic.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/service/src/main/inse/topics/logic.py b/service/src/main/inse/topics/logic.py index 94646f16..9c460f3f 100644 --- a/service/src/main/inse/topics/logic.py +++ b/service/src/main/inse/topics/logic.py @@ -318,20 +318,20 @@ async def vector_search_topics( "knn": { "field": "display_name_vector", "query_vector": query_vector, - "k": limit, - "num_candidates": 100, "similarity": SIMILARITY_THRESHOLD, - "boost": BOOST_DISPLAY_NAME_VECTOR + "boost": BOOST_DISPLAY_NAME_VECTOR, + "k": 500, + "num_candidates": 500 } }, { "knn": { "field": "description_vector", "query_vector": query_vector, - "k": limit, - "num_candidates": 100, "similarity": SIMILARITY_THRESHOLD, - "boost": BOOST_DESCRIPTION_VECTOR + "boost": BOOST_DESCRIPTION_VECTOR, + "k": 500, + "num_candidates": 500 } }, { @@ -341,9 +341,9 @@ async def vector_search_topics( "knn": { "field": "keyword_vectors.vector", "query_vector": query_vector, - "k": limit, - "num_candidates": 100, - "similarity": SIMILARITY_THRESHOLD + "similarity": SIMILARITY_THRESHOLD, + "k": 500, + "num_candidates": 500 } }, "score_mode": "max", From 479c144c8b15600c96e8297b10728d3900d6e890 Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Sun, 21 Jun 2026 19:01:41 +0200 Subject: [PATCH 06/17] removed logging --- service/src/data/search_scores.json | 114 ------------------- service/src/main/inse/topics/logic.py | 7 -- service/src/main/inse/topics/score_logger.py | 36 ------ 3 files changed, 157 deletions(-) delete mode 100644 service/src/data/search_scores.json delete mode 100644 service/src/main/inse/topics/score_logger.py diff --git a/service/src/data/search_scores.json b/service/src/data/search_scores.json deleted file mode 100644 index 303a117b..00000000 --- a/service/src/data/search_scores.json +++ /dev/null @@ -1,114 +0,0 @@ -{ - "query": "localization", - "max_score": 23.237041, - "results": [ - { - "topic_name": "Indoor and Outdoor Localization Technologies", - "score": 23.237041 - }, - { - "topic_name": "Robotics and Sensor-Based Localization", - "score": 21.511477 - }, - { - "topic_name": "Spectral Theory in Mathematical Physics", - "score": 14.039959 - }, - { - "topic_name": "Socioeconomic Development in MENA", - "score": 11.518878 - }, - { - "topic_name": "Electrical Fault Detection and Protection", - "score": 10.770052 - }, - { - "topic_name": "Machine Learning in Bioinformatics", - "score": 10.322677 - }, - { - "topic_name": "Software System Performance and Reliability", - "score": 10.112644 - }, - { - "topic_name": "Quantum many-body systems", - "score": 10.112644 - }, - { - "topic_name": "Random lasers and scattering media", - "score": 10.112644 - }, - { - "topic_name": "Insect Pheromone Research and Control", - "score": 9.910988 - }, - { - "topic_name": "Tactile and Sensory Interactions", - "score": 9.910988 - }, - { - "topic_name": "Handwritten Text Recognition Techniques", - "score": 9.910988 - }, - { - "topic_name": "Integrated Circuits and Semiconductor Failure Analysis", - "score": 9.910988 - }, - { - "topic_name": "Medical Imaging and Analysis", - "score": 9.7172165 - }, - { - "topic_name": "Microwave Imaging and Scattering Analysis", - "score": 9.7172165 - }, - { - "topic_name": "Neurology and Historical Studies", - "score": 9.7172165 - }, - { - "topic_name": "High-Velocity Impact and Material Behavior", - "score": 9.7172165 - }, - { - "topic_name": "Software Engineering Research", - "score": 9.530875 - }, - { - "topic_name": "Software Testing and Debugging Techniques", - "score": 9.530875 - }, - { - "topic_name": "Digital Media Forensic Detection", - "score": 9.530875 - }, - { - "topic_name": "Infrared Thermography in Medicine", - "score": 9.351548 - }, - { - "topic_name": "Explainable Artificial Intelligence (XAI)", - "score": 9.351548 - }, - { - "topic_name": "Underwater Vehicles and Communication Systems", - "score": 9.351548 - }, - { - "topic_name": "Diffusion and Search Dynamics", - "score": 8.8518915 - }, - { - "topic_name": "Direction-of-Arrival Estimation Techniques", - "score": 5.968384 - }, - { - "topic_name": "Retinal Imaging and Analysis", - "score": 5.6107 - }, - { - "topic_name": "Radar Systems and Signal Processing", - "score": 4.721418 - } - ] -} diff --git a/service/src/main/inse/topics/logic.py b/service/src/main/inse/topics/logic.py index 9c460f3f..ee0972fc 100644 --- a/service/src/main/inse/topics/logic.py +++ b/service/src/main/inse/topics/logic.py @@ -380,13 +380,6 @@ async def vector_search_topics( # 3. Format result hits = raw_results.get("hits", {}).get("hits", []) - # Log scores to JSON for threshold analysis TODO: Remove after finetune - try: - from .score_logger import log_scores_to_json - log_scores_to_json(hits, query) - except Exception as exc: - logger.warning(f"Could not log search scores: {exc}") - total = len(hits) results = [hit.get("_source", {}) for hit in hits] diff --git a/service/src/main/inse/topics/score_logger.py b/service/src/main/inse/topics/score_logger.py deleted file mode 100644 index 0493d9ad..00000000 --- a/service/src/main/inse/topics/score_logger.py +++ /dev/null @@ -1,36 +0,0 @@ -import json -from pathlib import Path -from typing import Any, Dict, List - -def log_scores_to_json(hits: List[Dict[str, Any]], query: str) -> None: - """ - Utility function to log the names and scores of all vector search hits to a JSON file. - This helps in debugging and manually tweaking the similarity score thresholds. - """ - scores_data = [] - for hit in hits: - source = hit.get("_source", {}) - topic_name = source.get("display_name") or source.get("name") or "Unknown" - score = hit.get("_score", 0.0) - scores_data.append({ - "topic_name": topic_name, - "score": score - }) - - - data_dir = Path("/data") - - output_file = data_dir / "search_scores.json" - - log_payload = { - "query": query, - "max_score": hits[0].get("_score", 0.0) if hits else 0.0, - "results": scores_data - } - - try: - with open(output_file, "w", encoding="utf-8") as f: - json.dump(log_payload, f, indent=2, ensure_ascii=False) - print(f"DEBUG: Saved search scores for query '{query}' to {output_file}") - except Exception as exc: - print(f"DEBUG: Failed to save search scores: {exc}") From 3249a8569b50ceed5d83cf935f6ff7e0b1f5499e Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Sun, 21 Jun 2026 19:43:45 +0200 Subject: [PATCH 07/17] changed topic-hierarchy to use Angular Material tooltip. Fixed Tooltip to also show, when only navigating with tab (no only mouse over) --- .../topic-hierarchy.component.html | 22 +++++--- .../topic-hierarchy.component.scss | 55 +++++++++++++++---- .../topic-hierarchy.component.ts | 2 + 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.html b/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.html index 08e8e6fd..f6bfaca2 100644 --- a/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.html +++ b/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.html @@ -48,8 +48,13 @@ @for (topic of filteredFlatTopics; track topic.id) {
+ (change)="toggleTopic(topic.name)" + [matTooltip]="topic.name" + matTooltipPosition="above" + (focusin)="tooltip.show()" + (focusout)="tooltip.hide()"> {{ topic.name }} {{ @@ -136,13 +141,16 @@
- {{ topic.name }} + (change)="toggleTopic(topic.name)" + [matTooltip]="topic.name" + matTooltipPosition="above" + (focusin)="tooltip.show()" + (focusout)="tooltip.hide()"> + {{ + topic.name + }}
} diff --git a/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.scss b/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.scss index 9be6e396..abfa99bc 100644 --- a/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.scss +++ b/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.scss @@ -2,11 +2,13 @@ width: 100%; max-height: 400px; overflow-y: auto; + overflow-x: hidden; border: 1px solid var(--sg-border); border-radius: var(--sg-radius-sm); background: var(--sg-background); - padding: 4px; + padding: 4px 8px 4px 4px; margin-top: 4px; + box-sizing: border-box; } .loading-state { @@ -55,6 +57,11 @@ font-size: 12px; color: var(--sg-text); font-weight: 500; + display: block; + width: 100%; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; } .topic-path { @@ -92,7 +99,7 @@ width: 100%; background: transparent; border: none; - padding: 4px 6px; + padding: 4px; text-align: left; cursor: pointer; border-radius: 4px; @@ -122,6 +129,7 @@ white-space: nowrap; text-overflow: ellipsis; overflow: hidden; + min-width: 0; } } @@ -158,37 +166,62 @@ } .domain-children { - padding-left: 12px; + padding-left: 10px; border-left: 1px solid var(--sg-border-soft); margin-left: 12px; margin-bottom: 4px; } .field-children { - padding-left: 14px; + padding-left: 10px; border-left: 1px solid var(--sg-border-soft); - margin-left: 14px; + margin-left: 12px; } .subfield-children { - padding-left: 14px; + padding-left: 10px; border-left: 1px dashed var(--sg-border-soft); - margin-left: 14px; + margin-left: 12px; margin-bottom: 2px; } .tree-leaf { padding: 2px 4px; + width: 100%; + box-sizing: border-box; } .topic-node { + width: 100%; + box-sizing: border-box; + .topic-label { font-size: 11px; color: var(--sg-text); - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; display: block; - max-width: 190px; + width: 100%; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } +} + +mat-checkbox { + display: block !important; + width: 100% !important; + + ::ng-deep { + .mdc-form-field { + width: 100% !important; + display: flex !important; + align-items: center; + } + + .mdc-label { + flex: 1 !important; + min-width: 0 !important; + overflow: hidden; + padding-left: 8px !important; + } } } diff --git a/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.ts b/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.ts index 20060484..22c8d34e 100644 --- a/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.ts +++ b/webapp/src/app/modules/topic-hierarchy/topic-hierarchy.component.ts @@ -11,6 +11,7 @@ import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatIconModule } from '@angular/material/icon'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { MatRadioModule } from '@angular/material/radio'; +import { MatTooltipModule } from '@angular/material/tooltip'; import { TopicsService } from '../../api/api/topics.service'; import { Subject, of } from 'rxjs'; import { @@ -55,6 +56,7 @@ interface FlatTopic { MatIconModule, MatProgressSpinnerModule, MatRadioModule, + MatTooltipModule, ], templateUrl: './topic-hierarchy.component.html', styleUrl: './topic-hierarchy.component.scss', From 84747b9efb004ae0b8df48449ade3906c8297cb2 Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Sun, 21 Jun 2026 20:39:04 +0200 Subject: [PATCH 08/17] refactor frontend (changed old decorator Input, Output to modern signals. Added URL parameters to safe topic filer) --- .../person-card/person-card.component.html | 66 ++++----- .../person-card/person-card.component.scss | 22 ++- .../person-card/person-card.component.ts | 125 ++++++++++-------- .../person-list/person-list.component.html | 40 ++++-- .../person-list/person-list.component.scss | 27 +++- .../person-list/person-list.component.ts | 72 +++++++--- .../topic-hierarchy.component.html | 10 +- .../topic-hierarchy.component.ts | 65 +++------ 8 files changed, 256 insertions(+), 171 deletions(-) diff --git a/webapp/src/app/modules/person-card/person-card.component.html b/webapp/src/app/modules/person-card/person-card.component.html index df244ae9..725b6617 100644 --- a/webapp/src/app/modules/person-card/person-card.component.html +++ b/webapp/src/app/modules/person-card/person-card.component.html @@ -1,8 +1,8 @@
- + -
- {{ getInitials(person.display_name) }} +
+ {{ initials() }}
@@ -11,41 +11,43 @@ (click)=" toggleBookmark(); $event.stopPropagation(); $event.preventDefault() " - [class.bookmarked]="isBookmarked" + [class.bookmarked]="isBookmarked()" aria-label="Bookmark person"> {{ - isBookmarked ? 'bookmark' : 'bookmark_border' + isBookmarked() ? 'bookmark' : 'bookmark_border' }}

- {{ person.display_name ?? '' }} + [title]="person().display_name ?? ''"> + {{ person().display_name ?? '' }}

-

- {{ getDistinguishingId(person) }} +

+ {{ distinguishingId() }}

-

- {{ getStatsString() }} +

+ {{ statsString() }}

-

- {{ getHIndexString() }} +

+ {{ hIndexString() }}

- @if (institution(person); as inst) { + @if (institution(); as inst) {
- + "> {{ inst.display_name ?? '' }} - @if (inst.country_code && !loading) { + @if (inst.country_code && !loading()) { {{ inst.country_code.toUpperCase() }} } - +
}
- @for (topic of topics(person); track topic.id) { - {{ topic.display_name }} + "> + {{ topic.display_name }} + }
@@ -56,14 +60,18 @@
Sortierung:
- - @@ -132,19 +140,23 @@ @if (topicSearchControl.value) { }
@@ -158,6 +170,7 @@ type="text" [formControl]="institutionControl" [matAutocomplete]="auto" + aria-label="Institution suchen" placeholder="Institution suchen..." (keyup.enter)="applySidebarFilters()" /> + (click)="clearInstitutionFilter()" + aria-label="Institution zurücksetzen"> close } @@ -198,7 +212,8 @@ "> + (change)="applySidebarFilters()" + aria-label="Zusammenarbeit nach Jahr filtern"> Zusammenarbeit nach Jahr filtern + style="display: flex; gap: 16px" + aria-label="Modus für Jahresfilter"> Genau in @if (filterYearControl.hasError('min')) { Jahr muss ≥ 1900 sein @@ -255,7 +272,10 @@ @@ -106,11 +91,7 @@ - - +
diff --git a/webapp/src/app/modules/institutions/institutions.component.scss b/webapp/src/app/modules/institutions/institutions.component.scss index 95ff7534..47a6389e 100644 --- a/webapp/src/app/modules/institutions/institutions.component.scss +++ b/webapp/src/app/modules/institutions/institutions.component.scss @@ -41,10 +41,6 @@ } } -mat-paginator { - background-color: var(--sg-background); -} - .card { padding: 0.5rem; background-color: var(--sg-background); diff --git a/webapp/src/app/modules/institutions/institutions.component.ts b/webapp/src/app/modules/institutions/institutions.component.ts index e2449349..18eea25f 100644 --- a/webapp/src/app/modules/institutions/institutions.component.ts +++ b/webapp/src/app/modules/institutions/institutions.component.ts @@ -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(); - urlSearchTerm = signal(''); - urlSortBy = signal('relevance'); - urlSortingOrder = signal('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; diff --git a/webapp/src/app/shared/ui/query-param-input/query-param-input.component.html b/webapp/src/app/shared/ui/query-param-input/query-param-input.component.html new file mode 100644 index 00000000..8ce973c0 --- /dev/null +++ b/webapp/src/app/shared/ui/query-param-input/query-param-input.component.html @@ -0,0 +1,13 @@ + + {{ this.label() }} + + search + + diff --git a/webapp/src/app/shared/ui/query-param-input/query-param-input.component.scss b/webapp/src/app/shared/ui/query-param-input/query-param-input.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/webapp/src/app/shared/ui/query-param-input/query-param-input.component.ts b/webapp/src/app/shared/ui/query-param-input/query-param-input.component.ts new file mode 100644 index 00000000..85d396f1 --- /dev/null +++ b/webapp/src/app/shared/ui/query-param-input/query-param-input.component.ts @@ -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(); + queryParamPageKey = input('page'); + label = input('Suchen'); + debounceTime = input(300); + handleValueChange = output(); + + private readonly activatedRouter = inject(ActivatedRoute); + private readonly router = inject(Router); + + private readonly queryParams = toSignal( + this.activatedRouter.queryParams.pipe(takeUntilDestroyed()), + ); + + _urlValue = computed(() => { + 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', + }); + } +} diff --git a/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.html b/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.html new file mode 100644 index 00000000..ea5f4947 --- /dev/null +++ b/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.html @@ -0,0 +1,6 @@ + diff --git a/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.scss b/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.scss new file mode 100644 index 00000000..bb582c94 --- /dev/null +++ b/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.scss @@ -0,0 +1,3 @@ +mat-paginator { + background-color: var(--sg-background); +} diff --git a/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.ts b/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.ts new file mode 100644 index 00000000..63a0bd8f --- /dev/null +++ b/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.ts @@ -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('page'); + queryParamSizeKey = input('size'); + pageSizeOptions = input([10, 25, 50]); + + total = input.required(); + + handlePageChange = output(); + + private readonly activatedRoute = inject(ActivatedRoute); + private readonly router = inject(Router); + + private readonly queryParams = toSignal( + this.activatedRoute.queryParams.pipe(takeUntilDestroyed()), + ); + + _urlPage = computed(() => { + const params = this.queryParams(); + const key = this.queryParamPageKey(); + + return params && key ? +params[key] || 0 : 0; + }); + + _urlSize = computed(() => { + 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', + }); + } +} diff --git a/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.html b/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.html new file mode 100644 index 00000000..0f6dcd9b --- /dev/null +++ b/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.html @@ -0,0 +1,5 @@ + diff --git a/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.scss b/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.scss new file mode 100644 index 00000000..d1990896 --- /dev/null +++ b/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.scss @@ -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; +} diff --git a/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.ts b/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.ts new file mode 100644 index 00000000..caa3f7bf --- /dev/null +++ b/webapp/src/app/shared/ui/query-param-selector/query-param-selector.component.ts @@ -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(); + queryParamKey = input.required(); + handleSelectionChange = output(); + + private readonly activatedRoute = inject(ActivatedRoute); + private readonly router = inject(Router); + + private readonly queryParams = toSignal( + this.activatedRoute.queryParams.pipe(takeUntilDestroyed()), + ); + + _urlValue = computed(() => { + 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); + } +} From 70ed62a220377b7a5db4309b5da2155fbd38c176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20Paul=20Ton=C4=8Dik?= Date: Sun, 21 Jun 2026 22:48:04 +0200 Subject: [PATCH 11/17] Updated projects to use query params components --- .../modules/projects/projects.component.html | 43 ++++------ .../modules/projects/projects.component.ts | 78 ++++--------------- 2 files changed, 30 insertions(+), 91 deletions(-) diff --git a/webapp/src/app/modules/projects/projects.component.html b/webapp/src/app/modules/projects/projects.component.html index 8d2a3884..0ae1e25c 100644 --- a/webapp/src/app/modules/projects/projects.component.html +++ b/webapp/src/app/modules/projects/projects.component.html @@ -4,19 +4,11 @@
- - Suche nach Namen - - search - - + +
- + - +
@@ -102,11 +91,7 @@ - - +
diff --git a/webapp/src/app/modules/projects/projects.component.ts b/webapp/src/app/modules/projects/projects.component.ts index 4fc6f46d..effdc3f4 100644 --- a/webapp/src/app/modules/projects/projects.component.ts +++ b/webapp/src/app/modules/projects/projects.component.ts @@ -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(); - urlSearchTerm = signal(''); - urlSortBy = signal('relevance'); - urlSortingOrder = signal('desc'); urlChips = signal(['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 { From 0c2a45ba66a0b5fc939ff0ffe2f72ed689853d72 Mon Sep 17 00:00:00 2001 From: spsaefan <117728614+spsaefan@users.noreply.github.com> Date: Sun, 21 Jun 2026 23:36:15 +0200 Subject: [PATCH 12/17] Clean API key config --- service/src/main/inse/config.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/service/src/main/inse/config.py b/service/src/main/inse/config.py index 80335dab..ab247ce5 100644 --- a/service/src/main/inse/config.py +++ b/service/src/main/inse/config.py @@ -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 @@ -49,8 +45,8 @@ class Settings(BaseSettings): llm_api_key: Optional[str] = None llm_model: Optional[str] = None - # 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 @@ -63,9 +59,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" From 514e572eb92be56879a89f2761e5688a9d9a4e42 Mon Sep 17 00:00:00 2001 From: spsaefan <117728614+spsaefan@users.noreply.github.com> Date: Sun, 21 Jun 2026 23:36:30 +0200 Subject: [PATCH 13/17] Use shared Elasticsearch config --- service/src/main/inse/company_connections/search_client.py | 5 ++--- service/src/main/inse/funders/elastic_search_client.py | 4 ++-- service/src/main/inse/works/search_client.py | 5 +++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/service/src/main/inse/company_connections/search_client.py b/service/src/main/inse/company_connections/search_client.py index 80934c96..4516f4f7 100644 --- a/service/src/main/inse/company_connections/search_client.py +++ b/service/src/main/inse/company_connections/search_client.py @@ -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 diff --git a/service/src/main/inse/funders/elastic_search_client.py b/service/src/main/inse/funders/elastic_search_client.py index 126fa319..a411cb0a 100644 --- a/service/src/main/inse/funders/elastic_search_client.py +++ b/service/src/main/inse/funders/elastic_search_client.py @@ -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 diff --git a/service/src/main/inse/works/search_client.py b/service/src/main/inse/works/search_client.py index 36b1b3bb..fe60c665 100644 --- a/service/src/main/inse/works/search_client.py +++ b/service/src/main/inse/works/search_client.py @@ -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, From fbf5dbefe3437af1731b62bf8aaf79b3c83fe9d9 Mon Sep 17 00:00:00 2001 From: Kazgatari <56477241+Kazgatari@users.noreply.github.com> Date: Mon, 22 Jun 2026 09:34:05 +0200 Subject: [PATCH 14/17] test jenkins --- .../person-list/person-list.component.scss | 159 +++++++++--------- 1 file changed, 80 insertions(+), 79 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 7d98bf38..bd630cd9 100644 --- a/webapp/src/app/modules/person-list/person-list.component.scss +++ b/webapp/src/app/modules/person-list/person-list.component.scss @@ -13,18 +13,64 @@ margin: 0 auto; } -.results-column { +// Shared flex layouts +.page-header, +.sidebar-header, +.toolbar { + display: flex; + align-items: center; +} + +.page-header, +.toolbar { + justify-content: space-between; +} + +.sidebar-header, +.toolbar { + border-bottom: 1px solid var(--sg-border); + padding-bottom: 12px; +} + +.selection-summary, +.active-filters-row, +.chips-container, +.sort-selector, +.topic-search-wrapper { + display: flex; + align-items: center; +} + +.filter-chip { + display: inline-flex; + align-items: center; +} + +// Shared column & sidebar column layouts +.results-column, +.empty-state, +.filters-sidebar, +.filter-section { display: flex; - min-width: 0; flex-direction: column; +} + +// Shared containers styling +.selection-summary, +.active-filters-row, +.filters-sidebar { + background: var(--sg-surface); + border: 1px solid var(--sg-border); + border-radius: var(--sg-radius-sm); +} + +// Individual styles +.results-column { gap: 20px; min-width: 0; } .page-header { - display: flex; - justify-content: space-between; - align-items: center; gap: 16px; h1 { @@ -42,13 +88,8 @@ } .selection-summary { - display: flex; - align-items: center; gap: 12px; padding: 8px 12px; - background: var(--sg-surface); - border: 1px solid var(--sg-border); - border-radius: var(--sg-radius-sm); strong { display: block; @@ -65,13 +106,8 @@ } .active-filters-row { - display: flex; - align-items: center; gap: 10px; - background: var(--sg-surface); padding: 8px 16px; - border: 1px solid var(--sg-border); - border-radius: var(--sg-radius-sm); flex-wrap: wrap; font-size: 13px; } @@ -82,15 +118,11 @@ } .chips-container { - display: flex; - align-items: center; gap: 6px; flex-wrap: wrap; } .filter-chip { - display: inline-flex; - align-items: center; gap: 4px; padding: 2px 8px; background: var(--sg-surface-soft); @@ -99,53 +131,53 @@ font-size: 11px; font-weight: 600; color: var(--sg-text); - - button { - border: none; - background: transparent; - cursor: pointer; - padding: 0; - display: flex; - color: var(--sg-text-soft); - - &:hover { - color: var(--sg-text); - } - - mat-icon { - font-size: 12px; - width: 12px; - height: 12px; - } - } } +// Shared button resets +.filter-chip button, +.clear-topic-search, .clear-all-btn { border: none; background: transparent; cursor: pointer; +} + +.filter-chip button, +.clear-topic-search { + padding: 0; + display: flex; + color: var(--sg-text-soft); + + &:hover { + color: var(--sg-text); + } +} + +.filter-chip button mat-icon { + font-size: 12px; + width: 12px; + height: 12px; +} + +.clear-topic-search mat-icon { + font-size: 14px; + width: 14px; + height: 14px; +} + +.clear-all-btn { font-size: 11px; font-weight: 600; color: var(--sg-warning); text-decoration: underline; } -.toolbar { - display: flex; - justify-content: space-between; - align-items: center; - border-bottom: 1px solid var(--sg-border); - padding-bottom: 12px; -} - .result-count { font-size: 13px; color: var(--sg-text-muted); } .sort-selector { - display: flex; - align-items: center; gap: 8px; font-size: 13px; color: var(--sg-text-muted); @@ -177,8 +209,6 @@ } .empty-state { - display: flex; - flex-direction: column; align-items: center; padding: 48px 16px; background: var(--sg-surface); @@ -212,24 +242,14 @@ mat-paginator { } .filters-sidebar { - background: var(--sg-surface); - border: 1px solid var(--sg-border); - border-radius: var(--sg-radius-sm); padding: 16px; box-shadow: var(--sg-shadow-sm); - display: flex; - flex-direction: column; - gap: 16px; position: sticky; top: 16px; } .sidebar-header { - display: flex; - align-items: center; gap: 8px; - padding-bottom: 12px; - border-bottom: 1px solid var(--sg-border); mat-icon { color: var(--sg-primary); @@ -246,8 +266,6 @@ mat-paginator { } .filter-section { - display: flex; - flex-direction: column; gap: 8px; } @@ -260,9 +278,6 @@ mat-paginator { } .topic-search-wrapper { - position: relative; - display: flex; - align-items: center; background: var(--sg-surface-soft); border: 1px solid var(--sg-border); border-radius: var(--sg-radius-sm); @@ -292,20 +307,6 @@ mat-paginator { flex-grow: 1; margin-left: 6px; } - - .clear-topic-search { - border: none; - background: transparent; - cursor: pointer; - display: flex; - color: var(--sg-text-soft); - - mat-icon { - font-size: 14px; - width: 14px; - height: 14px; - } - } } .sidebar-footer { From d1310f24ff51e8bd6858cfdf72161bb3c6bb1fb8 Mon Sep 17 00:00:00 2001 From: arzani Date: Mon, 22 Jun 2026 10:14:00 +0200 Subject: [PATCH 15/17] permission fixes for the py_cache --- service/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/build.gradle b/service/build.gradle index 40510af3..066a7af3 100644 --- a/service/build.gradle +++ b/service/build.gradle @@ -49,7 +49,7 @@ task exportOpenApiSpec(type: Exec) { commandLine 'docker', 'run', '--rm', '--platform', "${targetPlatform}", '-w', '/home', - '-v', "${projectDir}/src/main:/home", + //'-v', "${projectDir}/src/main:/home", the source code is already baked into the image at build time '-v', "${openApiDir}:/mnt/openapi", '-e', "DOCKER_DEFAULT_PLATFORM='${targetPlatform}'", '--name', "${imageName}-service-openapi", From c222d422a9c7713e48a9a032ff946f5917105605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20Paul=20Ton=C4=8Dik?= Date: Mon, 22 Jun 2026 15:30:32 +0200 Subject: [PATCH 16/17] Updated more components to use query param components --- .../institution-projects.component.html | 25 +++----- .../institution-projects.component.ts | 59 ++---------------- .../institutions/institutions.component.scss | 14 +---- .../person-projects.component.html | 22 ++----- .../person-projects.component.ts | 60 ++----------------- .../modules/projects/projects.component.scss | 14 +---- .../query-param-paginator.component.ts | 4 +- 7 files changed, 23 insertions(+), 175 deletions(-) diff --git a/webapp/src/app/modules/institution-projects/institution-projects.component.html b/webapp/src/app/modules/institution-projects/institution-projects.component.html index ce7c7648..8d0b6d47 100644 --- a/webapp/src/app/modules/institution-projects/institution-projects.component.html +++ b/webapp/src/app/modules/institution-projects/institution-projects.component.html @@ -4,19 +4,10 @@
- - Suche nach Themen - - search - - + + @@ -37,11 +28,9 @@ (sortChange)="handleSortChange($event)" /> - +
diff --git a/webapp/src/app/modules/institution-projects/institution-projects.component.ts b/webapp/src/app/modules/institution-projects/institution-projects.component.ts index cb1fc8bb..53d38360 100644 --- a/webapp/src/app/modules/institution-projects/institution-projects.component.ts +++ b/webapp/src/app/modules/institution-projects/institution-projects.component.ts @@ -19,7 +19,6 @@ import { import { MatCardModule } from '@angular/material/card'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatTabChangeEvent, MatTabsModule } from '@angular/material/tabs'; -import { MatPaginatorModule, PageEvent } from '@angular/material/paginator'; import { FormsModule } from '@angular/forms'; import { MatInputModule } from '@angular/material/input'; import { @@ -29,11 +28,12 @@ import { import { CurrencyPipe, DatePipe } from '@angular/common'; import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'; import { Sort, SortDirection } from '@angular/material/sort'; -import { DebounceDirective } from '../../directives/debounce.directive'; import { MatIconModule } from '@angular/material/icon'; import { MatButtonModule } from '@angular/material/button'; import { InstitutionProjectsFundingGraphComponent } from '../institution-projects-funding-graph/institution-projects-funding-graph.component'; import { PersonNetworkInfoCardComponent } from '../person-network-info-card/person-network-info-card.component'; +import { QueryParamPaginatorComponent } from '../../shared/ui/query-param-paginator/query-param-paginator.component'; +import { QueryParamInputComponent } from '../../shared/ui/query-param-input/query-param-input.component'; type BundProjectRow = { id: string; @@ -58,18 +58,18 @@ type EuProjectRow = { MatCardModule, MatFormFieldModule, MatTabsModule, - MatPaginatorModule, FormsModule, MatInputModule, DataTableComponent, DatePipe, CurrencyPipe, - DebounceDirective, MatIconModule, MatButtonModule, InstitutionProjectsFundingGraphComponent, PersonNetworkInfoCardComponent, RouterModule, + QueryParamPaginatorComponent, + QueryParamInputComponent, ], templateUrl: './institution-projects.component.html', styleUrl: './institution-projects.component.scss', @@ -119,7 +119,6 @@ export class InstitutionProjectsComponent implements OnInit { urlSortKey = signal(''); urlSortDirection = signal(''); - urlSearchTerm = signal(''); constructor( private readonly activatedRoute: ActivatedRoute, @@ -132,7 +131,6 @@ export class InstitutionProjectsComponent implements OnInit { this.urlSortDirection.set( (params['sort_direction'] as SortDirection) ?? '', ); - this.urlSearchTerm.set(params['search'] ?? ''); }); effect(() => { @@ -151,20 +149,6 @@ export class InstitutionProjectsComponent implements OnInit { : []; } }); - - effect(() => { - const searchTerm = this.urlSearchTerm(); - if (searchTerm) { - this.router.navigate([], { - queryParams: { search: searchTerm, page: 0, size: 10 }, - queryParamsHandling: 'merge', - }); - } - }); - - effect(() => { - console.log('Funding over time data:', this.bundProjectsFunding()); - }); } readonly queryParams = toSignal(this.activatedRoute.queryParamMap, { @@ -175,12 +159,6 @@ export class InstitutionProjectsComponent implements OnInit { return this.queryParams()?.get('project_tab') ?? 'eu'; }); - readonly page = computed(() => { - const pageParam = this.queryParams()?.get('page'); - const page = pageParam ? Number.parseInt(pageParam, 10) : 0; - return Number.isNaN(page) ? 0 : page; - }); - readonly selectedPage = computed(() => { if (this.displayedProjects() === 'eu') { return this.cordisEuProjectPage(); @@ -193,14 +171,6 @@ export class InstitutionProjectsComponent implements OnInit { return this.selectedPage()?.total ?? 0; }); - readonly pageSize = computed(() => { - return this.selectedPage()?.size ?? 10; - }); - - readonly pageIndex = computed(() => { - return this.selectedPage()?.page ?? 0; - }); - ngOnInit(): void { this.euProjectColumns = [ { @@ -320,31 +290,10 @@ export class InstitutionProjectsComponent implements OnInit { }); } - handlePageChange(event: PageEvent): void { - this.router.navigate([], { - queryParams: { page: event.pageIndex, size: event.pageSize }, - queryParamsHandling: 'merge', - }); - } - handleSortChange(event: Sort): void { this.router.navigate([], { queryParams: { sort_by: event.active, sort_direction: event.direction }, 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, page: 0, size: 10 }, - queryParamsHandling: 'merge', - }); - } } diff --git a/webapp/src/app/modules/institutions/institutions.component.scss b/webapp/src/app/modules/institutions/institutions.component.scss index 47a6389e..7303fdd7 100644 --- a/webapp/src/app/modules/institutions/institutions.component.scss +++ b/webapp/src/app/modules/institutions/institutions.component.scss @@ -25,22 +25,10 @@ .cards { display: grid; gap: 1.5rem; - grid-template-columns: repeat(4, 1fr); + grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); padding: 0 1rem; } -@media (max-width: 900px) { - .cards { - grid-template-columns: repeat(2, 1fr); - } -} - -@media (max-width: 600px) { - .cards { - grid-template-columns: 1fr; - } -} - .card { padding: 0.5rem; background-color: var(--sg-background); diff --git a/webapp/src/app/modules/person-projects/person-projects.component.html b/webapp/src/app/modules/person-projects/person-projects.component.html index e33bdee6..7faf7c59 100644 --- a/webapp/src/app/modules/person-projects/person-projects.component.html +++ b/webapp/src/app/modules/person-projects/person-projects.component.html @@ -5,19 +5,7 @@
- - Suche nach Titel - - search - - + - +
diff --git a/webapp/src/app/modules/person-projects/person-projects.component.ts b/webapp/src/app/modules/person-projects/person-projects.component.ts index 9e208870..baf3be30 100644 --- a/webapp/src/app/modules/person-projects/person-projects.component.ts +++ b/webapp/src/app/modules/person-projects/person-projects.component.ts @@ -24,12 +24,11 @@ import { MatCardModule } from '@angular/material/card'; import { MatTabsModule } from '@angular/material/tabs'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatInputModule } from '@angular/material/input'; -import { DebounceDirective } from '../../directives/debounce.directive'; import { ActivatedRoute, Router, RouterModule } from '@angular/router'; -import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { MatPaginatorModule, PageEvent } from '@angular/material/paginator'; import { Sort, SortDirection } from '@angular/material/sort'; import { CurrencyPipe, DatePipe } from '@angular/common'; +import { QueryParamPaginatorComponent } from '../../shared/ui/query-param-paginator/query-param-paginator.component'; +import { QueryParamInputComponent } from '../../shared/ui/query-param-input/query-param-input.component'; @Component({ selector: 'app-person-projects', @@ -41,11 +40,11 @@ import { CurrencyPipe, DatePipe } from '@angular/common'; MatTabsModule, MatFormFieldModule, MatInputModule, - DebounceDirective, - MatPaginatorModule, RouterModule, DatePipe, CurrencyPipe, + QueryParamPaginatorComponent, + QueryParamInputComponent, ], templateUrl: './person-projects.component.html', styleUrl: './person-projects.component.scss', @@ -82,7 +81,6 @@ export class PersonProjectsComponent implements OnInit { 'euProjectsActionsTmp', ); - urlSearchTerm = signal(''); urlSortKey = signal(''); urlSortDirection = signal(''); @@ -90,47 +88,18 @@ export class PersonProjectsComponent implements OnInit { return this.dfgProjectPage()?.total ?? 0; }); - readonly pageSize = computed(() => { - return this.dfgProjectPage()?.size ?? 10; - }); - - readonly pageIndex = computed(() => { - return this.dfgProjectPage()?.page ?? 0; - }); - constructor( private readonly router: Router, private readonly activatedRoute: ActivatedRoute, ) { - this.activatedRoute.queryParamMap - .pipe(takeUntilDestroyed()) - .subscribe((params) => { - this.urlSearchTerm.set(params.get('search') || ''); - }); - effect(() => { this.dfgProjectData = this.dfgProjectPage().elements || []; }); effect(() => { - console.log( - 'Updating personCordisEuProjectData with', - this.personCordisEuProjectPage(), - ); - this.personCordisEuProjectData = this.personCordisEuProjectPage().elements || []; }); - - effect(() => { - const searchTerm = this.urlSearchTerm(); - if (searchTerm) { - this.router.navigate([], { - queryParams: { search: searchTerm, page: 0, size: this.pageSize() }, - queryParamsHandling: 'merge', - }); - } - }); } ngOnInit(): void { @@ -197,27 +166,6 @@ export class PersonProjectsComponent implements OnInit { ]; } - 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', - }); - } - handleSortChange(event: Sort): void { this.router.navigate([], { queryParams: { sort_by: event.active, sort_direction: event.direction }, diff --git a/webapp/src/app/modules/projects/projects.component.scss b/webapp/src/app/modules/projects/projects.component.scss index e3d0edc0..32a0f31e 100644 --- a/webapp/src/app/modules/projects/projects.component.scss +++ b/webapp/src/app/modules/projects/projects.component.scss @@ -25,22 +25,10 @@ .cards { display: grid; gap: 1.5rem; - grid-template-columns: repeat(4, 1fr); + grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); padding: 0 1rem; } -@media (max-width: 900px) { - .cards { - grid-template-columns: repeat(2, 1fr); - } -} - -@media (max-width: 600px) { - .cards { - grid-template-columns: 1fr; - } -} - mat-paginator { background-color: var(--sg-background); } diff --git a/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.ts b/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.ts index 63a0bd8f..aa7466bd 100644 --- a/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.ts +++ b/webapp/src/app/shared/ui/query-param-paginator/query-param-paginator.component.ts @@ -43,8 +43,8 @@ export class QueryParamPaginatorComponent { this.handlePageChange?.emit(event); this.router.navigate([], { queryParams: { - [this.queryParamPageKey()]: event.pageIndex || null, - [this.queryParamSizeKey()]: event.pageSize || null, + [this.queryParamPageKey()]: event.pageIndex || 0, + [this.queryParamSizeKey()]: event.pageSize || 10, }, queryParamsHandling: 'merge', }); From 043db9b7cc4d83fdf304bd3d3838f9ddc91544ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20Paul=20Ton=C4=8Dik?= Date: Mon, 22 Jun 2026 15:48:57 +0200 Subject: [PATCH 17/17] Added sort query param manipulation by generic data table --- .../institution-projects.component.html | 10 ++- .../institution-projects.component.ts | 23 +------ .../person-projects.component.html | 9 +-- .../person-projects.component.ts | 19 +----- .../ui/data-table/data-table.component.html | 2 +- .../ui/data-table/data-table.component.ts | 68 ++++++++++++++++--- .../query-param-input.component.ts | 4 +- 7 files changed, 74 insertions(+), 61 deletions(-) diff --git a/webapp/src/app/modules/institution-projects/institution-projects.component.html b/webapp/src/app/modules/institution-projects/institution-projects.component.html index 8d0b6d47..6ad4c8f9 100644 --- a/webapp/src/app/modules/institution-projects/institution-projects.component.html +++ b/webapp/src/app/modules/institution-projects/institution-projects.component.html @@ -15,17 +15,15 @@ + queryParamSortKey="sort_by" + queryParamSortDirectionKey="sort_direction" /> + queryParamSortKey="sort_by" + queryParamSortDirectionKey="sort_direction" /> (''); - urlSortDirection = signal(''); - constructor( private readonly activatedRoute: ActivatedRoute, private readonly router: Router, ) { - this.activatedRoute.queryParams - .pipe(takeUntilDestroyed()) - .subscribe((params) => { - this.urlSortKey.set(params['sort_by'] ?? ''); - this.urlSortDirection.set( - (params['sort_direction'] as SortDirection) ?? '', - ); - }); - effect(() => { const euPage = this.cordisEuProjectPage(); if (euPage) { @@ -289,11 +275,4 @@ export class InstitutionProjectsComponent implements OnInit { queryParamsHandling: 'merge', }); } - - handleSortChange(event: Sort): void { - this.router.navigate([], { - queryParams: { sort_by: event.active, sort_direction: event.direction }, - queryParamsHandling: 'merge', - }); - } } diff --git a/webapp/src/app/modules/person-projects/person-projects.component.html b/webapp/src/app/modules/person-projects/person-projects.component.html index 7faf7c59..ed14000b 100644 --- a/webapp/src/app/modules/person-projects/person-projects.component.html +++ b/webapp/src/app/modules/person-projects/person-projects.component.html @@ -12,14 +12,15 @@ [columns]="dfgProjectColumns" [data]="dfgProjectData" [detailTemplate]="dfgProjectDetailRowTmp" - [activeSortKey]="urlSortKey()" - [sortDirection]="urlSortDirection()" - (sortChange)="handleSortChange($event)" /> + queryParamSortKey="sort_by" + queryParamSortDirectionKey="sort_direction" /> + [data]="personCordisEuProjectData" + queryParamSortKey="sort_by" + queryParamSortDirectionKey="sort_direction" /> (''); - urlSortDirection = signal(''); - readonly pageTotal = computed(() => { return this.dfgProjectPage()?.total ?? 0; }); - constructor( - private readonly router: Router, - private readonly activatedRoute: ActivatedRoute, - ) { + constructor(private readonly router: Router) { effect(() => { this.dfgProjectData = this.dfgProjectPage().elements || []; }); @@ -165,11 +157,4 @@ export class PersonProjectsComponent implements OnInit { }, ]; } - - handleSortChange(event: Sort): void { - this.router.navigate([], { - queryParams: { sort_by: event.active, sort_direction: event.direction }, - queryParamsHandling: 'merge', - }); - } } diff --git a/webapp/src/app/shared/ui/data-table/data-table.component.html b/webapp/src/app/shared/ui/data-table/data-table.component.html index 41347477..babc2916 100644 --- a/webapp/src/app/shared/ui/data-table/data-table.component.html +++ b/webapp/src/app/shared/ui/data-table/data-table.component.html @@ -3,7 +3,7 @@ mat-table [dataSource]="dataSource" matSort - (matSortChange)="onSortChange($event)" + (matSortChange)="_handleSortChange($event)" multiTemplateDataRows> @for (col of columns(); track col.id) { diff --git a/webapp/src/app/shared/ui/data-table/data-table.component.ts b/webapp/src/app/shared/ui/data-table/data-table.component.ts index 0e4c9d16..6fa71428 100644 --- a/webapp/src/app/shared/ui/data-table/data-table.component.ts +++ b/webapp/src/app/shared/ui/data-table/data-table.component.ts @@ -4,12 +4,14 @@ import { Component, computed, effect, + inject, input, output, signal, TemplateRef, viewChild, } from '@angular/core'; +import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'; import { MatSort, MatSortModule, @@ -17,6 +19,7 @@ import { SortDirection, } from '@angular/material/sort'; import { MatTableDataSource, MatTableModule } from '@angular/material/table'; +import { ActivatedRoute, Router } from '@angular/router'; export interface BaseColumn { id: string; @@ -55,15 +58,37 @@ export class DataTableComponent implements AfterViewInit { containerOverflow = computed(() => (this.maxHeight() ? 'auto' : 'visible')); stickyHeader = input(true); - activeSortKey = input(''); - sortDirection = input(''); - sortChange = output(); + queryParamSortKey = input(null); + queryParamSortDirectionKey = input(null); + + _urlSortValue = computed(() => { + const params = this.queryParams(); + const key = this.queryParamSortKey(); + + return params && key ? params[key] || null : null; + }); + + _urlSortDirectionValue = computed(() => { + const params = this.queryParams(); + const key = this.queryParamSortDirectionKey(); + + return params && key ? params[key] || null : null; + }); + + handleSortChange = output(); displayedColumns = computed(() => this.columns().map((col) => col.id)); dataSource = new MatTableDataSource([]); sort = viewChild.required(MatSort); + private readonly activatedRouter = inject(ActivatedRoute); + private readonly router = inject(Router); + + private readonly queryParams = toSignal( + this.activatedRouter.queryParams.pipe(takeUntilDestroyed()), + ); + constructor() { effect(() => { const currentData = this.data(); @@ -86,15 +111,23 @@ export class DataTableComponent implements AfterViewInit { effect(() => { const matSortInstance = this.sort(); - const activeKey = this.activeSortKey(); - const direction = this.sortDirection(); + const activeKey = this._urlSortValue(); + const direction = this._urlSortDirectionValue(); if ( matSortInstance.active !== activeKey || matSortInstance.direction !== direction ) { - matSortInstance.active = activeKey; - matSortInstance.direction = direction; + if (activeKey == null) { + matSortInstance.active = ''; + } else { + matSortInstance.active = activeKey; + } + if (direction == null) { + matSortInstance.direction = ''; + } else { + matSortInstance.direction = direction as SortDirection; + } this.dataSource.sort = matSortInstance; } @@ -105,8 +138,25 @@ export class DataTableComponent implements AfterViewInit { this.dataSource.sort = this.sort(); } - onSortChange(sort: Sort) { - this.sortChange.emit(sort); + _handleSortChange(sort: Sort): void { + this.handleSortChange.emit(sort); + + const sortKey = this.queryParamSortKey(); + const sortDirectionKey = this.queryParamSortDirectionKey(); + if (sortKey != null) { + const queryParams: any = { + [sortKey]: sort.active || null, + }; + + if (sortDirectionKey != null) { + queryParams[sortDirectionKey] = sort.direction || null; + } + + this.router.navigate([], { + queryParams, + queryParamsHandling: 'merge', + }); + } } toggleRow(row: T): void { diff --git a/webapp/src/app/shared/ui/query-param-input/query-param-input.component.ts b/webapp/src/app/shared/ui/query-param-input/query-param-input.component.ts index 85d396f1..3a3f62a7 100644 --- a/webapp/src/app/shared/ui/query-param-input/query-param-input.component.ts +++ b/webapp/src/app/shared/ui/query-param-input/query-param-input.component.ts @@ -28,11 +28,11 @@ export class QueryParamInputComponent { debounceTime = input(300); handleValueChange = output(); - private readonly activatedRouter = inject(ActivatedRoute); + private readonly activatedRoute = inject(ActivatedRoute); private readonly router = inject(Router); private readonly queryParams = toSignal( - this.activatedRouter.queryParams.pipe(takeUntilDestroyed()), + this.activatedRoute.queryParams.pipe(takeUntilDestroyed()), ); _urlValue = computed(() => {