Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(settings): require all query words to match (#1665)

Liam358b7c88fc63
diff --git a/fluxer_app/src/features/user/components/settings_utils/SettingsSearchIndex.ts b/fluxer_app/src/features/user/components/settings_utils/SettingsSearchIndex.ts
index 763d10edd..c1b05ef94 100644
--- a/fluxer_app/src/features/user/components/settings_utils/SettingsSearchIndex.ts
+++ b/fluxer_app/src/features/user/components/settings_utils/SettingsSearchIndex.ts
@@ -168,16 +168,27 @@ function calculateKeywordMatchScore(keywords: Array<string>, word: string): numb
function calculateMatchScore(item: SearchableSettingItem, queryWords: Array<string>): number {
let score = 0;
+
const labelLower = item.label.toLowerCase();
const descriptionLower = item.description?.toLowerCase() ?? '';
- const keywordsLower = [...item.keywords, ...(item.tags ?? [])].map((k) => k.toLowerCase());
+ const keywordsLower = [...item.keywords, ...(item.tags ?? [])].map((value) => value.toLowerCase());
+
for (const word of queryWords) {
- score += calculateTextMatchScore(labelLower, word, 100, 50, 25);
- score += calculateKeywordMatchScore(keywordsLower, word);
+ let wordScore = calculateTextMatchScore(labelLower, word, 100, 50, 25);
+
+ wordScore += calculateKeywordMatchScore(keywordsLower, word);
+
if (descriptionLower.includes(word)) {
- score += 10;
+ wordScore += 10;
}
+
+ if (wordScore === 0) {
+ return 0;
+ }
+
+ score += wordScore;
}
+
return score;
}