SearchResult.TextMatchInfo
@ExperimentalAppSearchApi
public final class SearchResult.TextMatchInfo
This class represents match objects for any text match snippets that might be present in 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
setMaxSnippetSize
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 getMaxSnippetSize is 10,
getFullTextreturns "A commonly used fake word is foo. Another nonsense word that’s used a lot is bar."getExactMatchRangereturns [29, 32]getExactMatchreturns "foo"getSubmatchRangereturns [29, 32]getSubmatchreturns "foo"getSnippetRangereturns [26, 33]getSnippetreturns "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 TERM_MATCH_PREFIX and getMaxSnippetSize is 10. We will have 2 matches:
Match-1
getFullTextreturns "Test Name Jr."getExactMatchRangereturns [0, 4]getExactMatchreturns "Test"getSubmatchRangereturns [0, 4]getSubmatchreturns "Test"getSnippetRangereturns [0, 9]getSnippetreturns "Test Name"
Match-2
getFullTextreturns "Testing 1 2 3"getExactMatchRangereturns [0, 7]getExactMatchreturns "Testing"getSubmatchRangereturns [0, 4]getSubmatchreturns "Test"getSnippetRangereturns [0, 9]getSnippetreturns "Testing 1"
Summary
Public constructors |
|---|
@ExperimentalAppSearchApiCreates a new immutable TextMatchInfo. |
Public methods |
|
|---|---|
@NonNull CharSequence |
Gets the exact term of the given entry that matched the query. |
@NonNull SearchResult.MatchRange |
Gets the |
@NonNull String |
Gets the full text corresponding to the given entry. |
@NonNull CharSequence |
Gets the snippet corresponding to the given entry. |
@NonNull SearchResult.MatchRange |
Gets the snippet |
@NonNull CharSequence |
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SEARCH_RESULT_MATCH_INFO_SUBMATCH)Gets the exact term subsequence of the given entry that matched the query. |
@NonNull SearchResult.MatchRange |
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SEARCH_RESULT_MATCH_INFO_SUBMATCH)Gets the |
Public constructors
TextMatchInfo
@ExperimentalAppSearchApi
public TextMatchInfo(
@NonNull SearchResult.MatchRange exactMatchRange,
@NonNull SearchResult.MatchRange submatchRange,
@NonNull SearchResult.MatchRange snippetRange
)
Creates a new immutable TextMatchInfo.
| Parameters | |
|---|---|
@NonNull SearchResult.MatchRange exactMatchRange |
the exact |
@NonNull SearchResult.MatchRange submatchRange |
the sub-match |
@NonNull SearchResult.MatchRange snippetRange |
the snippet |
Public methods
getExactMatch
@ExperimentalAppSearchApi
public @NonNull CharSequence getExactMatch()
Gets the exact term of the given entry that matched the query.
Class example 1: this returns "foo".
Class example 2: for the first TextMatchInfo, this returns "Test" and, for the second TextMatchInfo, this returns "Testing".
getExactMatchRange
@ExperimentalAppSearchApi
public @NonNull SearchResult.MatchRange getExactMatchRange()
Gets the 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 TextMatchInfo, this returns [0, 4] and, for the second TextMatchInfo, this returns [0, 7].
getFullText
@ExperimentalAppSearchApi
public @NonNull String getFullText()
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 TextMatchInfo, this returns "Test Name Jr." and, for the second TextMatchInfo, this returns "Testing 1 2 3".
getSnippet
@ExperimentalAppSearchApi
public @NonNull CharSequence getSnippet()
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 setMaxSnippetSize. 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 TextMatchInfo, this returns "Test Name" and, for the second TextMatchInfo, this returns "Testing 1 2 3".
getSnippetRange
@ExperimentalAppSearchApi
public @NonNull SearchResult.MatchRange getSnippetRange()
Gets the snippet TextMatchInfo corresponding to the given entry.
Only populated when set maxSnippetSize >0 in setMaxSnippetSize.
Class example 1: this returns [29, 41].
Class example 2: for the first TextMatchInfo, this returns [0, 9] and, for the second TextMatchInfo, this returns [0, 13].
getSubmatch
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SEARCH_RESULT_MATCH_INFO_SUBMATCH)
@ExperimentalAppSearchApi
public @NonNull CharSequence getSubmatch()
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 TextMatchInfo, this returns "Test" and, for the second TextMatchInfo, this returns "Test".
This information may not be available depending on the backend and Android API level. To ensure it is available, call isFeatureSupported.
| Throws | |
|---|---|
java.lang.UnsupportedOperationException |
if |
getSubmatchRange
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SEARCH_RESULT_MATCH_INFO_SUBMATCH)
@ExperimentalAppSearchApi
public @NonNull SearchResult.MatchRange getSubmatchRange()
Gets the 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 TextMatchInfo, this returns [0, 4] and, for the second 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 isFeatureSupported.
| Throws | |
|---|---|
java.lang.UnsupportedOperationException |
if |