From 63302a663470e1c6a8946ebbf097e4f2400ab83e Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Thu, 19 Sep 2024 11:22:23 +0900 Subject: [PATCH] Fix sorting on type filter + empty query (#880) * Fix sorting on type filter + empty query * nit * nit --- src/components/searchbox/NodeSearchBox.vue | 16 ++++++++-------- src/services/nodeSearchService.ts | 7 +++---- tests-ui/tests/nodeSearchService.test.ts | 6 +++++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/components/searchbox/NodeSearchBox.vue b/src/components/searchbox/NodeSearchBox.vue index 772a32f0d..cedf0d429 100644 --- a/src/components/searchbox/NodeSearchBox.vue +++ b/src/components/searchbox/NodeSearchBox.vue @@ -106,15 +106,15 @@ const placeholder = computed(() => { const nodeDefStore = useNodeDefStore() const nodeFrequencyStore = useNodeFrequencyStore() const search = (query: string) => { + const queryIsEmpty = query === '' && props.filters.length === 0 currentQuery.value = query - suggestions.value = - query === '' - ? nodeFrequencyStore.topNodeDefs - : [ - ...nodeDefStore.nodeSearchService.searchNode(query, props.filters, { - limit: props.searchLimit - }) - ] + suggestions.value = queryIsEmpty + ? nodeFrequencyStore.topNodeDefs + : [ + ...nodeDefStore.nodeSearchService.searchNode(query, props.filters, { + limit: props.searchLimit + }) + ] } const emit = defineEmits(['addFilter', 'removeFilter', 'addNode']) diff --git a/src/services/nodeSearchService.ts b/src/services/nodeSearchService.ts index af82b6b50..da1951156 100644 --- a/src/services/nodeSearchService.ts +++ b/src/services/nodeSearchService.ts @@ -32,11 +32,10 @@ export class FuseSearch { } public search(query: string, options?: FuseSearchOptions): T[] { - if (!query || query === '') { - return [...this.data] - } + const fuseResult = !query + ? this.data.map((x) => ({ item: x, score: 0 })) + : this.fuse.search(query, options) - const fuseResult = this.fuse.search(query, options) if (!this.advancedScoring) { return fuseResult.map((x) => x.item) } diff --git a/tests-ui/tests/nodeSearchService.test.ts b/tests-ui/tests/nodeSearchService.test.ts index 14c689650..fea642ac9 100644 --- a/tests-ui/tests/nodeSearchService.test.ts +++ b/tests-ui/tests/nodeSearchService.test.ts @@ -51,7 +51,11 @@ const EXAMPLE_NODE_DEFS: ComfyNodeDefImpl[] = [ category: 'latent/batch', output_node: false } -].map((nodeDef) => plainToClass(ComfyNodeDefImpl, nodeDef)) +].map((nodeDef) => { + const def = plainToClass(ComfyNodeDefImpl, nodeDef) + def['postProcessSearchScores'] = (s) => s + return def +}) describe('nodeSearchService', () => { it('searches with input filter', () => {