<ws-search> component establishes the connection between the frontend (search input field, filters) and the search backend. It is required in order to execute search requests and to fetch the data for filters and search results.
Prerequisite
- The component must be present on every page on which
<ws-search-box>is used, but only once per page.
Component
The component can be embedded on the category and search result page as follows:Please note: This code example shows both the
category syntaxes for WEBSALE V8 and VX (as a comment directly after the respective line). Please remember to remove the unused part when using the code.- Attributes
url:- Specifies the URL for the API endpoints via which the search requests are executed.
- Schema:
<your-shopid>.search.websale.net/api
category: Category ID (for filtering on a category) – leave empty if you are not on a category page.- Use on category pages with the help of ST-CatPage (only for WEBSALE V8)
redirect-url: Target URL that a search input is redirected to (for example the search result page). For details, see Redirect to the search result page.health-check: Activates a one-time status check of the search backend during initialization. For details, see Health check on initialization.
Redirect to the search result page (redirect-url)
With the redirect-url attribute, <ws-search> automatically redirects to the specified target URL on a search input. This is useful on pages that do not display search results themselves (for example landing pages or the home page). The user enters a search term there and is taken directly to the search result page.
- The redirect only happens if the current page is not already the target page – this prevents a redirect loop on the search result page itself.
- The search term is appended to the target URL as the URL parameter
query.
- On a landing page: search for “laptop” → redirect to
/?wsvc=Search&query=laptop - On the search result page: search for “laptop” → no redirect, the search is executed directly
redirect-url is available from ws-search-component-1.9.1.js onwards and replaces the previous redirect script in the template (event listener on wsPerformSearch).Health check on initialization (health-check)
With the health-check attribute, <ws-search> performs a one-time check of the status of the search backend and the configured indices during initialization. The check is disabled by default. The result is output exclusively in the browser console.
- When the check is enabled, a request to
<url>/health?subshop=<subshop>is executed during initialization. - The console level is derived from the result:
- Attributes
health-check:true/yesenables the check. Default: disabled.
health-check is available from ws-search-component-1.9.1.js onwards. The associated API endpoint requires websale_search version 1.20.1 or higher.