קבלת תוכן חיפוש
הוספנו ל-SDK תמיכה בקבלת ממשק משתמש של תוכן חיפוש.
Search Content
הוא מונח כללי שמייצג כמה סוגים של תכונות תוכן. בקטעים הבאים מוסבר איך לבקש כל סוג של תכונה תוכן בנפרד.
חיפוש חוזר
קוראים ל-method 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];
}