Acessar conteúdo da pesquisa
Adicionamos suporte para receber a interface de conteúdo da pesquisa no SDK.
Search Content é um termo geral que representa vários tipos de recursos de conteúdo. Confira as seções a seguir para saber como solicitar cada tipo de recurso de conteúdo, respectivamente.
Repetir pesquisa
Chame o método getSearchContent no ContextualSearchRuntime. Esse método usa um único GetSearchContentOptions em que você pode especificar o texto a ser usado para receber conteúdo de pesquisa. Para ativar a repetição da pesquisa, transmita o texto de repetição da pesquisa
para a instância GetSearchContentOptions.
O objeto SearchContents retornado não contém propriedades acessíveis.
Ele contém todas as informações necessárias para renderizar o conteúdo da pesquisa, mas
é opaco.
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.
}];
Conteúdo da pesquisa de display
Para mostrar o conteúdo da pesquisa, use os seguintes métodos.
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];
}