انتقل إلى المحتوى الرئيسي

globalSearch

بحث عام عبر العناوين وقيم السمات للسجلات المرئية.

Description​

تبحث هذه الطريقة في أسماء وقيم السمات للسجلات عبر أنواع الكيانات. تعيد Promise التي تحل إلى كائن IGlobalSearchResponse - الاستعلام الذي تم تشغيله من أجله، بالإضافة إلى السجلات التي تم العثور عليها مجمعة حسب نوع الكيان، حيث يحمل كل عنصر سياق كيفية تطابقه.

.globalSearch(

, , , ,

);

Parameters schema​

Schema

query(required): string
استعلام البحث
مثال: "شتاء"

types: TGlobalSearchEntityType[]
أنواع الكيانات للبحث فيها، تُرسل مفصولة بفواصل. يتم البحث في كل نوع عند الإغفال

visibility: 'الكل' | 'مرئي' | 'مخفي'
مرشح رؤية السجلات التي تم البحث عنها. الافتراضي: "الكل"
مثال: "الكل"

offset: number
إزاحة وضع التعمق. مررها فقط مع نوع واحد قابل للوصول في types

limit: number
حجم صفحة وضع التعمق. مررها فقط مع نوع واحد قابل للوصول في types، وإلا فإن واجهة برمجة التطبيقات تستجيب بـ 400 "وضع التعمق (الحد/الإزاحة) يتطلب بالضبط نوعًا واحدًا قابلًا للوصول في types". بدونها، يتم إرجاع كل مجموعة بالكامل

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
الاستعلام الذي تم إنتاج النتائج من أجله.
مثال: "شتاء"

groups: IGlobalSearchGroup[]
السجلات التي تم العثور عليها مجمعة حسب نوع الكيان.

groups.type: TGlobalSearchEntityType
نوع الكيان للمجموعة.
مثال: "المنتجات"

groups.items: IGlobalSearchItem[]
السجلات التي تم العثور عليها ضمن هذا النوع من الكيانات.

groups.hasMore: boolean
ما إذا كانت هناك سجلات أخرى من هذا النوع متاحة بخلاف الصفحة المطلوبة.
مثال: false

ℹ️ offset و limit يتطلبان بالضبط نوعًا واحدًا قابلًا للوصول في types؛ أي تركيبة أخرى تستجيب 400. اترك كلاهما للحصول على كل مجموعة بالكامل - انظر وضع التعمق.