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 @@