Normalize diacritics when searching conversations
This commit is contained in:
parent
e0fa526131
commit
1622fe21e7
3 changed files with 27 additions and 1 deletions
|
@ -36,6 +36,7 @@ import {
|
|||
CONVERSATION_UNLOADED,
|
||||
TARGETED_CONVERSATION_CHANGED,
|
||||
} from './conversations';
|
||||
import { removeDiacritics } from '../../util/removeDiacritics';
|
||||
|
||||
const {
|
||||
searchMessages: dataSearchMessages,
|
||||
|
@ -286,8 +287,14 @@ async function queryConversationsAndContacts(
|
|||
const { ourConversationId, noteToSelf, regionCode, allConversations } =
|
||||
options;
|
||||
|
||||
const normalizedQuery = removeDiacritics(query);
|
||||
|
||||
const searchResults: Array<ConversationType> =
|
||||
filterAndSortConversationsByRecent(allConversations, query, regionCode);
|
||||
filterAndSortConversationsByRecent(
|
||||
allConversations,
|
||||
normalizedQuery,
|
||||
regionCode
|
||||
);
|
||||
|
||||
// Split into two groups - active conversations and items just from address book
|
||||
let conversationIds: Array<string> = [];
|
||||
|
|
|
@ -6,6 +6,7 @@ import Fuse from 'fuse.js';
|
|||
import type { ConversationType } from '../state/ducks/conversations';
|
||||
import { parseAndFormatPhoneNumber } from './libphonenumberInstance';
|
||||
import { WEEK } from './durations';
|
||||
import { removeDiacritics } from './removeDiacritics';
|
||||
|
||||
// Fuse.js scores have order of 0.01
|
||||
const ACTIVE_AT_SCORE_FACTOR = (1 / WEEK) * 0.01;
|
||||
|
@ -44,6 +45,18 @@ const FUSE_OPTIONS: Fuse.IFuseOptions<ConversationType> = {
|
|||
weight: 0.5,
|
||||
},
|
||||
],
|
||||
getFn: (...args) => {
|
||||
const text = Fuse.config.getFn(...args);
|
||||
if (!text) {
|
||||
return text;
|
||||
}
|
||||
|
||||
if (typeof text === 'string') {
|
||||
return removeDiacritics(text);
|
||||
}
|
||||
|
||||
return text.map(removeDiacritics);
|
||||
},
|
||||
};
|
||||
|
||||
const cachedIndices = new WeakMap<
|
||||
|
|
6
ts/util/removeDiacritics.ts
Normal file
6
ts/util/removeDiacritics.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
export function removeDiacritics(text: string): string {
|
||||
return text.normalize('NFD').replace(/\p{Diacritic}/gu, '');
|
||||
}
|
Loading…
Reference in a new issue