SearchResult.TextMatchInfo
public
static
final
class
SearchResult.TextMatchInfo
extends Object
implements
Parcelable
| java.lang.Object | |
| ↳ | android.app.appsearch.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
SearchSpec.Builder.setMaxSnippetSize(int)
Class Example 1:
A document contains the following text in property "subject":
"A commonly used fake word is foo. Another nonsense word that\u2019s used a lot is bar."
If the queryExpression is "foo" and SearchSpec.getMaxSnippetSize is 10,
TextMatchInfo.getFullText()returns "A commonly used fake word is foo. Another nonsense word that\u2019s used a lot is bar."TextMatchInfo.getExactMatchRange()returns [29, 32]TextMatchInfo.getExactMatch()returns "foo"TextMatchInfo.getSubmatchRange()returns [29, 32]TextMatchInfo.getSubmatch()returns "foo"TextMatchInfo.getSnippetRange()returns [26, 33]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 SearchSpec.TERM_MATCH_PREFIX and SearchSpec.getMaxSnippetSize() is 10. We will have 2 matches:
Match-1
TextMatchInfo.getFullText()returns "Test Name Jr."TextMatchInfo.getExactMatchRange()returns [0, 4]TextMatchInfo.getExactMatch()returns "Test"TextMatchInfo.getSubmatchRange()returns [0, 4]TextMatchInfo.getSubmatch()returns "Test"TextMatchInfo.getSnippetRange()returns [0, 9]TextMatchInfo.getSnippet()returns "Test Name"
Match-2
TextMatchInfo.getFullText()returns "Testing 1 2 3"TextMatchInfo.getExactMatchRange()returns [0, 7]TextMatchInfo.getExactMatch()returns "Testing"TextMatchInfo.getSubmatchRange()returns [0, 4]TextMatchInfo.getSubmatch()returns "Test"TextMatchInfo.getSnippetRange()returns [0, 9]TextMatchInfo.getSnippet()returns "Testing 1"
Summary
Inherited constants |
|---|
Fields | |
|---|---|
public
static
final
Creator<SearchResult.TextMatchInfo> |
CREATOR
|
Public constructors | |
|---|---|
TextMatchInfo(SearchResult.MatchRange exactMatchRange, SearchResult.MatchRange submatchRange, SearchResult.MatchRange snippetRange)
Creates a new immutable TextMatchInfo. |
|
Public methods | |
|---|---|
CharSequence
|
getExactMatch()
Gets the exact term of the given entry that matched the query. |
SearchResult.MatchRange
|
getExactMatchRange()
Gets the |
String
|
getFullText()
Gets the full text corresponding to the given entry. |
CharSequence
|
getSnippet()
Gets the snippet corresponding to the given entry. |
SearchResult.MatchRange
|
getSnippetRange()
Gets the snippet |
CharSequence
|
getSubmatch()
Gets the exact term subsequence of the given entry that matched the query. |
SearchResult.MatchRange
|
getSubmatchRange()
Gets the |
void
|
writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel. |
Inherited methods | |
|---|---|
Fields
CREATOR
public static final Creator<SearchResult.TextMatchInfo> CREATOR
Public constructors
TextMatchInfo
public TextMatchInfo (SearchResult.MatchRange exactMatchRange, SearchResult.MatchRange submatchRange, SearchResult.MatchRange snippetRange)
Creates a new immutable TextMatchInfo.
| Parameters | |
|---|---|
exactMatchRange |
SearchResult.MatchRange: the exact MatchRange for the entry.
This value cannot be null. |
submatchRange |
SearchResult.MatchRange: the sub-match MatchRange for the entry.
This value cannot be null. |
snippetRange |
SearchResult.MatchRange: the snippet MatchRange for the entry.
This value cannot be null. |
Public methods
getExactMatch
public 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".
| Returns | |
|---|---|
CharSequence |
This value cannot be null. |
getExactMatchRange
public 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].
| Returns | |
|---|---|
SearchResult.MatchRange |
This value cannot be null. |
getFullText
public 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".
| Returns | |
|---|---|
String |
This value cannot be null. |
getSnippet
public 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 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 TextMatchInfo, this returns "Test Name" and,
for the second TextMatchInfo, this returns "Testing 1 2 3".
| Returns | |
|---|---|
CharSequence |
This value cannot be null. |
getSnippetRange
public SearchResult.MatchRange getSnippetRange ()
Gets the snippet TextMatchInfo corresponding to the given entry.
Only populated when set maxSnippetSize > 0 in SearchSpec.Builder.setMaxSnippetSize(int).
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].
| Returns | |
|---|---|
SearchResult.MatchRange |
This value cannot be null. |
getSubmatch
public 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".
| Returns | |
|---|---|
CharSequence |
This value cannot be null. |
getSubmatchRange
public 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].
| Returns | |
|---|---|
SearchResult.MatchRange |
This value cannot be null. |
writeToParcel
public void writeToParcel (Parcel dest, int flags)
Flatten this object in to a Parcel.
| Parameters | |
|---|---|
dest |
Parcel: This value cannot be null. |
flags |
int: Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE.
Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |