# 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 />

```
public final 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/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/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/androidx/appsearch/app/SearchResults` |   |

## Summary

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

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

## Public methods

### getDatabaseName

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

```
public @NonNull String getDatabaseName()
```

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.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)

```
public @NonNull T <T> getDocument(@NonNull Class<T> documentClass)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<T> documentClass` | the document class to be passed to `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument#toDocumentClass(java.lang.Class<T>)`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T` | Document object which matched the query. |

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

| See also |
|---|---|
| `https://developer.android.com/reference/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)

```
public @NonNull T <T> getDocument(
    @NonNull Class<T> documentClass,
    @Nullable Map<String, List<String>> documentClassMap
)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<T> documentClass` | the document class to be passed to `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument#toDocumentClass(java.lang.Class<T>,androidx.appsearch.app.DocumentClassMappingContext)`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html>> documentClassMap` | A map from AppSearch's type name specified by `https://developer.android.com/reference/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/androidx/appsearch/app/AppSearchDocumentClassMap#getGlobalMap()` will be sufficient. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T` | Document object which matched the query. |

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

| See also |
|---|---|
| `https://developer.android.com/reference/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)

```
public @NonNull GenericDocument getGenericDocument()
```

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/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)

```
public @NonNull List<Double> getInformationalRankingSignals()
```

Returns the informational ranking signals of the `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument`, according to the expressions added in `https://developer.android.com/reference/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)

```
public @NonNull List<SearchResult> getJoinedResults()
```

Gets a list of `https://developer.android.com/reference/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/androidx/appsearch/app/JoinSpec` with parentPropertyExpression and childPropertyExpression. They are ordered according to the `https://developer.android.com/reference/androidx/appsearch/app/JoinSpec#getNestedSearchSpec()`, and as many SearchResults as specified by `https://developer.android.com/reference/androidx/appsearch/app/JoinSpec#getMaxJoinedResultCount()` will be returned. If no `https://developer.android.com/reference/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/androidx/appsearch/app/SearchResult` objects are created each time.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/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)

```
public @NonNull List<SearchResult.MatchInfo> getMatchInfos()
```

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/appsearch/app/SearchResult.MatchInfo>` | List of matches based on `https://developer.android.com/reference/androidx/appsearch/app/SearchSpec`. If snippeting is disabled using `https://developer.android.com/reference/androidx/appsearch/app/SearchSpec.Builder#setSnippetCount(int)` or `https://developer.android.com/reference/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)

```
public @NonNull String getPackageName()
```

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.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
public @NonNull Map<String, List<String>> getParentTypeMap()
```

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/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)

```
public double getRankingSignal()
```

Returns the ranking signal of the `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument`, according to the ranking strategy set in `https://developer.android.com/reference/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/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_NONE()` - this value will be 0
- `https://developer.android.com/reference/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_DOCUMENT_SCORE()` - the value returned by calling `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument#getScore()` on the document returned by `https://developer.android.com/reference/androidx/appsearch/app/SearchResult#getGenericDocument()`
- `https://developer.android.com/reference/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_CREATION_TIMESTAMP()` - the value returned by calling `https://developer.android.com/reference/androidx/appsearch/app/GenericDocument#getCreationTimestampMillis()` on the document returned by `https://developer.android.com/reference/androidx/appsearch/app/SearchResult#getGenericDocument()`
- `https://developer.android.com/reference/androidx/appsearch/app/SearchSpec#RANKING_STRATEGY_RELEVANCE_SCORE()` - an arbitrary double value where a higher value means more relevant
- `https://developer.android.com/reference/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/androidx/appsearch/app/SearchResult#getGenericDocument()`
- `https://developer.android.com/reference/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/androidx/appsearch/app/SearchResult#getGenericDocument()`

| Returns |
|---|---|
| `double` | Ranking signal of the document |