検索コンテンツを取得する
SDK で検索コンテンツ UI の取得のサポートを追加しました。Search Content
は、複数の種類のコンテンツ機能を表す一般的な用語です。各種類のコンテンツ機能をリクエストする方法については、次のセクションをご覧ください。
検索の繰り返し
ContextualSearchRuntime
で getSearchContent
メソッドを呼び出します。このメソッドは、検索コンテンツの取得に使用するテキストを指定する GetSearchContentOptions
を 1 つ受け取ります。検索の繰り返しを取得するには、検索の繰り返しテキストを 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];
}