mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 22:59:14 +00:00
Node library search filters (#636)
* Add search filters to node library * Fix * Dont close on add * Fix wildcard --------- Co-authored-by: Chenlei Hu <chenlei.hu@mail.utoronto.ca>
This commit is contained in:
@@ -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[]
|
||||
@@ -145,13 +149,19 @@ export abstract class NodeFilter<FilterOptionT = string> {
|
||||
|
||||
public abstract getNodeOptions(node: ComfyNodeDefImpl): FilterOptionT[]
|
||||
|
||||
public matches(node: ComfyNodeDefImpl, value: FilterOptionT): boolean {
|
||||
if (value === '*') {
|
||||
public matches(
|
||||
node: ComfyNodeDefImpl,
|
||||
value: FilterOptionT,
|
||||
extraOptions?: ExtraSearchOptions
|
||||
): boolean {
|
||||
const matchWildcards = extraOptions?.matchWildcards !== false
|
||||
if (matchWildcards && value === '*') {
|
||||
return true
|
||||
}
|
||||
const options = this.getNodeOptions(node)
|
||||
return (
|
||||
options.includes(value) || _.some(options, (option) => option === '*')
|
||||
options.includes(value) ||
|
||||
(matchWildcards && _.some(options, (option) => option === '*'))
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -242,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)
|
||||
return filter.matches(node, value, extraOptions)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user