StaticFilter (Deprecated)
StaticFilter (Deprecated)
Example Implementation
static-filter.fn.tsx
import {useEffect, useState, FunctionComponent, useContext} from 'react';
import {StaticFilterOptions, buildStaticFilter} from '@coveo/headless';
import {AppContext} from '../../context/engine';
export const StaticFilter: FunctionComponent<StaticFilterOptions> = (props) => {
const {engine} = useContext(AppContext);
const controller = buildStaticFilter(engine!, {options: props});
const [state, setState] = useState(controller.state);
useEffect(() => controller.subscribe(() => setState(controller.state)), []);
return (
<ul>
{state.values.map((value) => {
return (
<li key={value.caption}>
<input
type="checkbox"
checked={controller.isValueSelected(value)}
onChange={() => controller.toggleSelect(value)}
/>
<span>{value.caption}</span>
</li>
);
})}
</ul>
);
};
/* Usage
const youtubeExpression = buildQueryExpression()
.addStringField({
field: 'filetype',
operator: 'isExactly',
values: ['youtubevideo'],
})
.toQuerySyntax();
const dropboxExpression = buildQueryExpression()
.addStringField({
field: 'connectortype',
operator: 'isExactly',
values: ['DropboxCrawler'],
})
.addStringField({
field: 'objecttype',
operator: 'isExactly',
values: ['File'],
})
.toQuerySyntax();
const youtube = buildStaticFilterValue({
caption: 'Youtube',
expression: youtubeExpression,
})
const dropbox = buildStaticFilterValue({
caption: 'Dropbox',
expression: dropboxExpression,
})
<StaticFilter id="fileType" values={[youtube, dropbox]}/>;
*/
The StaticFilter
controller manages a collection of filter values.
Methods
deselectAll
Deselects all static filter values.
isValueSelected
Checks whether the specified static filter value is selected.
Parameters
-
value:
StaticFilterValue
The static filter value to check.
Returns boolean
: Whether the specified static filter value is selected.
toggleSelect
Toggles the specified static filter value.
Parameters
-
value:
StaticFilterValue
The static filter value to toggle.
toggleSingleSelect
Toggles the specified static filter value, deselecting others.
Parameters
-
value:
StaticFilterValue
The static filter value to toggle.
subscribe
Adds a callback that’s invoked on state change.
Parameters
-
listener:
() => void
A callback that’s invoked on state change.
Returns Unsubscribe
: A function to remove the listener.
Attributes
state
A state of the StaticFilter
controller.
Properties
-
hasActiveValues:
boolean
true
if there’s at least one non-idle value andfalse
otherwise. -
id:
string
The static filter id.
-
values:
StaticFilterValue[]
The static filter values.
Initialize
buildStaticFilter
Creates a Static Filter
controller instance.
Parameters
-
engine:
SearchEngine
The headless engine.
-
props:
StaticFilterProps
The configurable
Sort
controller properties.
Returns StaticFilter
StaticFilterProps
The configurable Sort
controller properties.
Properties
-
options:
StaticFilterOptions
The options for the
StaticFilter
controller.
StaticFilterOptions
The options for the StaticFilter
controller.
Properties
-
id:
string
A unique identifier for the static filter.
-
values:
StaticFilterValue[]
The values the static filter is responsible for managing.
Utils
buildStaticFilterValue
Creates a StaticFilterValue
.
Parameters
-
config:
StaticFilterValueOptions
The options with which to create a
StaticFilterValue
.
Returns StaticFilterValue
buildQueryExpression
Creates an QueryExpression
instance.
Returns QueryExpression
: A utility to help build query expressions.
Related Types
DateFieldExpression
Properties
-
field:
string
The field name.
-
operator:
NumericOperator
The operator to use when comparing
field
andvalue
. Options for the operator are:"isExactly" | "lowerThan" | "lowerThanOrEqual" | "greaterThan" | "greaterThanOrEqual"
. -
value:
string
The value to match against the field. For absolute dates, please use form YYYY/MM/DD. For relative dates, please refer to the supported date/time operators.
-
negate?:
boolean
If
true
, the inverse expression will be created.
DateRangeFieldExpression
Properties
-
field:
string
The field name.
-
from:
string
The start of the range. For absolute dates, please use form YYYY/MM/DD. For relative dates, please refer to the supported date/time operators.
-
to:
string
The end of the range. For absolute dates, please use form YYYY/MM/DD. For relative dates, please refer to the supported date/time operators.
-
negate?:
boolean
If
true
, the inverse expression will be created.
ExactMatchExpression
Properties
-
expression:
string
An expression that must appear in its entirety at least once for an item to be returned.
For example, specifying
Star Wars
will only return items containing the exact phrase. -
negate?:
boolean
If
true
, the inverse expression will be created.
FieldExistsExpression
Properties
-
field:
string
The field that should be defined on all matching items.
-
negate?:
boolean
If
true
, the inverse expression will be created.
KeywordExpression
Properties
-
expression:
string
An expression containing terms to match. Terms can be in any order, and may also be expanded with stemming.
For example, specifying
Star Wars
will return items containing eitherStar
orWars
or both. -
negate?:
boolean
If
true
, the inverse expression will be created.
NearExpression
Properties
-
otherTerms:
OtherTerm[]
The other terms to check against the reference term. See NEAR for an example.
-
startTerm:
string
The reference term.
-
negate?:
boolean
If
true
, the inverse expression will be created.
NumericFieldExpression
Properties
-
field:
string
The field name.
-
operator:
NumericOperator
The operator to use when comparing
field
andvalue
. -
value:
number
The value to match against the field.
-
negate?:
boolean
If
true
, the inverse expression will be created.
NumericRangeFieldExpression
Properties
-
field:
string
The field name.
-
from:
number
The start of the range.
-
to:
number
The end of the range.
-
negate?:
boolean
If
true
, the inverse expression will be created.
OtherTerm
Properties
-
endTerm:
string
The term to check against the reference term.
-
maxKeywordsBetween:
number
The maximum number of keywords that should exist between the current term and the reference term.
QueryExpression
Properties
-
addDateField
: functionAdds an expression that uses an
operator
to compare a datefield
to avalue
. Returns all of the items for which the expression evaluates to true.Parameters
-
expression:
DateFieldExpression
A date field expression.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
addDateRangeField
: functionAdds an expression that returns all items for which the
value
of the datefield
is within the defined range.Parameters
-
expression:
DateRangeFieldExpression
A numeric field expression.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
addExactMatch
: functionAdds an expression that must appear in its entirety, at least once, for an item to be returned.
Parameters
-
expression:
ExactMatchExpression
An exact match expression.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
addExpression
: functionAdds a
QueryExpression
to the current instance.Parameters
-
expression:
QueryExpression
The query expression instance to add.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
addFieldExists
: functionAdds an expression returning all items where the defined field exists.
Parameters
-
expression:
FieldExistsExpression
A field exists expressions.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
addKeyword
: functionAdds an expression containing terms to match. Terms can be in any order, and may also be expanded with stemming.
Parameters
-
expression:
KeywordExpression
A keyword expression.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
addNear
: functionAdds an expression that returns all of the items in which the specified
startTerm
appears no more thanmaxKeywordsBetween
from the endTerm, for each element inotherTerms
.Parameters
-
expression:
NearExpression
A near expression.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
addNumericField
: functionAdds an expression that uses an
operator
to compare a numericfield
to avalue
. Returns all of the items for which the expression evaluates to true.Parameters
-
expression:
NumericFieldExpression
A numeric field expression.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
addNumericRangeField
: functionAdds an expression that returns all items for which the
value
of the numericfield
is within the defined range.Parameters
-
expression:
NumericRangeFieldExpression
A numeric field expression.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
addQueryExtension
: functionAdds an expression that invokes a query extension.
Parameters
-
expression:
QueryExtensionExpression
A query extension expression.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
addStringFacetField
: functionAdds an expression that uses an
operator
to compare a string facetfield
to avalue
. Returns all of the items for which the expression evaluates to true.Parameters
-
expression:
StringFacetFieldExpression
A string facet field expression.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
addStringField
: functionAdds an expression that uses an
operator
to compare a stringfield
against certainvalues
. Returns all of the items for which the expression evaluates to true.Parameters
-
expression:
StringFieldExpression
A string field expression.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
joinUsing
: functionAllows specifying a boolean operator join expressions with. Possible values are
and
andor
.Parameters
-
operator:
BooleanOperator
The boolean operator to join individual expressions with.
Returns
QueryExpression
: TheQueryExpression
instance.
-
-
toQuerySyntax
: functionJoins all expressions using the configured boolean operator.
Returns
string
: A string representation of the configured expressions.
QueryExtensionExpression
Properties
-
name:
string
The query extension name without the leading $ sign. See Standard query extensions for examples.
-
parameters:
QueryExtensionParameters
The query extension parameters where applicable.
StaticFilterValue
Properties
-
caption:
string
A human-readable caption for the expression (for example,
Youtube
). -
expression:
string
The query filter expression to apply when the value is selected (for example,
@filetype=="youtubevideo"
). -
state:
'idle' | 'selected'
The state of the static filter value.
StaticFilterValueOptions
Properties
-
caption:
string
A human-readable caption for the expression (for example,
Youtube
). -
expression:
string
The query filter expression to apply when the value is selected (for example,
@filetype=="youtubevideo"
). -
state?:
'idle' | 'selected'
The state of the static filter value.
StringFacetFieldExpression
Properties
-
field:
string
The field name.
-
operator:
StringFacetFieldOperator
The operator to use when comparing
field
andvalue
. -
value:
string
The value to match against the field.
-
negate?:
boolean
If
true
, the inverse expression will be created.
StringFieldExpression
Properties
-
field:
string
The field name.
-
operator:
StringOperator
The operator to use when comparing
field
andvalues
. -
values:
string[]
The values to match against the field.
-
negate?:
boolean
If
true
, the inverse expression will be created.
Unsubscribe
Call signatures
-
(): void