Skip to main content

globalSearch

Public search across titles and attribute values of visible records.

Description​

Searches the names and attribute values of visible products, pages, blocks and discounts. Resolves to an IGlobalSearchResponse: the query it ran for and the found records grouped by entity type, each with the context of how it matched.

The query is trimmed and must be 3 to 200 characters long; a shorter one resolves to an IError with status 400 (Search query must be at least 3 characters). In drilldown mode, limit accepts 1-50 (otherwise 400, limit must not be greater than 50).

.globalSearch(

, , , , , , ,

);

Parameters schema​

Schema

query(required): string
Search query.
example: "winter"

types: TGlobalSearchEntityType[]
Entity types to search in, sent comma-separated. Searches every type when omitted or empty.

visibility: 'all' | 'visible' | 'hidden'
Ignored by the Content API: only visible records are searched.
example: "all"

offset: number
Offset for drilldown mode. Ignored without limit; offset + limit must not exceed 200.

limit: number
Page size for drilldown mode, 1-50. Pass it only with exactly one accessible type in types; otherwise the API responds with 400. offset + limit must not exceed 200. Without it, each group holds up to 5 records and hasMore shows whether there are more.

langCode: string
Language code. Default: "en_US". The search index is built per language: words in another locale are found only when you pass that locale's langCode.
example: "en_US"

limitPerType: number
Dropdown mode: maximum items per type group (API default 5, max 20). Independent from limit/offset, which page a single type in drilldown mode.

correct: boolean
Correct typos in the query by the project's search dictionary before searching. API default: true; pass false to search the query as is. The correction itself is reported in the response headers.

Examples​

Minimal example​

const response = await Search.globalSearch('winter');

Example with optional parameters​

// Drilldown: limit is accepted only alongside exactly one type.
const response = await Search.globalSearch('winter', ['products'], undefined, 0, 20);

Rendering the groups​

const result = await Search.globalSearch('test');

if ('statusCode' in result) {
// IError: e.g. 400 for a query under 3 characters or an invalid drilldown request
console.error(result.message);
} else {
result.groups.forEach((group) => {
console.log(`${group.type} (${group.items.length}${group.hasMore ? '+' : ''})`);

group.items.forEach((item) => {
// fragment is plain text, safe to highlight yourself
console.log(item.title ?? item.identifier, item.matchKind, item.fragment);
});
});
}

Example response​

{
"query": "test",
"groups": [
{
"type": "pages",
"items": [
{
"type": "pages",
"id": 50,
"title": "Test",
"matchKind": "exact",
"matchedField": "url",
"subtitle": "test",
"langCode": "en_US"
}
],
"hasMore": false
},
{
"type": "blocks",
"items": [
{
"type": "blocks",
"id": 4,
"title": "test",
"identifier": "test",
"matchKind": "exact",
"matchedField": "identifier",
"langCode": "en_US"
}
],
"hasMore": false
},
{
"type": "discounts",
"items": [
{
"type": "discounts",
"id": 1,
"title": "Example discount",
"identifier": "example_discount",
"matchKind": "attributeValue",
"matchedField": "attributeValue",
"matchedAttribute": {
"identifier": "example_discount",
"title": "example_discount"
},
"fragment": "test value",
"langCode": "en_US"
}
],
"hasMore": false
}
]
}

Response schema​

Schema: IGlobalSearchResponse

query: string
The query the results were produced for.
example: "winter"

groups: IGlobalSearchGroup[]
Found records grouped by entity type.

groups.type: TGlobalSearchEntityType
Entity type of the group.
example: "products"

groups.items: IGlobalSearchItem[]
Records of this entity type that match the query.

groups.hasMore: boolean
Whether more records of this type are available beyond the requested page.
example: false

limit (1-50) switches to drilldown mode and requires exactly one accessible type in types; otherwise the API returns 400. offset + limit must not exceed 200. Without limit, each group holds up to 5 records, and offset is ignored. The Content API searches visible records only and ignores visibility. See Drilldown mode.

The search index is per language. langCode defaults to the language set in defineOneEntry; on a multilingual site, pass the language of the current page. SDK versions before 1.0.168 sent no language at all, so a word in the second locale came back as an empty group.