Skip to main content

globalSearch

Public search across titles and attribute values of visible records.

Description​

This method searches names and attribute values of records across entity types. It returns a Promise that resolves to an IGlobalSearchResponse object - the query it was run for, plus the found records grouped by entity type, each item carrying the context of how it matched.

.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

visibility: 'all' | 'visible' | 'hidden'
Visibility filter of the searched records. Default: "all"
example: "all"

offset: number
Drilldown mode offset. Pass it only together with a single accessible type in types

limit: number
Drilldown mode page size. Pass it only together with a single accessible type in types, otherwise the API answers 400 "Drilldown mode (limit/offset) requires exactly one accessible type in types". Without it every group is returned in full

Examples​

Minimal example​

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

Example with attributes​

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

Rendering the groups​

const { query, groups } = await Search.globalSearch('test');

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 found within this entity type.

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

ℹ️ offset and limit require exactly one accessible type in types; any other combination answers 400. Omit both to get every group in full - see Drilldown mode.