React SDK

FilterBuilder

The FilterBuilder class is used to construct filters for use with the relevant SearchProvider. They can later be referenced by the useFilter hook or Filter component.

Usage

Constructor

The constructor accepts a single object with the following properties:

NameTypeDefaultDescription
namestringThe name of the filter. This should be unique.
groupstringA group name, for grouping multiple filters together using ARRAY_MATCH.
fieldstringA field in schema, used if count = true.
optionsRecord<string, string \| () => string>Dictionary of name -> filter pairs.
initialstring | string[]List of initially selected items.
countbooleantrue if no options specified.Map to a field which aims to perform a count aggregate.
arraybooleanWhether the response of the field is an array. This setting is only applicable if count is set.
multibooleanMultiple selections allowed.
joinOperator'OR' | 'AND''OR'Join operator used if multi = true.

Properties

For more advanced implementations, you may want to access properties on the FilterBuilder instance.

NameDescription
listen(event: string, callback: (filter: FilterBuilder) => void)Register a listener for a specific event.
set(values: string[], merge: boolean = false)Set the state of the filter and optionally merge current values.
reset()Reset the current filter to the initial one.
remove(values: string[])Remove a list of values from the current state.
isSet(name: string)Returns whether the filter is set or not.
setOptions(options: Options, merge: boolean = false)Set or merge filter options.
filter()Builds up the filter string from the current filter and it's children.
getBuckets()Get the bucket definitions for the filter.
getName()Returns the name property of the filter.
getGroup()Returns the group property of the filter.
getField()Returns the field property of the filter.
getCount()Returns the count property of the filter.
getOptions()Returns the current options property of the filter.
get()Returns the current selected options of the filter.
isArray()Returns the array property of the filter.
isMulti()Returns the multi property of the filter.

Listen example