Search Page
Using the vviinn widgets as separate components gives you greater control over the layout and supports a wider range of use cases. For example, you can combine Text Search and Visual Search while refining results with filters, and display them on the same page or even on different pages.
Available components
Section titled “Available components”vviinn-text-search— a text search input field that allows users to search by text or upload an imagevviinn-filters,vviinn-extended-filters— a set of filters that allow users to refine their search resultsvviinn-results— a container that displays the search results
Examples
Section titled “Examples”Using results on a different page
Section titled “Using results on a different page”This is the most common use case: the search component is on one page (e.g., the homepage), and results are displayed on a separate search results page. The Search & Results Page Redirects guide covers this setup step by step.
Automatic redirect (recommended)
Section titled “Automatic redirect (recommended)”Set the results-page-url prop on the search component. The widget handles redirection and URL parameter passing automatically.
<!-- Homepage --><vviinn-text-search token="YOUR_READ_ONLY_TOKEN" mode="extended" locale="en-US" results-page-url="/search"></vviinn-text-search>
<!-- Results page (/search) --><vviinn-text-search token="YOUR_READ_ONLY_TOKEN" mode="extended" locale="en-US" results-page-url="/search"></vviinn-text-search>
<vviinn-filters></vviinn-filters><vviinn-extended-filters locale="en-US"></vviinn-extended-filters>
<vviinn-results token="YOUR_READ_ONLY_TOKEN" locale="en-US" product-details-new-tab="true" results-page-url="/search"></vviinn-results>How it works:
- When the user searches on the homepage, the widget redirects to the results page with URL parameters (e.g.,
/search?query=shoesor/search?searchId=abc-123). URL parameter names can be customized viaresults-page-params(e.g.,results-page-params="query=q&searchId=sid"→/search?q=shoes&sid=abc-123). Set this prop on both the search component andvviinn-resultsso they agree on the parameter names. - On the results page,
vviinn-resultswithresults-page-urlset automatically parses URL parameters and triggers the corresponding search. - The
vviinn-text-searchinput is automatically populated with the query from the URL. - On the results page,
results-page-urlensures that the widget does not redirect again — subsequent searches update results in place. - You can intercept the redirect by listening to the
vviinnRedirectevent and callingevent.preventDefault()(e.g., for SPA routing). - Visual search (
vviinn-vps-button,vviinn-vps-widget) supports the same flow: setresults-page-urlandshow-results-in-modal="false"to redirect to the results page after image upload instead of rendering results inside the modal.
Manual redirect
Section titled “Manual redirect”For full control over the redirect logic, omit results-page-url and handle navigation yourself using events.
<!-- Homepage --><script> document.addEventListener("vviinnTextSearchStarted", ({ detail }) => { // Redirect using detail.query (text search) });
document.addEventListener("vviinnImageUploadFinished", ({ detail }) => { // Redirect using detail.searchId (image search) });</script><vviinn-text-search token="YOUR_READ_ONLY_TOKEN" mode="extended" locale="en-US"></vviinn-text-search>
<!-- Results page --><script> // Get query or searchId from URL</script><vviinn-filters></vviinn-filters><vviinn-extended-filters locale="en-US"></vviinn-extended-filters>
<!-- Text Search example: --><vviinn-text-search token="YOUR_READ_ONLY_TOKEN" mode="extended" locale="en-US" search-query="RECEIVED_QUERY"></vviinn-text-search>
<vviinn-results token="YOUR_READ_ONLY_TOKEN" locale="en-US" product-details-new-tab="true"></vviinn-results>
<!-- Image Search example: --><vviinn-cropper token="YOUR_READ_ONLY_TOKEN" width="300"></vviinn-cropper>
<vviinn-text-search token="YOUR_READ_ONLY_TOKEN" mode="extended" locale="en-US"></vviinn-text-search>
<vviinn-results token="YOUR_READ_ONLY_TOKEN" search-id="RECEIVED_SEARCH_ID" locale="en-US" product-details-new-tab="true"></vviinn-results>In this example, the vviinn-text-search component is on the first page, and the rest of the components are on the second page.
- First, add event listeners to capture the
queryfor a text search or thesearchIdfor a Visual Search. - Pass this data to the second page via the URL and use it to get the results.
- For Text Search, use the
search-queryattribute to pass the query to thevviinn-text-searchcomponent. - For Visual Search, use the
search-idattribute to pass thesearchIdto thevviinn-resultscomponent. To show the image, use thevviinn-croppercomponent. The defaultsave-image-mode="once"lets the Cropper reuse the uploaded image.
- For Text Search, use the
Implementation tips
Section titled “Implementation tips”| Scenario | Recommendation | Component/Attribute |
|---|---|---|
| Automatic redirect to results page | Set the results page URL — the widget handles redirect and URL parameters automatically | <vviinn-text-search results-page-url="/search"> or results-page-url="https://shop.com/search" |
| Intercepting the redirect (SPA) | Listen to the vviinnRedirect event and call preventDefault() to handle navigation yourself |
document.addEventListener("vviinnRedirect", ...) |
| Performing new searches on results page | Don’t pass parameters again — components handle new queries automatically | No attributes needed |
| Supporting page reloads (manual redirect) | When handling the redirect manually, update the URL after each search using the browser History API so the page can be reloaded | Use pushState() or replaceState() |
| Preserving uploaded image on reload | Save the image between page reloads for Visual Search | <vviinn-cropper save-image-mode="always"> |
Single page example
Section titled “Single page example”Integration
Section titled “Integration”To integrate the components into your project, install the vviinn-widgets package using one of the methods in the Installation section. You need at least version 2.76.1 of the package to use the components, but the latest version is recommended.
You can use the components in a framework-agnostic way or integrate them into your project with a specific framework. The components can be used together or separately, depending on your needs. They are highly customizable and suitable for a wide range of use cases.