Skip to content

Commit

Permalink
Fix wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
pythongosssss committed Aug 27, 2024
1 parent 2c305e4 commit 7dc25c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
14 changes: 10 additions & 4 deletions src/components/sidebar/tabs/NodeLibrarySidebarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,16 @@ const handleSearch = (query: string) => {
}
const f = filters.value.map((f) => f.filter as FilterAndValue<string>)
const matchedNodes = nodeDefStore.nodeSearchService.searchNode(query, f, {
limit: 64,
supportWildcard: false
})
const matchedNodes = nodeDefStore.nodeSearchService.searchNode(
query,
f,
{
limit: 64
},
{
matchWildcards: false
}
)
filteredRoot.value = buildNodeDefTree(matchedNodes)
expandNode(filteredRoot.value)
Expand Down
17 changes: 11 additions & 6 deletions src/services/nodeSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import _ from 'lodash'

type SearchAuxScore = [number, number, number, number]

interface ExtraSearchOptions {
matchWildcards?: boolean
}

export class FuseSearch<T> {
private fuse: Fuse<T>
private readonly keys: string[]
Expand Down Expand Up @@ -148,16 +152,16 @@ export abstract class NodeFilter<FilterOptionT = string> {
public matches(
node: ComfyNodeDefImpl,
value: FilterOptionT,
searchOptions?: FuseSearchOptions
extraOptions?: ExtraSearchOptions
): boolean {
const checkWildcard = searchOptions?.supportWildcard !== false
if (checkWildcard && value === '*') {
const matchWildcards = extraOptions?.matchWildcards !== false
if (matchWildcards && value === '*') {
return true
}
const options = this.getNodeOptions(node)
return (
options.includes(value) ||
(checkWildcard && _.some(options, (option) => option === '*'))
(matchWildcards && _.some(options, (option) => option === '*'))
)
}
}
Expand Down Expand Up @@ -248,14 +252,15 @@ export class NodeSearchService {
public searchNode(
query: string,
filters: FilterAndValue<string>[] = [],
options?: FuseSearchOptions
options?: FuseSearchOptions,
extraOptions?: ExtraSearchOptions
): ComfyNodeDefImpl[] {
const matchedNodes = this.nodeFuseSearch.search(query)

const results = matchedNodes.filter((node) => {
return _.every(filters, (filterAndValue) => {
const [filter, value] = filterAndValue
return filter.matches(node, value, options)
return filter.matches(node, value, extraOptions)
})
})

Expand Down

0 comments on commit 7dc25c9

Please sign in to comment.