Skip to main content

SearchClient

The SearchClient class is a vital part of search system. It takes care of search data, caching, events and enables providing different search adapters.

import { SearchClient } from '@archibald/search';

In order to use the search client, you need to create a new instance which takes the following options. Afterward you need to provide the instance to the SearchDataProvider.

const searchClient = new SearchClient(OPTIONS);

Options

NameTypeDescriptionDefault
apiCreateApiapi definition.commerce
adapterSearchAdapter | mock | commerce | coveo | undefinedSearch adapter.commerce
cacheTimenumber | undefinedHow long search data should be kept in the cache.5 minutes
configDefaultApiConfig | undefinedApi Config for the adapter.
paramNamesSearchClientParamNames | undefinedURL params names for the search.

SearchClientParamNames

NameTypeDescriptionDefault
querystring | undefinedSearch termq
sortstring | undefinedSelected sortsort
pagestring | undefinedCurrent page if pagination is enabledpage

This method executes search by calling onSearch method from the provided adapter.

await searchClient.search(PARAMETERS);

prefetchSearch

This method is used to prefetch a search on the server and seed the DataCache.

await searchClient.prefetchSearch(PARAMETERS);

Parameters

NameTypeDescriptionDefault
keystringCache key pointing to the cache where the search results will be stored.
searchOptionsSearchRequestOptionsOptions that define what kind of search request will be sent.

SearchRequestOptions

NameTypeDescriptionDefault
categoryIdstring | undefinedCategory ID which is set on product search by category
searchstring | undefinedSearch string container query, sort, current page etc. needed for both free search and search by category
groupboolean | undefinedFallback that will be used when new data is being fetched for the changed key avoiding loading indicators
pageSizesnumber[] | undefinedNumber of page results per page
entitykeyof SearchResponseMap | undefinedEntity type that is being searched for.