البحث في المحتوى

الحصول على محتوى البحث

أضفنا إمكانية الحصول على واجهة مستخدم محتوى البحث في حزمة تطوير البرامج (SDK). Search Content هو مصطلح عام يمثّل أنواعًا متعدّدة من ميزات المحتوى، يُرجى الاطّلاع على الأقسام التالية لمعرفة كيفية طلب كل نوع من ميزات المحتوى على حدة.

تكرار البحث

استدعِ طريقة getSearchContent على ContextualSearchRuntime. تأخذ هذه الطريقة 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];
    }

التالي: عرض نتائج البحث