Skip to content

Fix sorting on type filter + empty query #880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/components/searchbox/NodeSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
7 changes: 3 additions & 4 deletions src/services/nodeSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ export class FuseSearch<T> {
}

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)
}
Expand Down
6 changes: 5 additions & 1 deletion tests-ui/tests/nodeSearchService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading