mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
fix: fuzzy search limits
This commit is contained in:
1 parent
637ba07ef3
commit
6518ed6fcb
4 files changed
+21
-7
No files matched your search
@@ -8,10 +8,12 @@ function useFuzzySearch<Data>({
|
||||
search,
|
||||
data,
|
||||
options = {},
|
||||
limit = -1,
|
||||
}: {
|
||||
search: MaybeRef<string>
|
||||
data: Data[]
|
||||
options?: IFuseOptions<Data> & { filterEmpty?: boolean }
|
||||
limit?: number
|
||||
}) {
|
||||
const fuse = new Fuse(data, options);
|
||||
const filterEmpty = options.filterEmpty ?? true;
|
||||
@@ -23,7 +25,7 @@ function useFuzzySearch<Data>({
|
||||
return data;
|
||||
}
|
||||
|
||||
return fuse.search(query).map(({ item }) => item);
|
||||
return fuse.search(query, { limit }).map(({ item }) => item);
|
||||
});
|
||||
|
||||
return { searchResult };
|
||||
|
||||
@@ -24,6 +24,7 @@ const emojisGroups: { emojiInfos: EmojiInfo[]; group: string }[] = _
|
||||
.map((emojiInfos, group) => ({ group, emojiInfos }))
|
||||
.value();
|
||||
|
||||
const limit = ref(100);
|
||||
const searchQuery = useDebouncedRef('', 500);
|
||||
|
||||
const { searchResult } = useFuzzySearch({
|
||||
@@ -35,21 +36,24 @@ const { searchResult } = useFuzzySearch({
|
||||
useExtendedSearch: true,
|
||||
isCaseSensitive: false,
|
||||
},
|
||||
limit: limit.value,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div mx-auto max-w-2400px important:flex-1>
|
||||
<div flex items-center gap-3>
|
||||
<div mx-auto max-w-600px flex justify-center gap-3>
|
||||
<c-input-text
|
||||
v-model:value="searchQuery"
|
||||
placeholder="Search emojis (e.g. 'smile')..."
|
||||
mx-auto max-w-600px
|
||||
>
|
||||
<template #prefix>
|
||||
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
||||
</template>
|
||||
</c-input-text>
|
||||
<n-form-item label="Max results:" label-placement="left">
|
||||
<n-input-number v-model:value="limit" :min="1" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div v-if="searchQuery.trim().length > 0">
|
||||
|
||||
@@ -14,6 +14,7 @@ const countriesSearchData = Object.entries(CountriesDB.getAllCountries()).map(([
|
||||
info,
|
||||
};
|
||||
});
|
||||
const limit = ref(100);
|
||||
const { searchResult } = useFuzzySearch({
|
||||
search: searchQuery,
|
||||
data: countriesSearchData,
|
||||
@@ -23,6 +24,7 @@ const { searchResult } = useFuzzySearch({
|
||||
isCaseSensitive: false,
|
||||
useExtendedSearch: true,
|
||||
},
|
||||
limit: limit.value,
|
||||
});
|
||||
|
||||
function langToName(code: string) {
|
||||
@@ -36,16 +38,18 @@ function langToName(code: string) {
|
||||
|
||||
<template>
|
||||
<div mx-auto max-w-2400px important:flex-1>
|
||||
<div flex items-center gap-3>
|
||||
<div mx-auto max-w-600px flex justify-center gap-3>
|
||||
<c-input-text
|
||||
v-model:value="searchQuery"
|
||||
placeholder="Search Countries by name, iso2, iso3..."
|
||||
mx-auto max-w-600px
|
||||
>
|
||||
<template #prefix>
|
||||
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
||||
</template>
|
||||
</c-input-text>
|
||||
<n-form-item label="Max results:" label-placement="left">
|
||||
<n-input-number v-model:value="limit" :min="1" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div v-if="searchQuery.trim().length > 0">
|
||||
|
||||
@@ -39,6 +39,7 @@ const unicodeSearchData = [...unicodeNames].map(([codePoint, characterName]) =>
|
||||
};
|
||||
});
|
||||
|
||||
const limit = ref(100);
|
||||
const { searchResult } = useFuzzySearch({
|
||||
search: parsedSearchQuery,
|
||||
data: unicodeSearchData,
|
||||
@@ -49,21 +50,24 @@ const { searchResult } = useFuzzySearch({
|
||||
minMatchCharLength: 3,
|
||||
useExtendedSearch: true,
|
||||
},
|
||||
limit: limit.value,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div mx-auto max-w-2400px important:flex-1>
|
||||
<div flex items-center gap-3>
|
||||
<div mx-auto max-w-600px flex justify-center gap-3>
|
||||
<c-input-text
|
||||
v-model:value="searchQuery"
|
||||
placeholder="Search Unicode by name (e.g. 'zero width') or code point..."
|
||||
mx-auto max-w-600px
|
||||
>
|
||||
<template #prefix>
|
||||
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
||||
</template>
|
||||
</c-input-text>
|
||||
<n-form-item label="Max results:" label-placement="left">
|
||||
<n-input-number v-model:value="limit" :min="1" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div v-if="searchQuery.trim().length > 0">
|
||||
|
||||
Reference in new issue
Block a user