useSearch
call driven by the shopper’s query, with facets, sort, pagination and attribution.
Prerequisite: the search app is registered (
.use(search())), your app is wrapped in
<GloodProvider>, and https://search.glood.ai is in your CSP connectSrc. See
Installation.1. Run the search
Read the query from the URL and pass it touseSearch. Set
includeFacets to get inline facet counts for the current query.
SearchParams;
data is a SearchResponse
and products are SearchProduct objects.
2. Render results, sort and pagination
sort values are listed in SearchSort;
data.pagination is a SearchPagination.
3. Add facet filtering
Track selected facet values in state and pass them as thefacets param (an array of
SearchAppliedFacet).
Render the buckets from data.facets:
For stable filter definitions independent of the query, fetch them with
fetchFilters, and
for standalone live counts use
fetchFilterAggregations.4. Attribution
useSearch returns
trackSearch,
trackResultView, trackResultClick, trackAddToCart and trackFilter. Call trackSearch
when the results render, trackResultClick on click (step 2), and trackAddToCart on add.
Each takes a SearchTrack.
Standard Shopify events (search_submitted, product_viewed, …) are forwarded automatically
— see Events & attribution.
5. (Optional) Server-render the first page
To ship results in the initial HTML, callfetchSearchResults
in the route loader instead of the hook:
See also
- Instant Search — the type-ahead box that feeds this page
- Search API Reference
- Full example route