Search
One query across the products, pages, blocks and discounts of your project, grouped by entity type.
The Search module wraps the public cross-entity search endpoint. You pass a text query and get back the visible products, pages, blocks and discounts whose name or attribute value matches it. Results are grouped by type, and each record says how it matched.
Use it for a global "search everything" box, the kind that shows a few products, a couple of pages and a matching block in one dropdown, and then drill down into a single type when the user asks for more.
This is keyword search: it matches on the literal text of titles, identifiers, URLs and attribute values. For meaning-based search (a query like "warm jacket for winter" matching a product named "Insulated parka"), use the semantic search of the individual modules. See Vector search vs global search below.
Quickstart
Initialize the module from defineOneEntry:
const { } = defineOneEntry( , { });
Search everything, then walk the groups:
// Search all four public types for "winter".
const result = await Search.globalSearch('winter');
if ('statusCode' in result) {
console.error(result.message); // IError
} else {
console.log(result.query); // "winter"
result.groups.forEach((group) => {
console.log(group.type, group.items.length, group.hasMore);
group.items.forEach((item) => {
console.log(item.id, item.title, item.matchKind, item.fragment);
});
});
}
In a search-as-you-type box, debounce the query: every keystroke is a request. Don't send it until it has at least 3 characters, not counting leading and trailing spaces. Shorter queries return 400: Search query must be at least 3 characters.
Groups
The response isn't a flat list. It's { query, groups }, where each group holds the records of one entity type:
{
query: "winter",
groups: [
{ type: "products", items: [ /* … */ ], hasMore: false },
{ type: "pages", items: [ /* … */ ], hasMore: false }
]
}
hasMore tells you whether more records of that type exist beyond the returned page. Use it to offer a "show all products" link that re-runs the query in drilldown mode.
Match context
Every item carries the context of how it matched, so you can render a meaningful result row instead of a bare title:
| Field | What it tells you |
|---|---|
matchKind | Ranking kind of the match: exact, title, attributeName or attributeValue |
matchedField | The concrete field that matched: id, title, identifier, url, attributeName or attributeValue |
matchedAttribute | The attribute the match happened in (when the match came from an attribute) |
fragment | Plain-text context around the match, with no markup - highlight it yourself |
langCode | Language of the matched value, so you can label cross-language hits |
To highlight the match in your UI, use fragment. It's plain text with no markup: render it as text, or escape it before you wrap the query in your own tags and insert it as HTML.
Item fields
idis the numeric id of the record. The SDK types it asnumber | stringbecause the type is shared with the admin search.titleis optional: it's left out when the record has no title in the requested language. Fall back toidentifierorsubtitle.subtitleis set for pages and holds the page URL.attributeSetIdandparentare never set for these four types.
Only records the current caller is allowed to see are returned: the search follows the same access rules as the rest of the API.
Entity types
types narrows the search. The Content API searches four types, and the SDK sends them comma-separated:
products, pages, blocks and discounts.
Omit types to search all four. blocks is skipped when the caller's user group can't read blocks. The SDK type TGlobalSearchEntityType lists more values (forms, orders, users and others), but the Content API drops them without an error: a call with only such types returns an empty groups array. Narrow types to what your UI can actually render.
Drilldown mode
Passing limit switches the endpoint to drilldown mode, which pages through one entity type instead of previewing all of them. offset is optional in drilldown mode and ignored without limit.
In drilldown mode,
typesmust hold exactly one accessible type, or the API returns 400: Drilldown mode (limit/offset) requires exactly one accessible type intypes. A type the Content API doesn't search, such asorders, doesn't count as accessible.limitaccepts 1-50, andoffset + limitcan't exceed 200, so drilldown reaches the first 200 results of a type.
Without limit, the call runs in overview mode: each group holds up to 5 records, and hasMore tells you whether that type has more. Groups with no matches are left out. Start with the overview call, then switch to drilldown when the user picks a type.
// Overview: every type, up to 5 records per group.
const overview = await Search.globalSearch('winter');
// Drilldown: page 1 of the products only.
const products = await Search.globalSearch('winter', ['products'], undefined, 0, 20);
Visibility
The Content API searches visible records only. visibility is accepted but has no effect: 'all', 'visible' and 'hidden' return the same visible records, so hidden records never appear in public search results.
Methods
| Method | Description |
|---|---|
| globalSearch() | Search names and attribute values of products, pages, blocks and discounts |
| searchCorrect() | Typo-correction suggestions for a query ("did you mean"), without searching |
Vector search vs global search
Both find records from a text query, but they answer different questions:
| globalSearch | get…ByVectorSearch | |
|---|---|---|
| Matches on | The literal text of titles, identifiers, urls and attribute values | Meaning - a semantic (vector) similarity |
| Scope | Products, pages, blocks and discounts in one call | One module per call |
| Returns | { query, groups[] } - grouped by type | { items, total, indexReady } - a flat container |
| Typical use | A global search box / command palette | "Find me something like this" over one entity |
The semantic counterparts live in the modules themselves: products, pages, users, orders, discounts, admins and form data.
Related
- Products: semantic product search and the product catalog
- Pages: pages returned in the
pagesgroup - Filters: curated filter trees for faceted navigation