From 507a73e74c2551e9e3d9829a148a884d7d6203b3 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 14 Nov 2021 20:49:52 +0000 Subject: [PATCH] feat: use flexsearch for all local searches (#997) Co-authored-by: kolaente Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/997 Reviewed-by: dpschen Co-authored-by: konrad Co-committed-by: konrad --- package.json | 4 +- src/components/namespace/namespace-search.vue | 10 +--- .../quick-actions/quick-actions.vue | 32 +++++------- src/components/tasks/partials/listSearch.vue | 18 ++----- src/helpers/labels.test.ts | 29 ++++++----- src/helpers/labels.ts | 25 ++++----- src/indexes/index.ts | 52 +++++++++++++++++++ src/store/modules/labels.js | 6 +++ src/store/modules/lists.js | 21 ++++++-- src/store/modules/namespaces.js | 30 ++++++++--- yarn.lock | 10 ++++ 11 files changed, 157 insertions(+), 80 deletions(-) create mode 100644 src/indexes/index.ts diff --git a/package.json b/package.json index 2014aafb..b229b50b 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "dompurify": "2.3.3", "easymde": "2.15.0", "flatpickr": "4.6.9", + "flexsearch": "^0.7.21", "highlight.js": "11.3.1", "is-touch-device": "1.0.1", "lodash.clonedeep": "4.5.0", @@ -54,6 +55,7 @@ "@fortawesome/free-regular-svg-icons": "5.15.4", "@fortawesome/free-solid-svg-icons": "5.15.4", "@fortawesome/vue-fontawesome": "3.0.0-5", + "@types/flexsearch": "^0.7.2", "@types/jest": "27.0.2", "@typescript-eslint/eslint-plugin": "5.3.1", "@typescript-eslint/parser": "5.3.1", @@ -81,8 +83,8 @@ "typescript": "4.4.4", "vite": "2.6.14", "vite-plugin-pwa": "0.11.5", - "vue-tsc": "0.29.4", "vite-svg-loader": "3.1.0", + "vue-tsc": "0.29.4", "wait-on": "6.0.0", "workbox-cli": "6.3.0" }, diff --git a/src/components/namespace/namespace-search.vue b/src/components/namespace/namespace-search.vue index cbe424d2..875583af 100644 --- a/src/components/namespace/namespace-search.vue +++ b/src/components/namespace/namespace-search.vue @@ -25,15 +25,7 @@ export default { }, computed: { namespaces() { - if (this.query === '') { - return [] - } - - return this.$store.state.namespaces.namespaces.filter(n => { - return !n.isArchived && - n.id > 0 && - n.title.toLowerCase().includes(this.query.toLowerCase()) - }) + return this.$store.getters['namespaces/searchNamespace'](this.query) }, }, methods: { diff --git a/src/components/quick-actions/quick-actions.vue b/src/components/quick-actions/quick-actions.vue index 16a5a034..3e8c38d1 100644 --- a/src/components/quick-actions/quick-actions.vue +++ b/src/components/quick-actions/quick-actions.vue @@ -110,40 +110,32 @@ export default { results() { let lists = [] if (this.searchMode === SEARCH_MODE_ALL || this.searchMode === SEARCH_MODE_LISTS) { - const ncache = {} - - const history = getHistory() - // Puts recently visited lists at the top - const allLists = [...new Set([ - ...history.map(l => { - return this.$store.getters['lists/getListById'](l.id) - }), - ...Object.values(this.$store.state.lists)])] - const {list} = this.parsedQuery if (list === null) { lists = [] } else { + const ncache = {} + const history = getHistory() + // Puts recently visited lists at the top + const allLists = [...new Set([ + ...history.map(l => { + return this.$store.getters['lists/getListById'](l.id) + }), + ...this.$store.getters['lists/searchList'](list), + ])] + lists = allLists.filter(l => { if (typeof l === 'undefined' || l === null) { return false } - if (l.isArchived) { - return false - } - if (typeof ncache[l.namespaceId] === 'undefined') { ncache[l.namespaceId] = this.$store.getters['namespaces/getNamespaceById'](l.namespaceId) } - if (ncache[l.namespaceId].isArchived) { - return false - } - - return l.title.toLowerCase().includes(list.toLowerCase()) - }) ?? [] + return !ncache[l.namespaceId].isArchived + }) } } diff --git a/src/components/tasks/partials/listSearch.vue b/src/components/tasks/partials/listSearch.vue index ea642f1f..e05d52f8 100644 --- a/src/components/tasks/partials/listSearch.vue +++ b/src/components/tasks/partials/listSearch.vue @@ -1,7 +1,6 @@