MatchInfo
class MatchInfo : Parcelable
kotlin.Any | |
↳ | android.app.appsearch.SearchResult.MatchInfo |
This class represents match objects for any snippets that might be present in SearchResults
from a 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
android.app.appsearch.SearchSpec.Builder#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 SearchSpec.getMaxSnippetSize
is 10,
MatchInfo.getPropertyPath()
returns "subject"MatchInfo.getFullText()
returns "A commonly used fake word is foo. Another nonsense word that’s used a lot is bar."MatchInfo.getExactMatchRange()
returns [29, 32]MatchInfo.getExactMatch()
returns "foo"MatchInfo.getSubmatchRange()
returns [29, 32]MatchInfo.getSubmatch()
returns "foo"MatchInfo.getSnippetRange()
returns [26, 33]MatchInfo.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 android.app.appsearch.SearchSpec#getMaxSnippetSize
is 10. We will have 2 matches:
Match-1
MatchInfo.getPropertyPath()
returns "sender.name"MatchInfo.getFullText()
returns "Test Name Jr."MatchInfo.getExactMatchRange()
returns [0, 4]MatchInfo.getExactMatch()
returns "Test"MatchInfo.getSubmatchRange()
returns [0, 4]MatchInfo.getSubmatch()
returns "Test"MatchInfo.getSnippetRange()
returns [0, 9]MatchInfo.getSnippet()
returns "Test Name"
Match-2
MatchInfo.getPropertyPath()
returns "subject"MatchInfo.getFullText()
returns "Testing 1 2 3"MatchInfo.getExactMatchRange()
returns [0, 7]MatchInfo.getExactMatch()
returns "Testing"MatchInfo.getSubmatchRange()
returns [0, 4]MatchInfo.getSubmatch()
returns "Test"MatchInfo.getSnippetRange()
returns [0, 9]MatchInfo.getSnippet()
returns "Testing 1"
Summary
Nested classes | |
---|---|
Builder for |
Inherited constants | |
---|---|
Public methods | |
---|---|
CharSequence |
Gets the exact term of the given entry that matched the query. |
SearchResult.MatchRange |
Gets the |
String |
Gets the full text corresponding to the given entry. |
String |
Gets the property path corresponding to the given entry. |
PropertyPath |
Gets a |
CharSequence |
Gets the snippet corresponding to the given entry. |
SearchResult.MatchRange |
Gets the snippet |
CharSequence |
Gets the exact term subsequence of the given entry that matched the query. |
SearchResult.MatchRange |
Gets the |
Unit |
writeToParcel(dest: Parcel, flags: Int) Flatten this object in to a Parcel. |
Properties | |
---|---|
static Parcelable.Creator<SearchResult.MatchInfo!> |
Public methods
getExactMatch
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 MatchInfo
, this returns "Test" and, for the second MatchInfo
, this returns "Testing".
Return | |
---|---|
CharSequence |
This value cannot be null . |
getExactMatchRange
fun getExactMatchRange(): SearchResult.MatchRange
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 MatchInfo
, this returns [0, 4] and, for the second MatchInfo
, this returns [0, 7].
Return | |
---|---|
SearchResult.MatchRange |
This value cannot be null . |
getFullText
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 MatchInfo
, this returns "Test Name Jr." and, for the second MatchInfo
, this returns "Testing 1 2 3".
Return | |
---|---|
String |
This value cannot be null . |
getPropertyPath
fun getPropertyPath(): String
Gets the property path corresponding to the given entry.
A property path is a '.' - delimited sequence of property names indicating which property in the document these snippets correspond to.
Example properties: 'body', 'sender.name', 'sender.emailaddress', etc. For class example 1 this returns "subject"
Return | |
---|---|
String |
This value cannot be null . |
getPropertyPathObject
fun getPropertyPathObject(): PropertyPath
Gets a PropertyPath
object representing the property path corresponding to the given entry.
Methods such as GenericDocument.getPropertyDocument
accept a path as a string rather than a PropertyPath
object. However, you may want to manipulate the path before getting a property document. This method returns a PropertyPath
rather than a String for easier path manipulation, which can then be converted to a String.
Return | |
---|---|
PropertyPath |
This value cannot be null . |
getSnippet
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 android.app.appsearch.SearchSpec.Builder#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 MatchInfo
, this returns "Test Name" and, for the second MatchInfo
, this returns "Testing 1 2 3".
Return | |
---|---|
CharSequence |
This value cannot be null . |
getSnippetRange
fun getSnippetRange(): SearchResult.MatchRange
Gets the snippet MatchRange
corresponding to the given entry.
Only populated when set maxSnippetSize > 0 in android.app.appsearch.SearchSpec.Builder#setMaxSnippetSize
.
Class example 1: this returns [29, 41].
Class example 2: for the first MatchInfo
, this returns [0, 9] and, for the second MatchInfo
, this returns [0, 13].
Return | |
---|---|
SearchResult.MatchRange |
This value cannot be null . |
getSubmatch
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 MatchInfo
, this returns "Test" and, for the second MatchInfo
, this returns "Test".
Return | |
---|---|
CharSequence |
This value cannot be null . |
getSubmatchRange
fun getSubmatchRange(): SearchResult.MatchRange
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 MatchInfo
, this returns [0, 4] and, for the second MatchInfo
, this returns [0, 4].
Return | |
---|---|
SearchResult.MatchRange |
This value cannot be null . |
writeToParcel
fun writeToParcel(
dest: Parcel,
flags: Int
): Unit
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_WRITE_RETURN_VALUE . Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE , and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |
Properties
CREATOR
static val CREATOR: Parcelable.Creator<SearchResult.MatchInfo!>