Trending Searches

  • Utilize the getTrendingSearches method within ContextualSearchRuntime to retrieve current trending searches, specifying the desired maximum number through GetTrendingSearchesOptions.

  • The returned SearchSuggestions object, while crucial for rendering trends, doesn't expose direct properties for data access.

  • Swift leverages Swift Concurrency with Task and await, while Objective-C relies on a callback function for handling results and errors.

  • Trending searches can be displayed using the same approach as standard search suggestions, ensuring visual consistency.

Get Trendings

To get trending searches, call the getTrendingSearches method on the ContextualSearchRuntime. This method takes a single GetTrendingSearchesOptions where you can specify the maximum number of trendings returned.

The returned SearchSuggestions object does not contain any accessible properties. It contains all of the necessary information to render trending searches, but otherwise is opaque.

Swift uses the Swift Concurrency style, Objective-C uses a callback function.

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

To display trending searches chips, use the same way as the search suggestions.

Next: Display search results