StaticFilter (Deprecated)
StaticFilter (Deprecated)
|
|
Headless v1 has been deprecated. We recommend using the latest version of the Coveo Headless library. |
Example implementation
static-filter.fn.tsx
import {StaticFilterOptions, buildStaticFilter} from '@coveo/headless';
import {useEffect, useState, FunctionComponent, useContext} from 'react';
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:
StaticFilterValueThe static filter value to check.
Returns boolean: Whether the specified static filter value is selected.
toggleSelect
Toggles the specified static filter value.
Parameters
-
value:
StaticFilterValueThe static filter value to toggle.
toggleSingleSelect
Toggles the specified static filter value, deselecting others.
Parameters
-
value:
StaticFilterValueThe static filter value to toggle.
subscribe
Adds a callback that’s invoked on state change.
Parameters
-
listener:
() => voidA 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:
booleantrueif there’s at least one non-idle value andfalseotherwise. -
id:
stringThe static filter id.
-
values:
StaticFilterValue[]The static filter values.
Initialize
buildStaticFilter
Creates a Static Filter controller instance.
Parameters
-
engine:
SearchEngineThe headless engine.
-
props:
StaticFilterPropsThe configurable
Sortcontroller properties.
Returns StaticFilter
StaticFilterProps
The configurable Sort controller properties.
Properties
-
options:
StaticFilterOptionsThe options for the
StaticFiltercontroller.
StaticFilterOptions
The options for the StaticFilter controller.
Properties
-
id:
stringA unique identifier for the static filter.
-
values:
StaticFilterValue[]The values the static filter is responsible for managing.
Utils
buildStaticFilterValue
Creates a StaticFilterValue.
Parameters
-
config:
StaticFilterValueOptionsThe 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:
stringThe field name.
-
operator:
NumericOperatorThe operator to use when comparing
fieldandvalue. Options for the operator are:"isExactly" | "lowerThan" | "lowerThanOrEqual" | "greaterThan" | "greaterThanOrEqual". -
value:
stringThe 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?:
booleanIf
true, the inverse expression will be created.
DateRangeFieldExpression
Properties
-
field:
stringThe field name.
-
from:
stringThe 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:
stringThe 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?:
booleanIf
true, the inverse expression will be created.
ExactMatchExpression
Properties
-
expression:
stringAn expression that must appear in its entirety at least once for an item to be returned.
For example, specifying
Star Warswill only return items containing the exact phrase. -
negate?:
booleanIf
true, the inverse expression will be created.
FieldExistsExpression
Properties
-
field:
stringThe field that should be defined on all matching items.
-
negate?:
booleanIf
true, the inverse expression will be created.
KeywordExpression
Properties
-
expression:
stringAn expression containing terms to match. Terms can be in any order, and may also be expanded with stemming.
For example, specifying
Star Warswill return items containing eitherStarorWarsor both. -
negate?:
booleanIf
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:
stringThe reference term.
-
negate?:
booleanIf
true, the inverse expression will be created.
NumericFieldExpression
Properties
-
field:
stringThe field name.
-
operator:
NumericOperatorThe operator to use when comparing
fieldandvalue. -
value:
numberThe value to match against the field.
-
negate?:
booleanIf
true, the inverse expression will be created.
NumericRangeFieldExpression
Properties
-
field:
stringThe field name.
-
from:
numberThe start of the range.
-
to:
numberThe end of the range.
-
negate?:
booleanIf
true, the inverse expression will be created.
OtherTerm
Properties
-
endTerm:
stringThe term to check against the reference term.
-
maxKeywordsBetween:
numberThe maximum number of keywords that should exist between the current term and the reference term.
QueryExpression
Properties
-
addDateField: functionAdds an expression that uses an
operatorto compare a datefieldto avalue. Returns all of the items for which the expression evaluates to true.Parameters
-
expression:
DateFieldExpressionA date field expression.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
addDateRangeField: functionAdds an expression that returns all items for which the
valueof the datefieldis within the defined range.Parameters
-
expression:
DateRangeFieldExpressionA numeric field expression.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
addExactMatch: functionAdds an expression that must appear in its entirety, at least once, for an item to be returned.
Parameters
-
expression:
ExactMatchExpressionAn exact match expression.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
addExpression: functionAdds a
QueryExpressionto the current instance.Parameters
-
expression:
QueryExpressionThe query expression instance to add.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
addFieldExists: functionAdds an expression returning all items where the defined field exists.
Parameters
-
expression:
FieldExistsExpressionA field exists expressions.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
addKeyword: functionAdds an expression containing terms to match. Terms can be in any order, and may also be expanded with stemming.
Parameters
-
expression:
KeywordExpressionA keyword expression.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
addNear: functionAdds an expression that returns all of the items in which the specified
startTermappears no more thanmaxKeywordsBetweenfrom the endTerm, for each element inotherTerms.Parameters
-
expression:
NearExpressionA near expression.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
addNumericField: functionAdds an expression that uses an
operatorto compare a numericfieldto avalue. Returns all of the items for which the expression evaluates to true.Parameters
-
expression:
NumericFieldExpressionA numeric field expression.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
addNumericRangeField: functionAdds an expression that returns all items for which the
valueof the numericfieldis within the defined range.Parameters
-
expression:
NumericRangeFieldExpressionA numeric field expression.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
addQueryExtension: functionAdds an expression that invokes a query extension.
Parameters
-
expression:
QueryExtensionExpressionA query extension expression.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
addStringFacetField: functionAdds an expression that uses an
operatorto compare a string facetfieldto avalue. Returns all of the items for which the expression evaluates to true.Parameters
-
expression:
StringFacetFieldExpressionA string facet field expression.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
addStringField: functionAdds an expression that uses an
operatorto compare a stringfieldagainst certainvalues. Returns all of the items for which the expression evaluates to true.Parameters
-
expression:
StringFieldExpressionA string field expression.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
joinUsing: functionAllows specifying a boolean operator join expressions with. Possible values are
andandor.Parameters
-
operator:
BooleanOperatorThe boolean operator to join individual expressions with.
Returns
QueryExpression: TheQueryExpressioninstance.
-
-
toQuerySyntax: functionJoins all expressions using the configured boolean operator.
Returns
string: A string representation of the configured expressions.
QueryExtensionExpression
Properties
-
name:
stringThe query extension name without the leading $ sign. See Standard query extensions for examples.
-
parameters:
QueryExtensionParametersThe query extension parameters where applicable.
StaticFilterValue
Properties
-
caption:
stringA human-readable caption for the expression (for example,
Youtube). -
expression:
stringThe 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:
stringA human-readable caption for the expression (for example,
Youtube). -
expression:
stringThe 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:
stringThe field name.
-
operator:
StringFacetFieldOperatorThe operator to use when comparing
fieldandvalue. -
value:
stringThe value to match against the field.
-
negate?:
booleanIf
true, the inverse expression will be created.
StringFieldExpression
Properties
-
field:
stringThe field name.
-
operator:
StringOperatorThe operator to use when comparing
fieldandvalues. -
values:
string[]The values to match against the field.
-
negate?:
booleanIf
true, the inverse expression will be created.
Unsubscribe
Call signatures
-
(): void