รับเนื้อหาในการค้นหา
เราได้เพิ่มการรองรับการรับ UI เนื้อหาการค้นหาใน SDK
Search Content เป็นคำทั่วไปที่แสดงถึงเนื้อหาหลายประเภท
ฟีเจอร์ โปรดดูส่วนต่อไปนี้เพื่อดูวิธีขอเนื้อหา
ฟีเจอร์แต่ละประเภทตามลำดับ
ค้นหาซ้ำ
เรียกใช้เมธอด getSearchContent ใน ContextualSearchRuntime เมธอดนี้
รับ GetSearchContentOptions รายการเดียวที่คุณระบุข้อความที่จะใช้
เพื่อรับเนื้อหาการค้นหาได้ หากต้องการให้ค้นหาซ้ำ ให้ส่งข้อความค้นหาซ้ำ
ไปยังอินสแตนซ์ GetSearchContentOptions
ออบเจ็กต์ SearchContents ที่แสดงไม่มีพร็อพเพอร์ตี้ที่เข้าถึงได้
ซึ่งมีข้อมูลที่จำเป็นทั้งหมดในการแสดงเนื้อหาการค้นหา แต่
นอกเหนือจากนั้นจะไม่มีการเปิดเผย
SwiftUI
Task {
let sampleSearchRepeat = "search repeat text"
let options = GetSearchContentOptions(searchRepeat: sampleSearchRepeat)
let searchContents: SearchContents =
try await contextualSearchRuntime.getSearchContent(withOptions: options)
}
Objective-C
GetSearchContentOptions *options =
[[GetSearchContentOptions alloc] initWithSearchRepeat:@"sample search repeat"];
[_contextualSearchRuntime getSearchContentWithOptions:options
completionHandler:^(SearchContents *_Nullable contents,
NSError *_Nullable error) {
// error will be not null if there is an error.
// On success, contents will be non null.
}];
แสดงเนื้อหาการค้นหา
หากต้องการแสดงเนื้อหาการค้นหา ให้ใช้วิธีการต่อไปนี้
SwiftUI
var customizationOptions = SearchContentViewOptions()
...
VStack {
ForEach(searchContents.searchContentBlocks) { block in
SearchContentView(blockData: block, options: customizationOptions)
}
}
Objective-C
for (SearchContentBlockData *block in ((SearchContents *)_searchContents)
.searchContentBlocks) {
SearchContentViewController *blockView = [[SearchContentViewController alloc]
initWithOptions:[[SearchSuggestionsViewOptions alloc] init]];
blockView.blockData = block;
[_searchContentStackView addSubview:blockView.view];
[blockView addToViewController:self];
}