Tab (Search Engine) (Deprecated)
Tab (Search Engine) (Deprecated)
|
|
Headless v1 has been deprecated. We recommend using the latest version of the Coveo Headless library. |
Example implementation
tab.fn.tsx
import {Tab as HeadlessTab} from '@coveo/headless';
import {useEffect, useState, FunctionComponent, PropsWithChildren} from 'react';
interface TabProps extends PropsWithChildren {
controller: HeadlessTab;
}
export const Tab: FunctionComponent<TabProps> = (props) => {
const {controller} = props;
const [state, setState] = useState(controller.state);
useEffect(() => controller.subscribe(() => setState(controller.state)), []);
return (
<button disabled={state.isActive} onClick={() => controller.select()}>
{props.children}
</button>
);
};
/* Usage
const messageExpression = buildQueryExpression()
.addStringField({
field: 'objecttype',
operator: 'isExactly',
values: ['Message'],
})
.toQuerySyntax();
const controller = buildTab(engine, {
initialState: {isActive: true},
options: {
id: 'messages',
expression: messageExpression,
},
});
<Tab controller={controller}>Messages</Tab>;
*/
The Tab headless controller offers a high-level interface for designing a common tab UI controller.
Methods
select
Activates the tab.
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
The state of the Tab controller.
Properties
-
isActive:
booleanIndicates whether the current tab is selected.
Initialize
buildTab
Creates a Tab controller instance.
Parameters
-
engine:
SearchEngineThe headless engine.
-
props:
TabPropsThe configurable
Tabproperties.
Returns Tab
TabProps
The configurable Tab properties.
Properties
-
options:
TabOptionsThe options for the
Tabcontroller. -
initialState?:
TabInitialStateThe initial state that should be applied to this
Tabcontroller.
TabOptions
The options for the Tab controller.
Properties
-
expression:
stringA constant query expression or filter that the Tab should add to any outgoing query.
Example:
@objecttype==Message -
id:
stringA unique identifier for the tab. The value will be used as the originLevel2 when the tab is active.
TabInitialState
The initial state that should be applied to this Tab controller.
Properties
-
isActive:
booleanSpecifies if the tab is currently selected. Note that there can be only one active tab for a given headless engine.
Utils
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.
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