From 6f1b17fc66f251658aaee246a653ff6b580f0528 Mon Sep 17 00:00:00 2001 From: Dark_Phoenix_ <92178883+0DarkPhoenix@users.noreply.github.com> Date: Sun, 8 Jun 2025 11:02:49 +0200 Subject: [PATCH] Convert last items to flex search (#87) * Improved performance on the Unicode Search page: - Created new flexSearch component (Faster than fuzzySearch). For more information, see https://github.com/nextapps-de/flexsearch - Replaced fuzzySearch with the flexSearch component on the unicode search page - Fixed a bug where the search limit counter didn't have any effect - Reduced the default search limit from 100 to 40 to reduce lag from loading all the ui elements * Added clarification to comment * components.d.ts update * - Replaced FuzzySearch with FlexSearch on the ISO 3166 Searcher page - Reduced the debounce from 500ms to 250ms - Reduced the default search limit from 100 to 20, and fixed a bug where the search limit wasn't applied when the value changed - Added the `readonly` prop to the `input-copyable` field - Added the `readonly` flag to all input copyable fields on the unicode search and iso 3166 searcher pages * Merged new changes to flexSearch * chore: vercel optimisation tentative * Emoji Picker: - Replaced fuzzysearch with flexsearch - Reduced debounce from 500ms to 250ms - Increased search limit from 100 to 150 - Implemented a UI loading sequence where it will load an emoji group each 150ms instead of loading all groups at once. This eliminates the lag experienced when loading the page or when removing the search query - Updated unicode-emoji-json from version 0.4.0 to 0.8.0 Emoji Card: - Fixed an issue where the country flag emojis weren't being rendered - Added row which displays the emoji keywords, and uses a tooltip to display all keywords when they are truncated to fit in the card - Moved codepoints and unicode escape lines to seperate rows instead of occasionally being displayed on the same line * - Added logic to use an emoji in the search query * small change * - Replaced fuzzysearch with flexsearch in the command pallette - Improved the performance of the collapsible tool menu by rewriting the logic to prevent the DOM elements being destroyed and recreated each time a category is expanded or collapsed - Added logic to load the home page tool cards in batches instead of all at once * Fixed linter error * Fixed an issue where the weight of a search key wasn't properly being applied * AD LDAP searcher: - Replaced fuzzysearch with flexsearch - Removed the debounce from the search field - Made all fields searchable C-Select: - Replaced fuzzysearch with flexsearch ASCII text drawer: - Fixed a bug where B1FF and Rot13 options appeared duplicate in the list, causing them to duplicate even further when searching specifically for them FuzzySearch: - Marked `useFuzzySearch` as deprecated, with the advise to use `useFlexSearch` instead * ISO 3166 searcher: - Made more fields searchable c-input-text: - Fixed an issue where country flag emojis weren't rendered * - Added batch loading for the UI elements after a search - Removed the Unicode item from the flag emoji copyable field so only the emoji is copied - Added string 'None' to be used when a country has no neighboring countries * - Disabled the cache by default because it caused minor hickups during searches and added extra documentation --------- Co-authored-by: ShareVB --- src/composable/flexSearch.ts | 26 +++++-- src/composable/fuzzySearch.ts | 5 ++ .../ad-ldap-searcher/ad-ldap-searcher.vue | 19 ++--- .../ascii-text-drawer/ascii-text-drawer.vue | 2 +- .../iso-3166-searcher/iso-3166-searcher.vue | 75 ++++++++++++++++++- src/ui/c-input-text/c-input-text.vue | 44 ++++++++++- src/ui/c-select/c-select.vue | 5 +- 7 files changed, 148 insertions(+), 28 deletions(-) diff --git a/src/composable/flexSearch.ts b/src/composable/flexSearch.ts index 875b22dd..96c12099 100644 --- a/src/composable/flexSearch.ts +++ b/src/composable/flexSearch.ts @@ -35,8 +35,19 @@ export function useFlexSearch>({ * Note: The `'tolerant'` tokenizer option mentioned in the documentation doesn't exist anymore in the current version of FlexSearch. */ tokenize?: 'strict' | 'forward' | 'reverse' | 'full' + /** + * Resolution value for giving meaningful results when searching for partial matches. + * @default 9 + * @see {@link https://github.com/nextapps-de/flexsearch?tab=readme-ov-file#resolution | FlexSearch Resolution Documentation} + */ resolution?: number optimize?: boolean + /** + * Value to determine if the cache should be used. + * If set to a number, the cache will use the number to assign that number of cache slots (No information in the documentation is provided about what a cache slot is exactly). + * @default false + * @see {@link https://github.com/nextapps-de/flexsearch?tab=readme-ov-file#auto-balanced-cache-by-popularity | FlexSearch Cache Documentation} + */ cache?: boolean | number } limit?: MaybeRef @@ -67,7 +78,7 @@ export function useFlexSearch>({ preset: 'performance', resolution: 9, optimize: true, - cache: 100, + cache: false, fastupdate: true, ...indexOptions, }), @@ -142,11 +153,9 @@ export function useFlexSearch>({ }) .map(([id]) => id); - // Apply limit and convert back to original items - const limitedIds = searchLimit > 0 ? sortedIds.slice(0, searchLimit) : sortedIds; - - // Return the limited results early if it shouldn't be sorted by similarity + // If shouldn't be sorted by similarity, apply limit here and return early if (!shouldSort) { + const limitedIds = searchLimit > 0 ? sortedIds.slice(0, searchLimit) : sortedIds; return limitedIds .map(id => dataMap.value.get(id)) .filter(Boolean) as Data[]; @@ -188,8 +197,8 @@ export function useFlexSearch>({ return 1 - (distance / maxLength); }; - // Sort limited results by similarity score, but maintain weight priority - const sortedResults = limitedIds + // Sort ALL results by similarity score, then apply limit at the end + const sortedResults = sortedIds .map((id) => { const item = dataMap.value.get(id); if (!item) { @@ -229,7 +238,8 @@ export function useFlexSearch>({ }) .map(result => result!.item); - return sortedResults as Data[]; + // Apply limit after final sorting + return searchLimit > 0 ? sortedResults.slice(0, searchLimit) : sortedResults; }; // Computed results diff --git a/src/composable/fuzzySearch.ts b/src/composable/fuzzySearch.ts index bf6c8000..1264d2c9 100644 --- a/src/composable/fuzzySearch.ts +++ b/src/composable/fuzzySearch.ts @@ -1,9 +1,14 @@ import { type MaybeRef, get } from '@vueuse/core'; import Fuse, { type IFuseOptions } from 'fuse.js'; import { computed } from 'vue'; +import { useFlexSearch } from './flexSearch'; export { useFuzzySearch }; +/** + * @deprecated This composable is deprecated and will be removed in a future version. + * Use {@link useFlexSearch} instead. + */ function useFuzzySearch({ search, data, diff --git a/src/tools/ad-ldap-searcher/ad-ldap-searcher.vue b/src/tools/ad-ldap-searcher/ad-ldap-searcher.vue index 0918bce2..441e1f14 100644 --- a/src/tools/ad-ldap-searcher/ad-ldap-searcher.vue +++ b/src/tools/ad-ldap-searcher/ad-ldap-searcher.vue @@ -1,20 +1,15 @@