# SearchResult.TextMatchInfo

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.TextMatchInfo) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***


```
@ExperimentalAppSearchApi
class SearchResult.TextMatchInfo
```

<br />

*** ** * ** ***

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. Using this class, you can get:

- the full text - all of the text in that String property
- the exact term match - the 'term' (full word) that matched the query
- the subterm match - the portion of the matched term that appears in the query
- a suggested text snippet - a portion of the full text surrounding the exact term match, set to term boundaries. The size of the snippet is specified in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec.Builder#setMaxSnippetSize(int)`

for each text match in the document.

Class Example 1:

A document contains the following text in property "subject":

"A commonly used fake word is foo. Another nonsense word that's used a lot is bar."

If the queryExpression is "foo" and `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#getMaxSnippetSize()` is 10,

- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getFullText()` returns "A commonly used fake word is foo. Another nonsense word that's used a lot is bar."
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getExactMatchRange()` returns \[29, 32\]
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getExactMatch()` returns "foo"
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSubmatchRange()` returns \[29, 32\]
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSubmatch()` returns "foo"
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSnippetRange()` returns \[26, 33\]
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSnippet()` returns "is foo."

Class Example 2:

A document contains one property named "subject" and one property named "sender" which contains a "name" property. In this case, we will have 2 property paths: `sender.name` and `subject`.

Let `sender.name = "Test Name Jr."` and `subject = "Testing 1 2 3"`

If the queryExpression is "Test" with `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#TERM_MATCH_PREFIX()` and `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec#getMaxSnippetSize()` is 10. We will have 2 matches:

Match-1

- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getFullText()` returns "Test Name Jr."
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getExactMatchRange()` returns \[0, 4\]
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getExactMatch()` returns "Test"
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSubmatchRange()` returns \[0, 4\]
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSubmatch()` returns "Test"
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSnippetRange()` returns \[0, 9\]
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSnippet()` returns "Test Name"

Match-2

- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getFullText()` returns "Testing 1 2 3"
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getExactMatchRange()` returns \[0, 7\]
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getExactMatch()` returns "Testing"
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSubmatchRange()` returns \[0, 4\]
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSubmatch()` returns "Test"
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSnippetRange()` returns \[0, 9\]
- `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSnippet()` returns "Testing 1"

## Summary

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#TextMatchInfo(androidx.appsearch.app.SearchResult.MatchRange,androidx.appsearch.app.SearchResult.MatchRange,androidx.appsearch.app.SearchResult.MatchRange)( exactMatchRange: https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange, submatchRange: https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange, snippetRange: https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange )` Creates a new immutable TextMatchInfo. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html` | `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getExactMatch()()` Gets the exact term of the given entry that matched the query. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` | `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getExactMatchRange()()` Gets the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` of the exact term of the given entry that matched the query. |
| `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.TextMatchInfo#getFullText()()` Gets the full text corresponding to the given entry. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html` | `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSnippet()()` Gets the snippet corresponding to the given entry. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` | `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSnippetRange()()` Gets the snippet `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo` corresponding to the given entry. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features.SEARCH_RESULT_MATCH_INFO_SUBMATCH) @https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSubmatch()()` Gets the exact term subsequence of the given entry that matched the query. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features.SEARCH_RESULT_MATCH_INFO_SUBMATCH) @https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo#getSubmatchRange()()` Gets the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` of the exact term subsequence of the given entry that matched the query. |

## Public constructors

### TextMatchInfo

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

```
@ExperimentalAppSearchApi
TextMatchInfo(
    exactMatchRange: SearchResult.MatchRange,
    submatchRange: SearchResult.MatchRange,
    snippetRange: SearchResult.MatchRange
)
```

Creates a new immutable TextMatchInfo.

| Parameters |
|---|---|
| `exactMatchRange: https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` | the exact `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` for the entry. |
| `submatchRange: https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` | the sub-match `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` for the entry. |
| `snippetRange: https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` | the snippet `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` for the entry. |

## Public functions

### getExactMatch

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

```
@ExperimentalAppSearchApi
fun getExactMatch(): CharSequence
```

Gets the exact term of the given entry that matched the query.

Class example 1: this returns "foo".

Class example 2: for the first `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns "Test" and, for the second `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns "Testing".

### getExactMatchRange

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

```
@ExperimentalAppSearchApi
fun getExactMatchRange(): SearchResult.MatchRange
```

Gets the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` of the exact term of the given entry that matched the query.

Class example 1: this returns \[29, 32\].

Class example 2: for the first `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns \[0, 4\] and, for the second `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns \[0, 7\].

### getFullText

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

```
@ExperimentalAppSearchApi
fun getFullText(): String
```

Gets the full text corresponding to the given entry.

Class example 1: this returns "A commonly used fake word is foo. Another nonsense word that's used a lot is bar."

Class example 2: for the first `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns "Test Name Jr." and, for the second `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns "Testing 1 2 3".

### getSnippet

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

```
@ExperimentalAppSearchApi
fun getSnippet(): CharSequence
```

Gets the snippet corresponding to the given entry.

Snippet - Provides a subset of the content to display. Only populated when requested maxSnippetSize \>0. The size of this content can be changed by `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec.Builder#setMaxSnippetSize(int)`. Windowing is centered around the middle of the matched token with content on either side clipped to token boundaries.

Class example 1: this returns "foo. Another".

Class example 2: for the first `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns "Test Name" and, for the second `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns "Testing 1 2 3".

### getSnippetRange

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

```
@ExperimentalAppSearchApi
fun getSnippetRange(): SearchResult.MatchRange
```

Gets the snippet `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo` corresponding to the given entry.

Only populated when set maxSnippetSize \>0 in `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec.Builder#setMaxSnippetSize(int)`.

Class example 1: this returns \[29, 41\].

Class example 2: for the first `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns \[0, 9\] and, for the second `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns \[0, 13\].

### getSubmatch

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

```
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SEARCH_RESULT_MATCH_INFO_SUBMATCH)
@ExperimentalAppSearchApi
fun getSubmatch(): CharSequence
```

Gets the exact term subsequence of the given entry that matched the query.

Class example 1: this returns "foo".

Class example 2: for the first `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns "Test" and, for the second `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns "Test".

This information may not be available depending on the backend and Android API level. To ensure it is available, call `https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features#isFeatureSupported(java.lang.String)`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if `https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features#isFeatureSupported(java.lang.String)` is false. |

### getSubmatchRange

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

```
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SEARCH_RESULT_MATCH_INFO_SUBMATCH)
@ExperimentalAppSearchApi
fun getSubmatchRange(): SearchResult.MatchRange
```

Gets the `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.MatchRange` of the exact term subsequence of the given entry that matched the query.

Class example 1: this returns \[29, 32\].

Class example 2: for the first `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns \[0, 4\] and, for the second `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchResult.TextMatchInfo`, this returns \[0, 4\].

This information may not be available depending on the backend and Android API level. To ensure it is available, call `https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features#isFeatureSupported(java.lang.String)`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if `https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features#isFeatureSupported(java.lang.String)` is false. |