Search content
Stay organized with collections
Save and categorize content based on your preferences.
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 resultsarrow_forward
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-11-05 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-11-05 UTC."],[[["\u003cp\u003eThe SDK now supports fetching and displaying search content UI, encompassing various content features like "search repeat".\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve search content using \u003ccode\u003egetSearchContent\u003c/code\u003e with specified options, like providing search repeat text.\u003c/p\u003e\n"],["\u003cp\u003eWhile the returned \u003ccode\u003eSearchContents\u003c/code\u003e object is opaque, it holds the data needed for rendering search content.\u003c/p\u003e\n"],["\u003cp\u003eSwiftUI and Objective-C code samples demonstrate how to obtain and display different search content blocks.\u003c/p\u003e\n"]]],["The SDK now supports displaying search content UI. To retrieve search repeat content, use the `getSearchContent` method of `ContextualSearchRuntime`, providing the search text via `GetSearchContentOptions`. The returned `SearchContents` object is opaque and contains data for rendering. In SwiftUI, use `SearchContentView` within a `ForEach` loop over `searchContentBlocks`. In Objective-C, use `SearchContentViewController` and add the view to your interface. `SearchContentViewOptions` and `SearchSuggestionsViewOptions` can be used for UI customization.\n"],null,["# Search content\n\nGet search content\n------------------\n\nWe have added the support of getting search content UI in the SDK.\n`Search Content` is a general term representing multiple types of content\nfeatures, check following sections for how to request each type of content\nfeature respectively.\n\n### Search Repeat\n\nCall the `getSearchContent` method on the `ContextualSearchRuntime`. This method\ntakes a single `GetSearchContentOptions` where you can specify the text to use\nto get search content for. To get search repeat, pass in the search repeat text\ninto the `GetSearchContentOptions` instance.\n\nThe returned `SearchContents` object does not contain any accessible properties.\nIt contains all of the necessary information to render search content, but\notherwise is opaque. \n\n### SwiftUI\n\n Task {\n let sampleSearchRepeat = \"search repeat text\"\n let options = GetSearchContentOptions(searchRepeat: sampleSearchRepeat)\n let searchContents: SearchContents =\n try await contextualSearchRuntime.getSearchContent(withOptions: options)\n }\n\n### Objective-C\n\n GetSearchContentOptions *options =\n [[GetSearchContentOptions alloc] initWithSearchRepeat:@\"sample search repeat\"];\n [_contextualSearchRuntime getSearchContentWithOptions:options\n completionHandler:^(SearchContents *_Nullable contents,\n NSError *_Nullable error) {\n // error will be not null if there is an error.\n // On success, contents will be non null.\n }];\n\nDisplay Search Content\n----------------------\n\nTo display search content, use the following methods. \n\n### SwiftUI\n\n var customizationOptions = SearchContentViewOptions()\n ...\n VStack {\n ForEach(searchContents.searchContentBlocks) { block in\n SearchContentView(blockData: block, options: customizationOptions)\n }\n }\n\n### Objective-C\n\n for (SearchContentBlockData *block in ((SearchContents *)_searchContents)\n .searchContentBlocks) {\n SearchContentViewController *blockView = [[SearchContentViewController alloc]\n initWithOptions:[[SearchSuggestionsViewOptions alloc] init]];\n blockView.blockData = block;\n [_searchContentStackView addSubview:blockView.view];\n [blockView addToViewController:self];\n }\n\n[Next: Display search resultsarrow_forward](/search-in-apps/ios/display_search_results)"]]