Ricerche di tendenza

Ottenere le ricerche di tendenza

Per ottenere le ricerche di tendenza, chiama il metodo getTrendingSearches su ContextualSearchRuntime. Questo metodo accetta un singolo GetTrendingSearchesOptions in cui puoi specificare il numero massimo di tendenze restituite.

L'oggetto SearchSuggestions restituito non contiene proprietà accessibili. Contiene tutte le informazioni necessarie per il rendering delle ricerche di tendenza, ma per il resto è opaco.

Swift utilizza lo stile Swift Concurrency, mentre Objective-C utilizza una funzione di callback.

Swift

getTrendingSearches(withOptions:)

Task {
    let suggestions = try await searchRuntime.getTrendingSearches(
            withOptions: GetTrendingSearchesOptions())
}

Objective-C

getTrendingSearchesWithOptions

  [searchRuntime
      getTrendingSearchesWithOptions:
            [[GetTrendingSearchesOptions alloc] init]
                             completionHandler:^(SearchSuggestions *_Nullable suggestions,
                                                 NSError *_Nullable error) {
                              // error will be not null if there is an error.
                              // On success, suggestions will be non null.
                            }];

Display

Per visualizzare i chip delle ricerche di tendenza, utilizza lo stesso metodo delle query di ricerca.

Avanti: Visualizzare i risultati di ricerca