Obtenir du contenu de recherche
Nous avons ajouté la possibilité d'obtenir l'UI du contenu de recherche dans le SDK.
Search Content
est un terme général qui représente plusieurs types de fonctionnalités de contenu. Consultez les sections suivantes pour savoir comment demander chaque type de fonctionnalité de contenu.
Répéter la recherche
Appelez la méthode getSearchContent
sur ContextualSearchRuntime
. Cette méthode accepte un seul GetSearchContentOptions
dans lequel vous pouvez spécifier le texte à utiliser pour obtenir le contenu de recherche. Pour obtenir la répétition de la recherche, transmettez le texte de répétition de la recherche à l'instance GetSearchContentOptions
.
L'objet SearchContents
renvoyé ne contient aucune propriété accessible.
Il contient toutes les informations nécessaires pour afficher le contenu de recherche, mais est par ailleurs opaque.
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.
}];
Afficher le contenu de la recherche
Pour afficher le contenu de la recherche, utilisez les méthodes suivantes.
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];
}