React SDK

useSearch

useSearch provides a way to perform a search using the current context or a custom one-off search.

Usage

Returns results for the current query. By default it will use the Variables and Pipeline from the context:

Editable Example
Suggestions
    Powered by

    Optionally pass in Variables or Pipeline:

    Editable Example

    Show

      Multiple searches

      As in the above example, it's possible to perform one off searches using the useSearch hook. This means we can build a page that performs multiple searches, for example within different categories.

      Note: each category search request must use it's own pipeline.

      Editable Example

      Audio

      Loading...

      Computers & Tablets

      Loading...

      TV & Home Theater

      Loading...

      Anatomy

      useSearch returns an object containing the following properties:

      NameTypeDefaultDescription
      resultsResult[]An array of results that met the query. See the JS SDK for detailed object shape.
      latencynumberThe engine latency.
      totalResultsnumberThe total count of results.
      search(q?: string) => voidThe search method, call without param to resend the search request with the current query.
      searchingbooleanIs a search request being processed.
      errorError | nullThe error encountered while searching.
      redirects{ [redirectQuery: string]: RedirectTarget }{}An object which maps a search string, redirectQuery, to possible redirect completions for that string. See the JS SDK for detailed object shape.
      activePromotionsActivePromotion[][]An array of active promotions on this result. See the JS SDK for detailed object shape.
      featureScoreWeightnumber0Meta info about this query, feature score weight determines the weighting of featureScore vs neural and index scores.
      bannersBanner[]0An array of banners.

      Parameters

      NameTypeDefaultDescription