多个客户端 ID

目前,一个客户 ID 只能支持一项搜索功能。如果您想在应用中使用多项搜索功能,则应使用多个客户端 ID。此外,如果您想在应用的不同入口点使用相同的搜索功能,则还应为每个入口点使用不同的客户端 ID 来区分流量。

对于每个请求,您都可以在 GetSearchSuggestionsOptionsGetTrendingSearchesOptionsGetSearchContentOptions 中主动设置客户端 ID,此 ID 将替换 Info.plist 文件中的默认客户端 ID(仅适用于此请求)。

Swift

getSearchSuggestions(withOptions:)

Task {
    let options = GetSearchSuggestionsOptions(withTextContext:['Sample Query', 'Another query string'])
    options.clientId = "client id"
    let suggestions = try await searchRuntime.getSearchSuggestions(
            withOptions: options)
}

Objective-C

getSearchSuggestionsWithOptions

  GetSearchSuggestionsOptions *options = [[GetSearchSuggestionsOptions alloc] initWithTextContext: @[@'Sample Query', @'Another query string' ]];
  options.clientId = [NSString stringWithFormat:@"client id"];
  [searchRuntime
      getSearchSuggestionsWithOptions:options
                             completionHandler:^(SearchSuggestions *_Nullable suggestions,
                                                 NSError *_Nullable error) {
                              // error will be not null if there is an error.
                              // On success, suggestions will be non null.
                            }];