প্রস্তাবিত অনুসন্ধান পান
অনুসন্ধানের পরামর্শ পেতে, ContextualSearchRuntime
অনুসন্ধান রানটাইমে getSearchSuggestions
পদ্ধতিতে কল করুন। এই পদ্ধতিটি একটি একক GetSearchSuggestionsOptions নেয় যেখানে আপনি অনুসন্ধানের পরামর্শ পেতে ব্যবহার করার জন্য পাঠ্য নির্দিষ্ট করতে পারেন।
ফিরে আসা SearchSuggestions
অবজেক্টে কোনো অ্যাক্সেসযোগ্য বৈশিষ্ট্য নেই। এতে অনুসন্ধানের পরামর্শ রেন্ডার করার জন্য প্রয়োজনীয় সমস্ত তথ্য রয়েছে, কিন্তু অন্যথায় অস্বচ্ছ।
সুইফট সুইফট কনকারেন্সি স্টাইল ব্যবহার করে, অবজেক্টিভ-সি একটি কলব্যাক ফাংশন ব্যবহার করে।
সুইফট
getSearch Suggestions(বিকল্প সহ:)
Task {
let suggestions = try await searchRuntime.getSearchSuggestions(
withOptions: GetSearchSuggestionsOptions(withTextContext:['Sample Query', 'Another query string']))
}
উদ্দেশ্য-C
getSearchSuggestionsWithOptions
[searchRuntime
getSearchSuggestionsWithOptions:
[[GetSearchSuggestionsOptions alloc] initWithTextContext: @[@'Sample Query', @'Another query string' ]]
completionHandler:^(SearchSuggestions *_Nullable suggestions,
NSError *_Nullable error) {
// error will be not null if there is an error.
// On success, suggestions will be non null.
}];
অবস্থান-ভিত্তিক প্রস্তাবিত অনুসন্ধান পান
getSearchSuggestions
অনুরোধটি অবস্থান-ভিত্তিক অনুসন্ধান পরামর্শকেও সমর্থন করে। একটি LocationSuggestionsContext দিয়ে একটি GetSearchSuggestionsOptions
অবজেক্ট তৈরি করুন।
LocationSuggestionsContext
ক্লাস তৈরি করতে এই ধাপগুলি অনুসরণ করুন:
- (প্রয়োজনীয়) অনুরোধ করা এলাকার সাথে মেলে
latitude
,longitude
এবংradiusMeters
সেট করুন। - (ঐচ্ছিক) অনুরোধ করা সময়ের সাথে মেলানোর জন্য
startTime
সেট করুন যেখানে অনুসন্ধানের পরামর্শগুলি প্রয়োগ করা উচিত। - (ঐচ্ছিক) অনুরোধ করা জিও প্রকারের সাথে
geoTypes
তালিকা সেট করুন। প্রদত্ত প্রকারগুলি পরিষেবা দ্বারা প্রত্যাবর্তিত ফলাফলগুলির র্যাঙ্কিং এবং ফিল্টারিং সামঞ্জস্য করতে ব্যবহৃত হয়। সমর্থিত মানগুলি LocationSuggestionsContext- এ নথিভুক্ত করা হয়েছে।
সুইফট
getSearch Suggestions(বিকল্প সহ:)
Task {
let locationContext: LocationSuggestionsContext = {
let context = LocationSuggestionsContext()
context.latitude = 40.748595
context.longitude = -73.992365
context.radiusMeters = 2500
context.startTime = try?
Date.ISO8601FormatStyle.iso8601.parse("2024-03-14T19:20:30.000+02:00")
context.geoTypes = ["restaurant", "cafe"]
return context
}()
let suggestions = try await searchRuntime.getSearchSuggestions(
withOptions: GetSearchSuggestionsOptions(locationContext: [
locationContext
]))
}
উদ্দেশ্য-C
getSearchSuggestionsWithOptions
LocationSuggestionsContext *locationContext;
locationContext = [[LocationSuggestionsContext alloc] init];
locationContext.latitude = 40.748595;
locationContext.longitude = -73.992365;
locationContext.radiusMeters = @2500;
[searchRuntime
getSearchSuggestionsWithOptions:
[[GetSearchSuggestionsOptions alloc] initWithLocationContext: locationContext]
completionHandler:^(SearchSuggestions *_Nullable suggestions,
NSError *_Nullable error) {
// error will be not null if there is an error.
// On success, suggestions will be non null.
}];
প্রদর্শন
অনুসন্ধান পরামর্শ চিপগুলি প্রদর্শন করতে, নিম্নলিখিত পদ্ধতিগুলি ব্যবহার করুন (যদি আপনি UIKit বনাম SwiftUI ব্যবহার করেন তবে শৈলীটি পরিবর্তিত হয়)।
সুইফট ইউআইকিট
SearchSuggestionsViewController ব্যবহার করে সার্চ সাজেশন চিপ প্রদর্শন করুন।
// Create the SearchSuggestionsViewController with specified display options.
var searchSuggestionsController = SearchSuggestionsViewController(options: viewOptions)
...
// Add the view controller to the existing view hierarchy
searchSuggestionsController.addToViewContoller(self)
view.addSubview(searchSuggestionsController.view)
...
// Assign a specific set of search suggestions to this view controller.
searchSuggestionsController.searchSuggestions = suggestions
উদ্দেশ্য-C
SearchSuggestionsViewController ব্যবহার করে সার্চ সাজেশন চিপ প্রদর্শন করুন।
// Create the SearchSuggestionsController with specified display options.
SearchSuggestionsViewController *_searchSuggestionsController =
[[SearchSuggestionsViewController alloc] initWithOptions:_customizationOptions];
...
// Add the view controller to the existing view hierarchy
[_searchSuggestionsController addToViewController:self];
[self.view addSubview:_searchSuggestionsController.view];
...
// Assign a specific set of search suggestions to this view controller.
_searchSuggestionsController.searchSuggestions = suggestions
সুইফটইউআই
অনুসন্ধান পরামর্শগুলি একটি অনুসন্ধান পরামর্শ ভিউ দিয়ে প্রদর্শিত হতে পারে
SearchSuggestionsView(suggestions: suggestions, options: options)