pl-fe: fix emoji search

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-10-16 23:36:49 +02:00
parent 3e45a3142b
commit 8ae3adbe5a

View file

@ -6,7 +6,14 @@ import type { CustomEmoji } from 'pl-api';
let emojis: EmojiData['emojis'] = {};
import('./data').then(data => emojis = data.emojis).catch(() => { });
import('./data').then(data => {
emojis = data.emojis;
const sortedEmojis = Object.entries(emojis).sort((a, b) => a[0].localeCompare(b[0]));
for (const [key, emoji] of sortedEmojis) {
index.add('n' + key, `${emoji.id} ${emoji.name} ${emoji.keywords.join(' ')}`);
}
}).catch(() => { });
const index = new FlexSearch.Index({
tokenize: 'full',
@ -14,11 +21,6 @@ const index = new FlexSearch.Index({
context: true,
});
const sortedEmojis = Object.entries(emojis).sort((a, b) => a[0].localeCompare(b[0]));
for (const [key, emoji] of sortedEmojis) {
index.add('n' + key, `${emoji.id} ${emoji.name} ${emoji.keywords.join(' ')}`);
}
interface searchOptions {
maxResults?: number;
custom?: any;