Obtenir le contenu de la recherche
Nous avons ajouté la prise en charge de l'obtention de l'interface utilisateur du contenu de la recherche dans le SDK.
Search Content est un terme général représentant plusieurs types de fonctionnalités de contenu. Consultez les sections suivantes pour savoir comment demander chaque type de fonctionnalité de contenu.
Répétition de la recherche
Appelez la méthode getSearchContent sur ContextualSearchRuntime. Cette méthode prend un seul GetSearchContentOptions dans lequel vous pouvez spécifier le texte à utiliser pour obtenir le contenu de la 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 la recherche, mais il est 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];
}