Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
feat: optimize search logic
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 24, 2023
1 parent f5f8b04 commit 4121f71
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 36 deletions.
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false"
},
"devDependencies": {
"@algorithm.ts/lcs": "^3.1.1",
"@hpcc-js/wasm": "^2.13.1",
"@tsconfig/node18": "^18.2.0",
"@types/node": "^18.17.0",
Expand Down
32 changes: 21 additions & 11 deletions packages/client/src/components/task/SingleNavigateEdit.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { findLengthOfLCS } from '@algorithm.ts/lcs'
import {
AdsClickOutlined,
ErrorOutlineOutlined,
Expand Down Expand Up @@ -38,18 +39,27 @@ const navTask = computed(() => {
})
const options = computed(() => {
const lowerSearch = value.value.toLowerCase()
const low = value.value.toLowerCase()
return Object.keys(taskIndex.value)
.map(name => ({
name,
type: name.toLowerCase().startsWith(lowerSearch)
? 0
: name.toLowerCase().indexOf(lowerSearch) !== -1
? 1
: 2
}))
.filter(({ type }) => type < 2)
.sort((a, b) => a.type - b.type)
.map(name => {
const lowName = name.toLowerCase()
return {
name,
point: findLengthOfLCS(
low.length,
lowName.length,
(i, j) => low[i] === lowName[j]
)
}
})
.sort((a, b) => {
if (a.point !== b.point) {
return b.point - a.point
} else {
return a.name.localeCompare(b.name)
}
})
.slice(0, 20)
.map(x => ({
label: x.name,
value: x.name
Expand Down
36 changes: 21 additions & 15 deletions packages/client/src/components/task/SingleTemplateEdit.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { findLengthOfLCS } from '@algorithm.ts/lcs'
import { useVModel } from '@vueuse/core'
import { NAutoComplete } from 'naive-ui'
import { computed } from 'vue'
Expand All @@ -18,22 +19,27 @@ const value = useVModel(props, 'value', emits, {
})
const options = computed(() => {
const lowerSearch = value.value
.toLowerCase()
.split(/[ /]+/)
.filter(x => x)
if (lowerSearch.length === 0) {
return []
}
const low = value.value.toLowerCase()
return Object.keys(imageIndex.value)
.map(name => ({
name,
type: lowerSearch
.map(key => (name.toLowerCase().indexOf(key) !== -1 ? 0 : 1) as number)
.reduce((a, b) => a + b, 0)
}))
.filter(({ type }) => type < 2)
.sort((a, b) => a.type - b.type)
.map(name => {
const lowName = name.toLowerCase()
return {
name,
point: findLengthOfLCS(
low.length,
lowName.length,
(i, j) => low[i] === lowName[j]
)
}
})
.sort((a, b) => {
if (a.point !== b.point) {
return b.point - a.point
} else {
return a.name.localeCompare(b.name)
}
})
.slice(0, 20)
.map(x => ({
label: x.name,
value: x.name
Expand Down
10 changes: 0 additions & 10 deletions packages/client/src/wasm.d.ts

This file was deleted.

0 comments on commit 4121f71

Please sign in to comment.