Search content

Get search content

We have added the support of getting search content UI in the SDK. Search Content is a general term representing multiple types of content features, check following sections for how to request each type of content feature respectively.

Search Repeat

Call the getSearchContent method on the ContextualSearchRuntime. This method takes a single GetSearchContentOptions where you can specify the text to use to get search content for. To get search repeat, pass in the search repeat text into the GetSearchContentOptions instance.

The returned SearchContents object does not contain any accessible properties. It contains all of the necessary information to render search content, but otherwise is 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.
                                    }];

Display Search Content

To display search content, use the following methods.

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];
    }

Next: Display search results