Broadleaf Microservices
  • v1.0.0-latest-prod

Product Search

Searching for products is a common requriement for an eCommerce site. This portion of the SDK handling advanced searching as well as type-ahead suggestions.

Search for Products

Operation

BrowseClient#searchProducts(searchParams, options);

Parameters

Parameter Type Required? Description

searchParams

SearchParams

Provide filters, queries, and sorting

options

BrowseClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a SearchResponse<Product> or SearchRedirectResponse.

Examples

Example of searching by a query string
const response = await browseClient.searchProducts({
  query: 'green'
});

console.log(response);
Example of searching by a query string with active filters
const response = await browseClient.searchProducts({
  query: 'green',
  filters: [
    {
      name: 'price',
      ranges: [
        { minValue: '0', maxValue: '100' }
      ]
    }
  ]
});

console.log(response.content);

Type-Ahead Suggestions

Operation

BrowseClient#searchSuggestions(searchSuggestionsRequest, options);

Parameters

Parameter Type Required? Description

searchSuggestionsRequest

SearchSuggestionsRequest

The criteria for the TypeAhead suggestions

options

BrowseClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a SearchSuggestionsResponse

Examples

Example of searching by a query string
const response = await browseClient.searchSuggestions({
  query: 'green',
  config: 'productTypeAhead' (1)
});

console.log(response);
  1. This is configured in the admin under Search → Type Ahead