mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-21 05:24:06 +03:00
Improve IES Lighting guidelines performance (#83)
* 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 * Fixed incorrect case usage for functions and variables * - Replaced fuzzysearch with flexsearch on the IES Lighting Guidelines page - Reduced the debounce from 500ms to 250ms - Changed the search keys so all columns are now searchable * - Added logic to sort the limited results using a similarity score created by calculating the Levenshtein distance - Added the `shouldSort` boolean to control whether the results should be filtered by similarity. `true` by default * Merged new changes to flexSearch * - Added readonly flag to input copyable fields
This commit is contained in:
1 parent
226081db3a
commit
02df1bc9f2
3 files changed
+106
-34
No files matched your search
Vendored
+10
-16
@@ -12,6 +12,7 @@ declare module '@vue/runtime-core' {
|
|||||||
'404.page': typeof import('./src/pages/404.page.vue')['default']
|
'404.page': typeof import('./src/pages/404.page.vue')['default']
|
||||||
About: typeof import('./src/pages/About.vue')['default']
|
About: typeof import('./src/pages/About.vue')['default']
|
||||||
AdLdapSearcher: typeof import('./src/tools/ad-ldap-searcher/ad-ldap-searcher.vue')['default']
|
AdLdapSearcher: typeof import('./src/tools/ad-ldap-searcher/ad-ldap-searcher.vue')['default']
|
||||||
|
AgeCrypto: typeof import('./src/tools/age-crypto/age-crypto.vue')['default']
|
||||||
AiPromptSplitter: typeof import('./src/tools/ai-prompt-splitter/ai-prompt-splitter.vue')['default']
|
AiPromptSplitter: typeof import('./src/tools/ai-prompt-splitter/ai-prompt-splitter.vue')['default']
|
||||||
AlarmSoundToggle: typeof import('./src/tools/pomodoro-timer/app/components/AlarmSoundToggle.vue')['default']
|
AlarmSoundToggle: typeof import('./src/tools/pomodoro-timer/app/components/AlarmSoundToggle.vue')['default']
|
||||||
AngleConverter: typeof import('./src/tools/angle-converter/angle-converter.vue')['default']
|
AngleConverter: typeof import('./src/tools/angle-converter/angle-converter.vue')['default']
|
||||||
@@ -28,6 +29,8 @@ declare module '@vue/runtime-core' {
|
|||||||
Base64FileConverter: typeof import('./src/tools/base64-file-converter/base64-file-converter.vue')['default']
|
Base64FileConverter: typeof import('./src/tools/base64-file-converter/base64-file-converter.vue')['default']
|
||||||
Base64HexConverter: typeof import('./src/tools/base64-hex-converter/base64-hex-converter.vue')['default']
|
Base64HexConverter: typeof import('./src/tools/base64-hex-converter/base64-hex-converter.vue')['default']
|
||||||
Base64StringConverter: typeof import('./src/tools/base64-string-converter/base64-string-converter.vue')['default']
|
Base64StringConverter: typeof import('./src/tools/base64-string-converter/base64-string-converter.vue')['default']
|
||||||
|
BashMemo: typeof import('./src/tools/bash-memo/bash-memo.vue')['default']
|
||||||
|
'BashMemo.content': typeof import('./src/tools/bash-memo/bash-memo.content.md')['default']
|
||||||
BasicAuthGenerator: typeof import('./src/tools/basic-auth-generator/basic-auth-generator.vue')['default']
|
BasicAuthGenerator: typeof import('./src/tools/basic-auth-generator/basic-auth-generator.vue')['default']
|
||||||
Bcrypt: typeof import('./src/tools/bcrypt/bcrypt.vue')['default']
|
Bcrypt: typeof import('./src/tools/bcrypt/bcrypt.vue')['default']
|
||||||
BenchmarkBuilder: typeof import('./src/tools/benchmark-builder/benchmark-builder.vue')['default']
|
BenchmarkBuilder: typeof import('./src/tools/benchmark-builder/benchmark-builder.vue')['default']
|
||||||
@@ -259,6 +262,8 @@ declare module '@vue/runtime-core' {
|
|||||||
JsUnobfuscator: typeof import('./src/tools/js-unobfuscator/js-unobfuscator.vue')['default']
|
JsUnobfuscator: typeof import('./src/tools/js-unobfuscator/js-unobfuscator.vue')['default']
|
||||||
JwtGenerator: typeof import('./src/tools/jwt-generator/jwt-generator.vue')['default']
|
JwtGenerator: typeof import('./src/tools/jwt-generator/jwt-generator.vue')['default']
|
||||||
JwtParser: typeof import('./src/tools/jwt-parser/jwt-parser.vue')['default']
|
JwtParser: typeof import('./src/tools/jwt-parser/jwt-parser.vue')['default']
|
||||||
|
K8sMemo: typeof import('./src/tools/k8s-memo/k8s-memo.vue')['default']
|
||||||
|
'K8sMemo.content': typeof import('./src/tools/k8s-memo/k8s-memo.content.md')['default']
|
||||||
KeycodeInfo: typeof import('./src/tools/keycode-info/keycode-info.vue')['default']
|
KeycodeInfo: typeof import('./src/tools/keycode-info/keycode-info.vue')['default']
|
||||||
LengthConverter: typeof import('./src/tools/length-converter/length-converter.vue')['default']
|
LengthConverter: typeof import('./src/tools/length-converter/length-converter.vue')['default']
|
||||||
ListComparer: typeof import('./src/tools/list-comparer/list-comparer.vue')['default']
|
ListComparer: typeof import('./src/tools/list-comparer/list-comparer.vue')['default']
|
||||||
@@ -294,40 +299,26 @@ declare module '@vue/runtime-core' {
|
|||||||
MultiLinkDownloader: typeof import('./src/tools/multi-link-downloader/multi-link-downloader.vue')['default']
|
MultiLinkDownloader: typeof import('./src/tools/multi-link-downloader/multi-link-downloader.vue')['default']
|
||||||
MyIp: typeof import('./src/tools/my-ip/my-ip.vue')['default']
|
MyIp: typeof import('./src/tools/my-ip/my-ip.vue')['default']
|
||||||
NA: typeof import('naive-ui')['NA']
|
NA: typeof import('naive-ui')['NA']
|
||||||
NAlert: typeof import('naive-ui')['NAlert']
|
|
||||||
NanoidGenerator: typeof import('./src/tools/nanoid-generator/nanoid-generator.vue')['default']
|
NanoidGenerator: typeof import('./src/tools/nanoid-generator/nanoid-generator.vue')['default']
|
||||||
NanoMemo: typeof import('./src/tools/nano-memo/nano-memo.vue')['default']
|
NanoMemo: typeof import('./src/tools/nano-memo/nano-memo.vue')['default']
|
||||||
'NanoMemo.content': typeof import('./src/tools/nano-memo/nano-memo.content.md')['default']
|
'NanoMemo.content': typeof import('./src/tools/nano-memo/nano-memo.content.md')['default']
|
||||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||||
NButton: typeof import('naive-ui')['NButton']
|
|
||||||
NCard: typeof import('naive-ui')['NCard']
|
|
||||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
|
||||||
NCheckboxGroup: typeof import('naive-ui')['NCheckboxGroup']
|
|
||||||
NCode: typeof import('naive-ui')['NCode']
|
|
||||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||||
NDataTable: typeof import('naive-ui')['NDataTable']
|
|
||||||
NDivider: typeof import('naive-ui')['NDivider']
|
|
||||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||||
NginxFormatter: typeof import('./src/tools/nginx-formatter/nginx-formatter.vue')['default']
|
NginxFormatter: typeof import('./src/tools/nginx-formatter/nginx-formatter.vue')['default']
|
||||||
|
NginxMemo: typeof import('./src/tools/nginx-memo/nginx-memo.vue')['default']
|
||||||
|
'NginxMemo.content': typeof import('./src/tools/nginx-memo/nginx-memo.content.md')['default']
|
||||||
NH1: typeof import('naive-ui')['NH1']
|
NH1: typeof import('naive-ui')['NH1']
|
||||||
NH3: typeof import('naive-ui')['NH3']
|
NH3: typeof import('naive-ui')['NH3']
|
||||||
NIcon: typeof import('naive-ui')['NIcon']
|
NIcon: typeof import('naive-ui')['NIcon']
|
||||||
NInput: typeof import('naive-ui')['NInput']
|
|
||||||
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||||
NLayout: typeof import('naive-ui')['NLayout']
|
NLayout: typeof import('naive-ui')['NLayout']
|
||||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||||
NMenu: typeof import('naive-ui')['NMenu']
|
NMenu: typeof import('naive-ui')['NMenu']
|
||||||
NModal: typeof import('naive-ui')['NModal']
|
|
||||||
NP: typeof import('naive-ui')['NP']
|
NP: typeof import('naive-ui')['NP']
|
||||||
NRadio: typeof import('naive-ui')['NRadio']
|
|
||||||
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
|
|
||||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
|
||||||
NSpace: typeof import('naive-ui')['NSpace']
|
|
||||||
NTable: typeof import('naive-ui')['NTable']
|
NTable: typeof import('naive-ui')['NTable']
|
||||||
NTag: typeof import('naive-ui')['NTag']
|
|
||||||
NTimePicker: typeof import('naive-ui')['NTimePicker']
|
|
||||||
NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default']
|
NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default']
|
||||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||||
OcrImage: typeof import('./src/tools/ocr-image/ocr-image.vue')['default']
|
OcrImage: typeof import('./src/tools/ocr-image/ocr-image.vue')['default']
|
||||||
@@ -346,6 +337,7 @@ declare module '@vue/runtime-core' {
|
|||||||
PdfLinearize: typeof import('./src/tools/pdf-linearize/pdf-linearize.vue')['default']
|
PdfLinearize: typeof import('./src/tools/pdf-linearize/pdf-linearize.vue')['default']
|
||||||
PdfSignatureChecker: typeof import('./src/tools/pdf-signature-checker/pdf-signature-checker.vue')['default']
|
PdfSignatureChecker: typeof import('./src/tools/pdf-signature-checker/pdf-signature-checker.vue')['default']
|
||||||
PdfSignatureDetails: typeof import('./src/tools/pdf-signature-checker/components/pdf-signature-details.vue')['default']
|
PdfSignatureDetails: typeof import('./src/tools/pdf-signature-checker/components/pdf-signature-details.vue')['default']
|
||||||
|
PdfTextExtractor: typeof import('./src/tools/pdf-text-extractor/pdf-text-extractor.vue')['default']
|
||||||
PdfUnlock: typeof import('./src/tools/pdf-unlock/pdf-unlock.vue')['default']
|
PdfUnlock: typeof import('./src/tools/pdf-unlock/pdf-unlock.vue')['default']
|
||||||
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
|
PercentageCalculator: typeof import('./src/tools/percentage-calculator/percentage-calculator.vue')['default']
|
||||||
PgpEncryption: typeof import('./src/tools/pgp-encryption/pgp-encryption.vue')['default']
|
PgpEncryption: typeof import('./src/tools/pgp-encryption/pgp-encryption.vue')['default']
|
||||||
@@ -443,6 +435,8 @@ declare module '@vue/runtime-core' {
|
|||||||
UuidConverter: typeof import('./src/tools/uuid-converter/uuid-converter.vue')['default']
|
UuidConverter: typeof import('./src/tools/uuid-converter/uuid-converter.vue')['default']
|
||||||
UuidGenerator: typeof import('./src/tools/uuid-generator/uuid-generator.vue')['default']
|
UuidGenerator: typeof import('./src/tools/uuid-generator/uuid-generator.vue')['default']
|
||||||
VatValidator: typeof import('./src/tools/vat-validator/vat-validator.vue')['default']
|
VatValidator: typeof import('./src/tools/vat-validator/vat-validator.vue')['default']
|
||||||
|
VimMemo: typeof import('./src/tools/vim-memo/vim-memo.vue')['default']
|
||||||
|
'VimMemo.content': typeof import('./src/tools/vim-memo/vim-memo.content.md')['default']
|
||||||
VolumeConverter: typeof import('./src/tools/volume-converter/volume-converter.vue')['default']
|
VolumeConverter: typeof import('./src/tools/volume-converter/volume-converter.vue')['default']
|
||||||
WebsocketTester: typeof import('./src/tools/websocket-tester/websocket-tester.vue')['default']
|
WebsocketTester: typeof import('./src/tools/websocket-tester/websocket-tester.vue')['default']
|
||||||
WeekNumberConverter: typeof import('./src/tools/week-number-converter/week-number-converter.vue')['default']
|
WeekNumberConverter: typeof import('./src/tools/week-number-converter/week-number-converter.vue')['default']
|
||||||
|
|||||||
@@ -17,7 +17,23 @@ export function useFlexSearch<Data extends Record<string, any>>({
|
|||||||
data: Data[]
|
data: Data[]
|
||||||
options?: {
|
options?: {
|
||||||
keys: SearchKey[]
|
keys: SearchKey[]
|
||||||
|
/**
|
||||||
|
* Whether to show or not show items with an empty search query. `true` won't show any items, `false` will show all items.
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
filterEmpty?: boolean
|
filterEmpty?: boolean
|
||||||
|
/**
|
||||||
|
* Whether the results should be sorted by similarity score using the Levenshtein distance.
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
shouldSort?: boolean
|
||||||
|
/**
|
||||||
|
* Type of tokenization logic to use (Determines how the search logic will behave).
|
||||||
|
* @default 'forward'
|
||||||
|
* @see {@link https://github.com/nextapps-de/flexsearch?tab=readme-ov-file#tokenizer-partial-match | FlexSearch Tokenizer Documentation}
|
||||||
|
*
|
||||||
|
* Note: The `'tolerant'` tokenizer option mentioned in the documentation doesn't exist anymore in the current version of FlexSearch.
|
||||||
|
*/
|
||||||
tokenize?: 'strict' | 'forward' | 'reverse' | 'full'
|
tokenize?: 'strict' | 'forward' | 'reverse' | 'full'
|
||||||
resolution?: number
|
resolution?: number
|
||||||
optimize?: boolean
|
optimize?: boolean
|
||||||
@@ -26,7 +42,7 @@ export function useFlexSearch<Data extends Record<string, any>>({
|
|||||||
limit?: MaybeRef<number>
|
limit?: MaybeRef<number>
|
||||||
}) {
|
}) {
|
||||||
// Extract options
|
// Extract options
|
||||||
const { keys, filterEmpty = true, tokenize = 'forward', ...indexOptions } = options;
|
const { keys, filterEmpty = true, shouldSort = true, tokenize = 'forward', ...indexOptions } = options;
|
||||||
|
|
||||||
// Normalize keys to include weights
|
// Normalize keys to include weights
|
||||||
const normalizedKeys = keys.map((key) => {
|
const normalizedKeys = keys.map((key) => {
|
||||||
@@ -115,9 +131,75 @@ export function useFlexSearch<Data extends Record<string, any>>({
|
|||||||
// Apply limit and convert back to original items
|
// Apply limit and convert back to original items
|
||||||
const limitedIds = searchLimit > 0 ? sortedIds.slice(0, searchLimit) : sortedIds;
|
const limitedIds = searchLimit > 0 ? sortedIds.slice(0, searchLimit) : sortedIds;
|
||||||
|
|
||||||
return limitedIds
|
// Return the limited results early if it shouldn't be sorted by similarity
|
||||||
.map(id => dataMap.value.get(id))
|
if (!shouldSort) {
|
||||||
.filter(Boolean) as Data[];
|
return limitedIds
|
||||||
|
.map(id => dataMap.value.get(id))
|
||||||
|
.filter(Boolean) as Data[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate Levenshtein distance
|
||||||
|
const levenshteinDistance = (str1: string, str2: string): number => {
|
||||||
|
const matrix = Array(str2.length + 1).fill(null).map(() => Array(str1.length + 1).fill(null));
|
||||||
|
|
||||||
|
for (let i = 0; i <= str1.length; i++) {
|
||||||
|
matrix[0][i] = i;
|
||||||
|
}
|
||||||
|
for (let j = 0; j <= str2.length; j++) {
|
||||||
|
matrix[j][0] = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let j = 1; j <= str2.length; j++) {
|
||||||
|
for (let i = 1; i <= str1.length; i++) {
|
||||||
|
const indicator = str1[i - 1] === str2[j - 1] ? 0 : 1;
|
||||||
|
matrix[j][i] = Math.min(
|
||||||
|
matrix[j][i - 1] + 1, // deletion
|
||||||
|
matrix[j - 1][i] + 1, // insertion
|
||||||
|
matrix[j - 1][i - 1] + indicator, // substitution
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matrix[str2.length][str1.length];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calculate similarity score (0-1, where 1 is perfect match)
|
||||||
|
const calculateSimilarity = (str1: string, str2: string): number => {
|
||||||
|
const maxLength = Math.max(str1.length, str2.length);
|
||||||
|
if (maxLength === 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const distance = levenshteinDistance(str1.toLowerCase(), str2.toLowerCase());
|
||||||
|
return 1 - (distance / maxLength);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Sort limited results by similarity score
|
||||||
|
const sortedResults = limitedIds
|
||||||
|
.map((id) => {
|
||||||
|
const item = dataMap.value.get(id);
|
||||||
|
if (!item) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate best similarity score across all searchable fields
|
||||||
|
const similarities = normalizedKeys.map(({ name }) => {
|
||||||
|
const value = name.split('.').reduce((obj, path) => obj?.[path], item);
|
||||||
|
return value ? calculateSimilarity(query, String(value)) : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
const bestSimilarity = Math.max(...similarities);
|
||||||
|
|
||||||
|
return {
|
||||||
|
item,
|
||||||
|
similarity: bestSimilarity,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter(Boolean)
|
||||||
|
.sort((a, b) => b!.similarity - a!.similarity)
|
||||||
|
.map(result => result!.item);
|
||||||
|
|
||||||
|
return sortedResults as Data[];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Computed results
|
// Computed results
|
||||||
|
|||||||
@@ -1,20 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import iesData from './ies-lighting-data.json';
|
import iesData from './ies-lighting-data.json';
|
||||||
import { useFuzzySearch } from '@/composable/fuzzySearch';
|
|
||||||
import useDebouncedRef from '@/composable/debouncedref';
|
import useDebouncedRef from '@/composable/debouncedref';
|
||||||
|
import { useFlexSearch } from '@/composable/flexSearch';
|
||||||
|
|
||||||
const data = iesData.map(i => ({ ...i, all: `${i.industryType} - ${i.industryApplication}` }));
|
const data = iesData;
|
||||||
const searchQuery = useDebouncedRef('', 500);
|
const searchQuery = useDebouncedRef('', 250);
|
||||||
|
|
||||||
const { searchResult } = useFuzzySearch({
|
const { searchResult } = useFlexSearch({
|
||||||
search: searchQuery,
|
search: searchQuery,
|
||||||
data,
|
data,
|
||||||
options: {
|
options: {
|
||||||
keys: ['all'],
|
keys: ['industryType', 'industryApplication', 'footCandlesRange', 'recommendedLighting'],
|
||||||
threshold: 0.2,
|
|
||||||
isCaseSensitive: false,
|
|
||||||
minMatchCharLength: 3,
|
|
||||||
useExtendedSearch: true,
|
|
||||||
filterEmpty: false,
|
filterEmpty: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -25,7 +21,7 @@ const { searchResult } = useFuzzySearch({
|
|||||||
<div flex items-center gap-3>
|
<div flex items-center gap-3>
|
||||||
<c-input-text
|
<c-input-text
|
||||||
v-model:value="searchQuery"
|
v-model:value="searchQuery"
|
||||||
placeholder="Search IES recommandation by industry or application"
|
placeholder="Search IES recommendation by industry or application"
|
||||||
mx-auto max-w-600px
|
mx-auto max-w-600px
|
||||||
>
|
>
|
||||||
<template #prefix>
|
<template #prefix>
|
||||||
@@ -64,16 +60,16 @@ const { searchResult } = useFuzzySearch({
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="(result, ix) in searchResult" :key="ix">
|
<tr v-for="(result, ix) in searchResult" :key="ix">
|
||||||
<td>
|
<td>
|
||||||
<input-copyable :value="result.industryType" />
|
<input-copyable :readonly="true" :value="result.industryType" />
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input-copyable :value="result.industryApplication" />
|
<input-copyable :readonly="true" :value="result.industryApplication" />
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input-copyable :value="result.footCandlesRange" />
|
<input-copyable :readonly="true" :value="result.footCandlesRange" />
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input-copyable :value="result.recommendedLighting" />
|
<input-copyable :readonly="true" :value="result.recommendedLighting" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in new issue
Block a user