Cómo obtener contenido de búsqueda
Se agregó compatibilidad para obtener la IU del contenido de búsqueda en el SDK.
Search Content
es un término general que representa varios tipos de atributos de contenido. Consulta las siguientes secciones para saber cómo solicitar cada tipo de atributo de contenido, respectivamente.
Repetir búsqueda
Llama al método getSearchContent
en ContextualSearchRuntime
. Este método toma un solo GetSearchContentOptions
en el que puedes especificar el texto que se usará para obtener el contenido de búsqueda. Para obtener la repetición de búsqueda, pasa el texto de repetición de búsqueda a la instancia de GetSearchContentOptions
.
El objeto SearchContents
que se muestra no contiene ninguna propiedad accesible.
Contiene toda la información necesaria para renderizar el contenido de la búsqueda, pero, por lo demás, es 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.
}];
Cómo mostrar contenido de la Búsqueda
Para mostrar contenido de búsqueda, usa los siguientes 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];
}