Stay organized with collections
Save and categorize content based on your preferences.
SearchResults
open class SearchResults : Closeable
Encapsulates results of a search operation.
Each AppSearchSession.search
operation returns a list of SearchResult
objects, referred to as a "page", limited by the size configured by android.app.appsearch.SearchSpec.Builder#setResultCountPerPage
.
To fetch a page of results, call getNextPage
.
All instances of SearchResults
must call android.app.appsearch.SearchResults#close() after the results are fetched.
This class is not thread safe.
Summary
Public methods
close
open fun close(): Unit
Exceptions |
java.lang.Exception |
if this resource cannot be closed |
java.io.IOException |
if an I/O error occurs |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 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 2025-02-10 UTC."],[],[],null,["# SearchResults\n\nAdded in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nSearchResults\n=============\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/app/appsearch/SearchResults \"View this page in Java\") \n\n```\nopen class SearchResults : Closeable\n```\n\n|---|------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.app.appsearch.SearchResults](#) |\n\nEncapsulates results of a search operation.\n\nEach [AppSearchSession.search](/reference/kotlin/android/app/appsearch/AppSearchSession#search(kotlin.String,%20android.app.appsearch.SearchSpec)) operation returns a list of [SearchResult](/reference/kotlin/android/app/appsearch/SearchResult) objects, referred to as a \"page\", limited by the size configured by [android.app.appsearch.SearchSpec.Builder#setResultCountPerPage](/reference/kotlin/android/app/appsearch/SearchSpec.Builder#setResultCountPerPage(kotlin.Int)).\n\nTo fetch a page of results, call [getNextPage](#getNextPage(java.util.concurrent.Executor,%20java.util.function.Consumer)).\n\nAll instances of [SearchResults](#) must call android.app.appsearch.SearchResults#close() after the results are fetched.\n\nThis class is not thread safe.\n\nSummary\n-------\n\n| Public methods ||\n|-----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [close](#close())`()` \u003cbr /\u003e |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [getNextPage](#getNextPage(java.util.concurrent.Executor,%20java.util.function.Consumer))`(`executor:` `[Executor](../../../java/util/concurrent/Executor.html#)`, `callback:` `[Consumer](../../../java/util/function/Consumer.html#)\u003c[AppSearchResult](/reference/kotlin/android/app/appsearch/AppSearchResult)\u003c[MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\u003c[SearchResult](/reference/kotlin/android/app/appsearch/SearchResult)!\u003e!\u003e!\u003e`)` Retrieves the next page of [SearchResult](/reference/kotlin/android/app/appsearch/SearchResult) objects. |\n\nPublic methods\n--------------\n\n### close\n\nAdded in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun close(): Unit\n```\n\n| Exceptions ||\n|-----------------------|-----------------------------------|\n| `java.lang.Exception` | if this resource cannot be closed |\n| `java.io.IOException` | if an I/O error occurs |\n\n### getNextPage\n\nAdded in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getNextPage(\n executor: Executor, \n callback: Consumer\u003cAppSearchResult\u003cMutableList\u003cSearchResult!\u003e!\u003e!\u003e\n): Unit\n```\n\nRetrieves the next page of [SearchResult](/reference/kotlin/android/app/appsearch/SearchResult) objects.\n\nThe page size is configured by [SearchSpec.Builder.setResultCountPerPage](/reference/kotlin/android/app/appsearch/SearchSpec.Builder#setResultCountPerPage(kotlin.Int)).\n\nContinue calling this method to access results until it returns an empty list, signifying there are no more results.\n\n| Parameters ||\n|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `executor` | [Executor](../../../java/util/concurrent/Executor.html#): Executor on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this [Executor](../../../java/util/concurrent/Executor.html#), providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use [Context.getMainExecutor()](../../content/Context.html#getMainExecutor()). Otherwise, provide an [Executor](../../../java/util/concurrent/Executor.html#) that dispatches to an appropriate thread. |\n| `callback` | [Consumer](../../../java/util/function/Consumer.html#)\\\u003c[AppSearchResult](/reference/kotlin/android/app/appsearch/AppSearchResult)\\\u003c[MutableList](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html)\\\u003c[SearchResult](/reference/kotlin/android/app/appsearch/SearchResult)!\\\u003e!\\\u003e!\\\u003e: Callback to receive the pending result of performing this operation. This value cannot be `null`. |"]]