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:
Name | Type | Default | Description |
---|---|---|---|
name | string | The name of the filter. This should be unique. | |
group | string | A group name, for grouping multiple filters together using ARRAY_MATCH . | |
field | string | A field in schema, used if count = true . | |
options | Record<string, string \| () => string> | Dictionary of name -> filter pairs. | |
initial | string | string[] | List of initially selected items. | |
count | boolean | true if no options specified. | Map to a field which aims to perform a count aggregate. |
array | boolean | Whether the response of the field is an array. This setting is only applicable if count is set. | |
multi | boolean | Multiple 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.
Name | Description |
---|---|
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(emitEvent?: boolean) | Reset the current filter to the initial one and optionally emit an event. |
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. |
hasChanged() | Returns a boolean to indicate if the filter's current value differs from the initial value. |