mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-29 16:40:29 +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,
|
search,
|
||||||
data,
|
data,
|
||||||
options = {},
|
options = {},
|
||||||
|
limit = -1,
|
||||||
}: {
|
}: {
|
||||||
search: MaybeRef<string>
|
search: MaybeRef<string>
|
||||||
data: Data[]
|
data: Data[]
|
||||||
options?: IFuseOptions<Data> & { filterEmpty?: boolean }
|
options?: IFuseOptions<Data> & { filterEmpty?: boolean }
|
||||||
|
limit?: number
|
||||||
}) {
|
}) {
|
||||||
const fuse = new Fuse(data, options);
|
const fuse = new Fuse(data, options);
|
||||||
const filterEmpty = options.filterEmpty ?? true;
|
const filterEmpty = options.filterEmpty ?? true;
|
||||||
@@ -23,7 +25,7 @@ function useFuzzySearch<Data>({
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fuse.search(query).map(({ item }) => item);
|
return fuse.search(query, { limit }).map(({ item }) => item);
|
||||||
});
|
});
|
||||||
|
|
||||||
return { searchResult };
|
return { searchResult };
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const emojisGroups: { emojiInfos: EmojiInfo[]; group: string }[] = _
|
|||||||
.map((emojiInfos, group) => ({ group, emojiInfos }))
|
.map((emojiInfos, group) => ({ group, emojiInfos }))
|
||||||
.value();
|
.value();
|
||||||
|
|
||||||
|
const limit = ref(100);
|
||||||
const searchQuery = useDebouncedRef('', 500);
|
const searchQuery = useDebouncedRef('', 500);
|
||||||
|
|
||||||
const { searchResult } = useFuzzySearch({
|
const { searchResult } = useFuzzySearch({
|
||||||
@@ -35,21 +36,24 @@ const { searchResult } = useFuzzySearch({
|
|||||||
useExtendedSearch: true,
|
useExtendedSearch: true,
|
||||||
isCaseSensitive: false,
|
isCaseSensitive: false,
|
||||||
},
|
},
|
||||||
|
limit: limit.value,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div mx-auto max-w-2400px important:flex-1>
|
<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
|
<c-input-text
|
||||||
v-model:value="searchQuery"
|
v-model:value="searchQuery"
|
||||||
placeholder="Search emojis (e.g. 'smile')..."
|
placeholder="Search emojis (e.g. 'smile')..."
|
||||||
mx-auto max-w-600px
|
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
||||||
</template>
|
</template>
|
||||||
</c-input-text>
|
</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>
|
||||||
|
|
||||||
<div v-if="searchQuery.trim().length > 0">
|
<div v-if="searchQuery.trim().length > 0">
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const countriesSearchData = Object.entries(CountriesDB.getAllCountries()).map(([
|
|||||||
info,
|
info,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
const limit = ref(100);
|
||||||
const { searchResult } = useFuzzySearch({
|
const { searchResult } = useFuzzySearch({
|
||||||
search: searchQuery,
|
search: searchQuery,
|
||||||
data: countriesSearchData,
|
data: countriesSearchData,
|
||||||
@@ -23,6 +24,7 @@ const { searchResult } = useFuzzySearch({
|
|||||||
isCaseSensitive: false,
|
isCaseSensitive: false,
|
||||||
useExtendedSearch: true,
|
useExtendedSearch: true,
|
||||||
},
|
},
|
||||||
|
limit: limit.value,
|
||||||
});
|
});
|
||||||
|
|
||||||
function langToName(code: string) {
|
function langToName(code: string) {
|
||||||
@@ -36,16 +38,18 @@ function langToName(code: string) {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div mx-auto max-w-2400px important:flex-1>
|
<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
|
<c-input-text
|
||||||
v-model:value="searchQuery"
|
v-model:value="searchQuery"
|
||||||
placeholder="Search Countries by name, iso2, iso3..."
|
placeholder="Search Countries by name, iso2, iso3..."
|
||||||
mx-auto max-w-600px
|
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
||||||
</template>
|
</template>
|
||||||
</c-input-text>
|
</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>
|
||||||
|
|
||||||
<div v-if="searchQuery.trim().length > 0">
|
<div v-if="searchQuery.trim().length > 0">
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ const unicodeSearchData = [...unicodeNames].map(([codePoint, characterName]) =>
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const limit = ref(100);
|
||||||
const { searchResult } = useFuzzySearch({
|
const { searchResult } = useFuzzySearch({
|
||||||
search: parsedSearchQuery,
|
search: parsedSearchQuery,
|
||||||
data: unicodeSearchData,
|
data: unicodeSearchData,
|
||||||
@@ -49,21 +50,24 @@ const { searchResult } = useFuzzySearch({
|
|||||||
minMatchCharLength: 3,
|
minMatchCharLength: 3,
|
||||||
useExtendedSearch: true,
|
useExtendedSearch: true,
|
||||||
},
|
},
|
||||||
|
limit: limit.value,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div mx-auto max-w-2400px important:flex-1>
|
<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
|
<c-input-text
|
||||||
v-model:value="searchQuery"
|
v-model:value="searchQuery"
|
||||||
placeholder="Search Unicode by name (e.g. 'zero width') or code point..."
|
placeholder="Search Unicode by name (e.g. 'zero width') or code point..."
|
||||||
mx-auto max-w-600px
|
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
||||||
</template>
|
</template>
|
||||||
</c-input-text>
|
</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>
|
||||||
|
|
||||||
<div v-if="searchQuery.trim().length > 0">
|
<div v-if="searchQuery.trim().length > 0">
|
||||||
|
|||||||
Reference in new issue
Block a user