Search

This is for:

Developer
Important

The Headless commerce engine, controllers, and actions are in open beta and therefore under active development. Reach out to your Coveo team for support in adopting them.

Methods

executeFirstSearch

Executes the first search.

promoteChildToParent

Finds the specified parent product and the specified child product of that parent, and makes that child the new parent. The children and totalNumberOfChildren properties of the original parent are preserved in the new parent.

This method is useful when leveraging the product grouping feature to allow users to select nested products.

E.g., if a product has children (such as color variations), you can call this method when the user selects a child to make that child the new parent product, and re-render the product as such in the storefront.

Note: In the controller state, a product that has children will always include itself as its own child so that it can be rendered as a nested product, and restored as the parent product through this method as needed.

Parameters

  • childPermanentId: string

    The permanentid of the child product that will become the new parent.

  • parentPermanentId: string

    The permanentid of the current parent product of the child product to promote.

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.

didYouMean

Creates a DidYouMean sub-controller.

Returns DidYouMean: A DidYouMean sub-controller.

Creates a BreadcrumbManager sub-controller.

Returns BreadcrumbManager: A BreadcrumbManager sub-controller.

facetGenerator

Creates a FacetGenerator sub-controller.

Returns FacetGenerator: A FacetGenerator sub-controller.

parameterManager

Creates a ParameterManager sub-controller with the specified properties.

Parameters

Returns ParameterManager<P>: A ParameterManager sub-controller.

sort

Creates a Sort sub-controller.

Parameters

  • props: SortProps

    Optional properties for the Sort sub-controller.

Returns Sort: A Sort sub-controller.

urlManager

Creates a UrlManager sub-controller with the specified properties.

Parameters

Returns UrlManager: A UrlManager sub-controller.

interactiveProduct

Creates an InteractiveProduct sub-controller.

Parameters

  • props: Omit<InteractiveProductCoreProps, 'responseIdSelector'>

    The properties for the InteractiveProduct sub-controller.

Returns InteractiveProduct: An InteractiveProduct sub-controller.

pagination

Creates a Pagination sub-controller.

Parameters

  • props: PaginationProps

    The optional properties for the Pagination sub-controller.

Returns Pagination: A Pagination sub-controller.

Attributes

state

A scoped and simplified part of the headless state that is relevant to the Search controller.

Properties

  • error: CommerceAPIErrorStatusResponse | null

  • isLoading: boolean

  • products: Product[]

  • responseId: string

Initialize

buildSearch

Builds a Search controller for the given commerce engine.

Parameters

  • engine: CommerceEngine

    The commerce engine.

Returns Search

Sub-controllers

DidYouMean

Properties

  • state: DidYouMeanState

    A scoped and simplified part of the headless state that is relevant to the DidYouMean controller.

  • subscribe: function

    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.

FacetGenerator

Properties

  • facets: GeneratedFacetControllers

    The facet sub-controllers created by the facet generator.

  • state: string[]

    The ordered list of facet IDs for which sub-controllers will be created and returned when the facets getter is called.

  • subscribe: function

    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.

Pagination

Properties

  • state: PaginationState

    A scoped and simplified part of the headless state that is relevant to the Pagination controller.

  • fetchMoreProducts: function

    Fetches the next page of products, and appends them to the current list of products.

  • nextPage: function

    Navigates to the next page.

  • previousPage: function

    Navigates to the previous page.

  • selectPage: function

    Navigates to a specific page.

    Parameters

    • page: number

      The page to navigate to.

  • setPageSize: function

    Sets the page size.

    Parameters

    • pageSize: number

      The page size.

  • subscribe: function

    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.

ParameterManager<P>

Properties

  • state: ParameterManagerState<T>

    The state relevant to the ParameterManager controller.

  • synchronize: function

    Updates the parameters in the state with the specified parameters and fetches results. Unspecified keys are reset to their initial values.

    Parameters

    • parameters: T

      The parameters to synchronize.

  • subscribe: function

    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.

Sort

Properties

  • state: SortState

    A scoped and simplified part of the headless state that is relevant to the Sort controller.

  • isAvailable: function

    Verifies whether the specified sort criterion is available.

    Parameters

    • criterion: SortByRelevance | SortByFields

      The sort criterion to look for.

      Returns boolean: true if the specified sort criterion is available; false otherwise.

  • isSortedBy: function

    Verifies whether the specified sort criterion is the currently active one.

    Parameters

    • criterion: SortByRelevance | SortByFields

      The sort criterion to evaluate.

      Returns boolean: true if the specified sort criterion is the currently active one; false otherwise.

  • sortBy: function

    Updates the sort criterion and executes a new query.

    Parameters

    • criterion: SortByRelevance | SortByFields

      The new sort criterion.

  • subscribe: function

    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.

