code cleaned, minor bugfixing

This commit is contained in:
2026-07-14 13:24:46 +02:00
parent 8f1462cecc
commit ec78bdb1f3
3 changed files with 25 additions and 61 deletions
@@ -159,7 +159,6 @@
</mat-button-toggle>
</mat-button-toggle-group>
</div>
<div class="toolbar-divider"></div>
</div>
<div class="spacer toolbar-controls manual-input-controls">
@@ -23,7 +23,7 @@
<mat-slide-toggle
labelPosition="before"
(change)="onToggleFuzzySearch($event)"
[checked]="fuzzySearch()"
[checked]="state.fuzzySearch()"
matTooltip="Wenn aktiviert, werden die extrahierten Keywords auf bekannte Themenbereiche abgebildet, was die Suchergebnisse vermehrt">
Fuzzy Search
</mat-slide-toggle>
@@ -63,56 +63,19 @@ export class KeywordsSearchResultsComponent {
];
readonly selectedKeywordCount = computed(() => this.state.keywords().length);
readonly fuzzySearch = signal<boolean>(false);
readonly selectedKeywordEntries = computed(() => {
const payload = this.state.payload();
if (!payload) return [];
const allEntries = [
...(payload.extractedKeywords ?? []),
...(payload.manualKeywords ?? []),
];
const entryByKeyword = new Map<string, KeywordEntryWithTopic>();
for (const entry of allEntries) {
entryByKeyword.set(
this.normalizeKeyword(this.getKeywordLabel(entry)),
entry,
);
}
const result: KeywordEntryWithTopic[] = [];
readonly allKeywordEntries = computed(() => {
const seen = new Set<string>();
for (const keyword of payload.keywords) {
const normalized = this.normalizeKeyword(keyword);
const entry = entryByKeyword.get(normalized);
if (!entry || seen.has(normalized)) continue;
seen.add(normalized);
result.push(entry);
}
return result;
const all = [
...this.state.extractedKeywords(),
...this.state.manualKeywords(),
];
return all.filter((entry) => {
const kw = entry.llm_keyword?.keyword?.trim().toLowerCase();
if (!kw || seen.has(kw)) return false;
seen.add(kw);
return true;
});
});
readonly missingKeywordLabels = computed(() => {
const payload = this.state.payload();
if (!payload) return [];
const entryKeywordSet = new Set(
this.selectedKeywordEntries().map((entry) =>
this.normalizeKeyword(this.getKeywordLabel(entry)),
),
);
return payload.keywords.filter(
(keyword) => !entryKeywordSet.has(this.normalizeKeyword(keyword)),
);
});
constructor() {
// Query params are authoritative (URL survives reload, deep links,
// browser back/forward). sessionStorage is a best-effort cache for the
@@ -133,11 +96,8 @@ export class KeywordsSearchResultsComponent {
extractedKeywords: cacheMatches ? cached!.extractedKeywords : [],
manualKeywords: cacheMatches ? cached!.manualKeywords : [],
});
this.fuzzySearch.set(fuzzySearch);
});
}
goBackToSearch(): void {
void this.router.navigate(['/keywords'], {
queryParamsHandling: 'merge',
@@ -145,7 +105,7 @@ export class KeywordsSearchResultsComponent {
}
getChipLabel(keyword: KeywordEntryWithTopic): string {
if (!this.fuzzySearch()) {
if (!this.state.fuzzySearch()) {
return keyword.llm_keyword?.keyword ?? '';
}
return (
@@ -222,9 +182,9 @@ export class KeywordsSearchResultsComponent {
}
private sameKeywordSet(a: string[], b: string[]): boolean {
if (a.length !== b.length) return false;
const setA = new Set(a.map((k) => this.normalizeKeyword(k)));
return b.every((k) => setA.has(this.normalizeKeyword(k)));
const setA = new Set(a.map(this.normalizeKeyword.bind(this)));
const setB = new Set(b.map(this.normalizeKeyword.bind(this)));
return setA.size === setB.size && [...setA].every((k) => setB.has(k));
}
private parseKeywordList(raw: string | null): string[] {
@@ -247,12 +207,17 @@ export class KeywordsSearchResultsComponent {
return value.trim().toLowerCase();
}
onToggleFuzzySearch(event: any): void {
this.fuzzySearch.set(event.checked);
this.updateQueryParams(event.checked);
}
updateQueryParams(fuzzy: boolean): void {
console.log('Updating query params with keywords:', fuzzy);
const queryParams = {
fuzzy: fuzzy,
};
this.router.navigate([], {
relativeTo: this.route,
queryParams: {
fuzzy: this.fuzzySearch(),
},
queryParams,
queryParamsHandling: 'merge',
replaceUrl: true,
});