Search basics
POST /search is the one request behind a results page: the matching records,
facet counts for the filters beside them, and a queryId for tracking clicks.
A search
Section titled “A search”curl -s "https://api.shoofai.co/v1/apps/$SHOOF_APP/search" \ -H "x-shoof-api-key: $SHOOF_SEARCH_KEY" \ -H "content-type: application/json" \ -d '{ "q": "waterproof jacket", "lang": "en", "filters": { "type": "product", "price": { "lte": 400 } }, "facets": ["brand", "categories", "price"], "page": 0, "hitsPerPage": 24 }'const res = await client.search({ q: "waterproof jacket", lang: "en", filters: { type: "product", price: { lte: 400 } }, facets: ["brand", "categories", "price"], page: 0, hitsPerPage: 24,});Every field is optional. An empty q returns every record, which is how you
build a category page: filter by category and sort by price or date.
The response:
{ "hits": [ { "id": "jkt-77-en", "type": "product", "title": "Storm shell jacket", "url": "https://example.com/p/storm-shell", "price": 349, "brand": "Arc'teryx", "_highlight": { "title": ["Storm shell <mark>jacket</mark>"] }, "_snippet": "Fully <mark>waterproof</mark> three-layer shell with taped seams…" // … the record's other fields } ], "nbHits": 37, "nbHitsExact": false, "page": 0, "nbPages": 2, "hitsPerPage": 24, "facets": { "brand": [{ "value": "Arc'teryx", "count": 9 }, { "value": "Patagonia", "count": 7 }], "categories": [{ "value": "Jackets", "count": 31 }], "price": { "min": 89, "max": 400 } }, "query": "waterproof jacket", "queryId": "xU3s9fQk1…", "mode": "hybrid", "processingTimeMS": 38}| Field | Means |
|---|---|
hits |
The page of results. Each is the record, plus _highlight, _snippet and, on request, _rankingInfo. |
nbHits |
How many records match. In hybrid and semantic modes this is an estimate (nbHitsExact: false). |
page, nbPages, hitsPerPage |
Paging. Pages count from 0. |
facets |
Counts per facet value, or {min, max} for number and date facets. See Facets. |
queryId |
Send it with click and conversion events. |
mode |
The mode that ran. |
appliedRules, banners, userData |
What matching rules returned. |
Search modes
Section titled “Search modes”| Mode | How it ranks | Good at |
|---|---|---|
hybrid (default) |
Runs both, and fuses their rankings with reciprocal rank fusion. | Everything: exact terms and meaning. |
lexical |
Keyword matching (BM25) with typo tolerance, synonyms and field weights. | SKUs, model numbers, brand names, exact phrases. |
semantic |
Vector similarity over multilingual embeddings of the title and text. | Paraphrases and descriptions: “something to keep coffee hot”. |
Hybrid is the default because it keeps keyword precision for SKUs and names and
adds semantic recall for everything else. Set an app’s default in the settings
(mode) and override it per request with mode.
Some things switch a search to lexical on their own: an empty q, an explicit
sort, and apps whose region has no embeddings.
Languages
Section titled “Languages”Send lang (en or ar) with every search. It picks the language’s text
analysis, and with the filterByLang setting (on by default) it returns only
records in that language. Without lang, records in every language can match.
Paging
Section titled “Paging”page counts from 0 and hitsPerPage is 1 to 100 (20 by default, or the app’s
hitsPerPage setting). Results go up to the first 1,000.
hitsPerPage: 0 returns no hits, only counts and facets: handy for a filter
sidebar.
Sorting
Section titled “Sorting”Without sort, results are ranked by relevance. To sort, send a field, with
:asc or :desc (the default):
{ "q": "jacket", "sort": "price:asc" }You can sort on price, regular_price, sale_price, rating,
review_count, popularity, date, modified, title, your own
ranking.<name> signals, and custom fields that
aren’t text. Records without the field come last. relevance goes back to
relevance order.
Highlighting and snippets
Section titled “Highlighting and snippets”Each hit has:
_highlight: the matched fields as HTML fragments with matches in<mark>, such as{"title": ["Storm shell <mark>jacket</mark>"]}. Text is HTML-escaped, so it’s safe to insert as HTML._snippet: the passage that best matches the query, with matches marked. For long content, it’s the matching passage, not just the start of the text.
Turn both off with "highlight": false.
Choosing fields
Section titled “Choosing fields”Hits return the whole record. To return less, list the fields you want:
{ "q": "jacket", "attributesToRetrieve": ["title", "url", "image", "price"] }id, type and title are always returned, and ["*"] returns everything.
The app’s attributesToRetrieve setting sets the default for every search.
Ranking details
Section titled “Ranking details”"rankingInfo": true adds _rankingInfo to each hit: its rank in the keyword
and semantic lists, whether a rule pinned it, and its
learned boost. Useful while tuning relevance.
Analytics flags
Section titled “Analytics flags”| Field | Default | Does |
|---|---|---|
analytics |
true |
Record the search in analytics. Set false for searches visitors didn’t type, such as a category page’s. It still counts towards your quota. |
clickAnalytics |
true |
Return a queryId for click tracking. |
userToken |
The visitor’s anonymous ID. See user tokens. |
Several searches at once
Section titled “Several searches at once”POST /multi-search runs up to 10 searches in parallel, such as products and
articles for a results page with two sections:
{ "requests": [ { "q": "shoes", "filters": { "type": "product" }, "hitsPerPage": 12 }, { "q": "shoes", "filters": { "type": "post" }, "hitsPerPage": 3 } ]}Each search counts towards your quota.
Without a request body
Section titled “Without a request body”GET /search takes the same parameters in the query string, for clients that
can’t send a body. facets is comma-separated, and filters is JSON:
GET /v1/apps/my-store/search?q=jacket&lang=en&facets=brand,price&filters={"price":{"lte":400}}