UrlManager

Properties

  • state: UrlManagerState

    The state relevant to the UrlManager controller.

  • synchronize: function

    Updates the search parameters in state with those from the url & launches a search.

    Parameters

    • fragment: string

      The part of the url that contains search parameters. E.g., q=windmill&f[author]=Cervantes

  • subscribe: function

    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.

DidYouMeanState

Properties

  • hasQueryCorrection: boolean

    Specifies if there is a query correction to apply.

  • originalQuery: string

    The original query that was performed, without any automatic correction applied.

  • queryCorrection: QueryCorrection

    The query correction that is currently applied by the "did you mean" module.

  • wasAutomaticallyCorrected: boolean

    Specifies if the query was automatically corrected by Headless.

    This happens when there is no result returned by the API for a particular misspelling.

  • wasCorrectedTo: string

    The correction that was applied to the query. If no correction was applied, will default to an empty string.

InteractiveProduct

Properties

  • beginDelayedSelect: function

    Prepares to select the result after a certain delay, sending analytics if it was never selected before.

In a DOM context, it’s recommended to call this method on the touchstart event.

  • cancelPendingSelect: function

    Cancels the pending selection caused by beginDelayedSelect.

In a DOM context, it’s recommended to call this method on the touchend event.

  • select: function

    Selects the result, logging a UA event to the Coveo Platform if the result wasn’t selected before.

In a DOM context, it’s recommended to call this method on all of the following events: * contextmenu * click * mouseup * mousedown

PaginationProps

Properties

  • options?: Omit<CorePaginationOptions, 'slotId'>

PaginationState

Properties

  • page: number

  • pageSize: number

  • totalEntries: number

  • totalPages: number

ParameterManagerInitialState<T>

Properties

  • parameters: T

    The parameters affecting the response.

ParameterManagerProps<P>

Properties

ParameterManagerState<T>

Properties

  • parameters: T

    The parameters affecting the response.

Product

Properties

  • additionalFields: Record<string, unknown>

    The requested additional fields for the product.

  • children: Omit<Product, 'children' | 'totalNumberOfChildren'>

    The child products of the product, fetched through product grouping.

  • clickUri: string

    The URL of the product.

  • permanentid: string

    The SKU of the product.

  • totalNumberOfChildren: number

    The total number of child products fetched through product grouping.

  • ec_brand?: string

    The brand of the product.

    From the ec_brand field.

  • ec_category?: string

    The category of the product (e.g., "Electronics;Electronics|Televisions;Electronics|Televisions|4K Televisions").

    From the ec_category field.

  • ec_description?: string

    The description of the product.

    From the ec_description field.

  • ec_gender?: string

    The gender the product is intended for.

  • ec_images?: string[]

    The URLs of additional product images.

    From the ec_images field.

  • ec_in_stock?: boolean

    Whether the product is currently in stock.

    From the ec_in_stock field.

  • ec_item_group_id?: string

    The ID used for the purpose of product grouping.

    From the ec_item_group_id field.

  • ec_name?: string

    The name of the product.

    From the ec_name field.

  • ec_price?: number

    The base price of the product.

    From the ec_price field.

  • ec_product_id?: string

    The product ID.

  • ec_promo_price?: number

    The promotional price of the product.

    From the ec_promo_price field.

  • ec_rating?: number

    The product rating, from 0 to 10.

    From the ec_rating field.

  • ec_shortdesc?: string

    A short description of the product.

    From the ec_shortdesc field.

  • ec_thumbnails?: string[]

    The URLs of the product image thumbnails.

    From the ec_thumbnails field.

QueryCorrection

Properties

  • correctedQuery: string

    The query once corrected

  • wordCorrections?: WordCorrection[]

    Array of correction for each word in the query

SortInitialState

Properties

  • criterion?: SortByRelevance | SortByFields

    The initial sort criterion to register in state.

SortProps

Properties

  • initialState?: SortInitialState

    The initial state that should be applied to this Sort controller.

SortState

Properties

  • appliedSort: SortByRelevance | SortByFields

    The current sort criterion.

  • availableSorts: SortByRelevance | SortByFields

    The available sort criteria.

Unsubscribe

Call signatures

  • (): void;

UrlManagerInitialState

Properties

  • fragment: string

    The part of the url that contains search parameters. E.g., q=windmill&f[author]=Cervantes

UrlManagerProps

Properties

UrlManagerState

Properties

  • fragment: string

    The part of the url that contains search parameters. E.g., q=windmill&f[author]=Cervantes

WordCorrection

Properties

  • correctedWord: string

    The new corrected word

  • length: number

    Length of the correction

  • offset: number

    Offset, from the beginning of the query

  • originalWord: string

    The original word that was corrected