# SearchResult

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/app/SearchResult.java+class:androidx.appsearch.app.SearchResult) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***

<br />

```
class SearchResult
```

<br />

*** ** * ** ***

This class represents one of the results obtained from an AppSearch query.

This allows clients to obtain:

- The document which matched, using `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getGenericDocument()`
- Information about which properties in the document matched, and "snippet" information containing textual summaries of the document's matches, using `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getMatchInfos()`

"Snippet" refers to a substring of text from the content of document that is returned as a part of search result.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResults` |   |

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.Builder` Builder for `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` objects. |
| `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi class https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.EmbeddingMatchInfo` This class represents match objects for any snippets that might be present in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResults` from an embedding query. |
| `class https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchInfo` This class represents match objects for any snippets that might be present in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResults` from a query. |
| `class https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchInfo.Builder` Builder for `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchInfo` objects. |
| `class https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` Class providing the position range of a text match information. |
| `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi class https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo` This class represents match objects for any text match snippets that might be present in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResults` from a string query. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getDatabaseName()()` Contains the database name that stored the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument`. |
| `T` | `<T> https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getDocument(java.lang.Class<T>)(documentClass: https://developer.android.com/reference/java/lang/Class.html<T!>)` Contains the matching document, converted to the given document class. |
| `T` | `<T> https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getDocument(java.lang.Class<T>,java.util.Map<java.lang.String,java.util.List<java.lang.String>>)( documentClass: https://developer.android.com/reference/java/lang/Class.html<T!>, documentClassMap: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!>? )` Contains the matching document, converted to the given document class. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getGenericDocument()()` Contains the matching `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument`. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html!>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getInformationalRankingSignals()()` Returns the informational ranking signals of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument`, according to the expressions added in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec.Builder#addInformationalRankingExpressions(java.lang.String...)`. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult!>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getJoinedResults()()` Gets a list of `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` joined from the join operation. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchInfo!>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getMatchInfos()()` Returns a list of `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchInfo`s providing information about how the document in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getGenericDocument()` matched the query. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getPackageName()()` Contains the package name of the app that stored the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument`. |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!>` | `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getParentTypeMap()()` Returns the map from schema type names to the list of their parent types. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getRankingSignal()()` Returns the ranking signal of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument`, according to the ranking strategy set in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec.Builder#setRankingStrategy(int)`. |

## Public functions

### getDatabaseName

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getDatabaseName(): String
```

Contains the database name that stored the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument`.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | Name of the database within which the document is stored |

### getDocument

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun <T> getDocument(documentClass: Class<T!>): T
```

Contains the matching document, converted to the given document class.

This is equivalent to calling `getGenericDocument().toDocumentClass(T.class)`.

Calling this function repeatedly is inefficient. Prefer to retain the object returned by this function, rather than calling it multiple times.

| Parameters |
|---|---|
| `documentClass: https://developer.android.com/reference/java/lang/Class.html<T!>` | the document class to be passed to `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument#toDocumentClass(java.lang.Class<T>)`. |

| Returns |
|---|---|
| `T` | Document object which matched the query. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/exceptions/AppSearchException` | if no factory for this document class could be found on the classpath. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument#toDocumentClass(java.lang.Class<T>)` |   |

### getDocument

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun <T> getDocument(
    documentClass: Class<T!>,
    documentClassMap: (Mutable)Map<String!, (Mutable)List<String!>!>?
): T
```

Contains the matching document, converted to the given document class.

This is equivalent to calling `getGenericDocument().toDocumentClass(T.class, new DocumentClassMappingContext(documentClassMap, getParentTypeMap()))`.

Calling this function repeatedly is inefficient. Prefer to retain the object returned by this function, rather than calling it multiple times.

| Parameters |
|---|---|
| `documentClass: https://developer.android.com/reference/java/lang/Class.html<T!>` | the document class to be passed to `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument#toDocumentClass(java.lang.Class<T>,androidx.appsearch.app.DocumentClassMappingContext)`. |
| `documentClassMap: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!>?` | A map from AppSearch's type name specified by `https://developer.android.com/reference/kotlin/androidx/appsearch/annotation/Document#name()` to the list of the fully qualified names of the corresponding document classes. In most cases, passing the value returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchDocumentClassMap#getGlobalMap()` will be sufficient. |

| Returns |
|---|---|
| `T` | Document object which matched the query. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/exceptions/AppSearchException` | if no factory for this document class could be found on the classpath. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument#toDocumentClass(java.lang.Class<T>,androidx.appsearch.app.DocumentClassMappingContext)` |   |

### getGenericDocument

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getGenericDocument(): GenericDocument
```

Contains the matching `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument`.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument` | Document object which matched the query. |

### getInformationalRankingSignals

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getInformationalRankingSignals(): (Mutable)List<Double!>
```

Returns the informational ranking signals of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument`, according to the expressions added in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec.Builder#addInformationalRankingExpressions(java.lang.String...)`.

### getJoinedResults

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getJoinedResults(): (Mutable)List<SearchResult!>
```

Gets a list of `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` joined from the join operation.

These joined documents match the outer document as specified in the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/JoinSpec` with parentPropertyExpression and childPropertyExpression. They are ordered according to the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/JoinSpec#getNestedSearchSpec()`, and as many SearchResults as specified by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/JoinSpec#getMaxJoinedResultCount()` will be returned. If no `https://developer.android.com/reference/kotlin/androidx/appsearch/app/JoinSpec` was specified, this returns an empty list.

This method is inefficient to call repeatedly, as new `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult` objects are created each time.

| Returns |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult!>` | a List of SearchResults containing joined documents. |

### getMatchInfos

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getMatchInfos(): (Mutable)List<SearchResult.MatchInfo!>
```

Returns a list of `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchInfo`s providing information about how the document in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getGenericDocument()` matched the query.

| Returns |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchInfo!>` | List of matches based on `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec`. If snippeting is disabled using `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec.Builder#setSnippetCount(int)` or `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec.Builder#setSnippetCountPerProperty(int)`, for all results after that value, this method returns an empty list. |

### getPackageName

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getPackageName(): String
```

Contains the package name of the app that stored the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument`.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | Package name that stored the document |

### getParentTypeMap

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
@ExperimentalAppSearchApi
fun getParentTypeMap(): (Mutable)Map<String!, (Mutable)List<String!>!>
```

Returns the map from schema type names to the list of their parent types.

The map includes entries for the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument`'s own type and all of the nested documents' types. Child types are guaranteed to appear before parent types in each list.

Parent types include transitive parents.

Calling this function repeatedly is inefficient. Prefer to retain the Map returned by this function, rather than calling it multiple times.

### getRankingSignal

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getRankingSignal(): Double
```

Returns the ranking signal of the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument`, according to the ranking strategy set in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec.Builder#setRankingStrategy(int)`. The meaning of the ranking signal and its value is determined by the selected ranking strategy:

- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_NONE()` - this value will be 0
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_DOCUMENT_SCORE()` - the value returned by calling `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument#getScore()` on the document returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getGenericDocument()`
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_CREATION_TIMESTAMP()` - the value returned by calling `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument#getCreationTimestampMillis()` on the document returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getGenericDocument()`
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_RELEVANCE_SCORE()` - an arbitrary double value where a higher value means more relevant
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_USAGE_COUNT()` - the number of times usage has been reported for the document returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getGenericDocument()`
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_USAGE_LAST_USED_TIMESTAMP()` - the timestamp of the most recent usage that has been reported for the document returned by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult#getGenericDocument()`

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-double/index.html` | Ranking signal of the document |