fixed resolver issues, where fuzzy search would not display anything

This commit is contained in:
Kazgatari
2026-07-31 13:55:02 +02:00
parent fa9def349c
commit 9f10e9e7af
5 changed files with 102 additions and 33 deletions
+4 -1
View File
@@ -285,6 +285,7 @@ export const routes: Routes = [
'search_type',
'topic',
'topics',
'trend_topics',
'keyword',
'keywords',
'institutions',
@@ -294,7 +295,9 @@ export const routes: Routes = [
'fuzzy',
];
return keys.some(
(key) => from.queryParamMap.get(key) !== to.queryParamMap.get(key),
(key) =>
from.queryParamMap.getAll(key).join(',') !==
to.queryParamMap.getAll(key).join(','),
);
},
},
@@ -107,6 +107,15 @@ export class SearchResultsStateService {
result.push(entry);
}
console.log(
'[TrendDebug] SearchResultsStateService selectedKeywordEntries:',
result.map((e) => ({
kw: e.llm_keyword?.keyword,
topicName: e.topic_mapping?.topic?.display_name,
topicId: e.topic_mapping?.topic?.id,
})),
);
return result;
});
@@ -150,10 +159,21 @@ export class SearchResultsStateService {
return kw;
})
.filter((t) => t.length > 0);
return Array.from(new Set(list));
const uniqueTopics = Array.from(new Set(list));
console.log(
'[TrendDebug] SearchResultsStateService topicsList computed:',
uniqueTopics,
);
return uniqueTopics;
});
setPayload(payload: SearchResultsPayload): void {
console.log('[TrendDebug] SearchResultsStateService setPayload:', {
keywords: payload.keywords,
extractedCount: payload.extractedKeywords?.length ?? 0,
manualCount: payload.manualKeywords?.length ?? 0,
fuzzy: payload.options?.fuzzy,
});
this._payload.set(payload);
}
}
@@ -186,7 +186,7 @@
}
@if (selectedTrendTopics().length > 0) {
<div class="chart-topic-tabs">
@for (topic of selectedTrendTopics(); track topic) {
@for (topic of selectedTrendTopics(); track $index) {
@if (selectedSearchType() === 'news') {
<app-topic-chip
[label]="getMappedTopic(topic)"
@@ -821,6 +821,12 @@ export class UniTrendParentComponent implements OnInit {
const type = resolved.searchType || this.selectedSearchType();
this.selectedSearchType.set(type);
console.log('[TrendDebug] UniTrendParent route data received:', {
resolvedTopics: resolved.topics,
initialActiveTopic: resolved.initialActiveTopic,
seriesCount: res?.series?.length ?? 0,
});
if (resolved.topics && resolved.topics.length > 0) {
this.selectedTrendTopics.set(resolved.topics);
const targetTopic =
@@ -855,12 +861,12 @@ export class UniTrendParentComponent implements OnInit {
effect(() => {
const kws = this.keywords();
const fuzzy = this.isFuzzy();
const topics = fuzzy ? (this.state?.topicsList() ?? kws) : kws;
const currentSelections = untracked(() => this.selectedTrendTopics());
const currentActive = untracked(() => this.activeChartTopic());
const stateTopicsList = this.state?.topicsList();
const topics = fuzzy ? (stateTopicsList ?? kws) : kws;
if (topics.length > 0) {
const altTopics = fuzzy ? kws : (this.state?.topicsList() ?? kws);
const currentSelections = untracked(() => this.selectedTrendTopics());
const altTopics = fuzzy ? kws : (stateTopicsList ?? kws);
const mappedSelections: string[] = [];
currentSelections.forEach((item) => {
@@ -874,29 +880,37 @@ export class UniTrendParentComponent implements OnInit {
}
});
const finalSelections = Array.from(new Set(mappedSelections));
if (finalSelections.length > 0) {
this.selectedTrendTopics.set(finalSelections);
} else {
this.selectedTrendTopics.set(topics);
const targetSelections =
mappedSelections.length > 0
? Array.from(new Set(mappedSelections))
: topics;
// Only update selectedTrendTopics if array actually changed to prevent DOM re-creation
const current = untracked(() => this.selectedTrendTopics());
const hasChanged =
targetSelections.length !== current.length ||
targetSelections.some((t, i) => t !== current[i]);
if (hasChanged) {
this.selectedTrendTopics.set(targetSelections);
}
const active = currentActive;
const updatedSelections = untracked(() => this.selectedTrendTopics());
const mappedActive = this.getMappedTopic(active);
if (
mappedActive &&
updatedSelections.includes(mappedActive) &&
!this.isTopicEmpty(mappedActive)
) {
this.activeChartTopic.set(mappedActive);
} else {
this.activeChartTopic.set(
this.findFirstNonEmptyTopic(updatedSelections),
);
const currentActive = untracked(() => this.activeChartTopic());
const validSelections = untracked(() => this.selectedTrendTopics());
if (!currentActive || !validSelections.includes(currentActive)) {
const firstValid = this.findFirstNonEmptyTopic(validSelections);
if (firstValid) {
this.activeChartTopic.set(firstValid);
} else if (validSelections.length > 0) {
this.activeChartTopic.set(validSelections[0]);
}
}
} else {
this.selectedTrendTopics.set([]);
const current = untracked(() => this.selectedTrendTopics());
if (current.length > 0) {
this.selectedTrendTopics.set([]);
}
}
});
+39 -7
View File
@@ -66,18 +66,44 @@ export const uniTrendResolver: ResolveFn<UniTrendResolvedData> = (
keywords = searchState.keywords();
}
let topics = params.getAll('topic');
let topics = [
...params.getAll('trend_topics'),
...params.getAll('trend_topic'),
];
if (topics.length === 0) {
const rawTopics = params.get('topics');
if (rawTopics) {
topics = rawTopics
.split(',')
const rawTopicsList = [
...params.getAll('topic'),
...params.getAll('topics'),
];
if (rawTopicsList.length > 0) {
topics = rawTopicsList
.flatMap((t) => t.split(','))
.map((t) => t.trim())
.filter((t) => t.length > 0);
}
}
if (topics.length === 0 && searchState) {
topics = fuzzy ? searchState.topicsList() : searchState.keywords();
console.log('[TrendDebug] Resolver input params:', {
fuzzy,
searchType,
urlTrendTopics: params.getAll('trend_topics'),
urlTopics: params.getAll('topics'),
urlKeywords: params.get('keywords') || params.getAll('keyword'),
hasSearchState: !!searchState,
});
if (searchState) {
const stateTopics = fuzzy
? searchState.topicsList()
: searchState.keywords();
if (
topics.length === 0 ||
(fuzzy &&
stateTopics.length > 0 &&
topics.some((t) => t.startsWith('http') || /^T\d+$/i.test(t)))
) {
topics = stateTopics;
}
}
// Fallback defaults if no topics/keywords present yet
@@ -90,6 +116,12 @@ export const uniTrendResolver: ResolveFn<UniTrendResolvedData> = (
keywords = topics;
}
console.log('[TrendDebug] Resolver resolved topics & keywords:', {
topics,
keywords,
searchType,
});
// Parse comparison items ensuring clean uppercase OpenAlex IDs
const instParams = params.getAll('institutions');
const parsedInstitutions: CompareItem[] = instParams.map((i) => {