콘텐츠 검색

검색 콘텐츠 가져오기

SDK에서 검색 콘텐츠 UI를 가져오는 지원을 추가했습니다. Search Content는 여러 유형의 콘텐츠 기능을 나타내는 일반적인 용어입니다. 각 유형의 콘텐츠 기능을 각각 요청하는 방법은 다음 섹션을 확인하세요.

검색 반복

ContextualSearchRuntime에서 getSearchContent 메서드를 호출합니다. 이 메서드는 검색 콘텐츠를 가져오는 데 사용할 텍스트를 지정할 수 있는 단일 GetSearchContentOptions를 사용합니다. 검색 반복을 가져오려면 검색 반복 텍스트를 GetSearchContentOptions 인스턴스에 전달합니다.

반환된 SearchContents 객체에는 액세스 가능한 속성이 포함되어 있지 않습니다. 검색 콘텐츠를 렌더링하는 데 필요한 모든 정보가 포함되어 있지만 그 외에는 불투명합니다.

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

검색 콘텐츠 표시

검색 콘텐츠를 표시하려면 다음 메서드를 사용하세요.

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

다음: 검색 결과 표시