public final class

SearchResult.MatchInfo

extends AbstractSafeParcelable

 java.lang.Object

androidx.appsearch.safeparcel.AbstractSafeParcelable

↳androidx.appsearch.app.SearchResult.MatchInfo

Overview

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 SearchSpec.Builder.setMaxSnippetSize(int)
for each 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 SearchSpec.getMaxSnippetSize() is 10,

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

Match-2

Summary

Fields
public static final <any>CREATOR

Methods
public java.lang.CharSequencegetExactMatch()

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

public SearchResult.MatchRangegetExactMatchRange()

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

public java.lang.StringgetFullText()

Gets the full text corresponding to the given entry.

public java.lang.StringgetPropertyPath()

Gets the property path corresponding to the given entry.

public PropertyPathgetPropertyPathObject()

Gets a PropertyPath object representing the property path corresponding to the given entry.

public java.lang.CharSequencegetSnippet()

Gets the snippet corresponding to the given entry.

public SearchResult.MatchRangegetSnippetRange()

Gets the snippet SearchResult.MatchRange corresponding to the given entry.

public java.lang.CharSequencegetSubmatch()

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

public SearchResult.MatchRangegetSubmatchRange()

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

public voidwriteToParcel(Parcel dest, int flags)

To be implemented by child classes.

from AbstractSafeParcelabledescribeContents
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final <any> CREATOR

Methods

public java.lang.String getPropertyPath()

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"

public PropertyPath getPropertyPathObject()

Gets a PropertyPath object representing the property path corresponding to the given entry.

Methods such as GenericDocument.getPropertyDocument(String) 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.

See also: SearchResult.MatchInfo.getPropertyPath(), PropertyPath

public java.lang.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 SearchResult.MatchInfo, this returns "Test Name Jr." and, for the second SearchResult.MatchInfo, this returns "Testing 1 2 3".

public SearchResult.MatchRange getExactMatchRange()

Gets the 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 SearchResult.MatchInfo, this returns [0, 4] and, for the second SearchResult.MatchInfo, this returns [0, 7].

public java.lang.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 SearchResult.MatchInfo, this returns "Test" and, for the second SearchResult.MatchInfo, this returns "Testing".

public SearchResult.MatchRange getSubmatchRange()

Gets the 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 SearchResult.MatchInfo, this returns [0, 4] and, for the second SearchResult.MatchInfo, this returns [0, 4].

This information may not be available depending on the backend and Android API level. To ensure it is available, call Features.isFeatureSupported(String).

public java.lang.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 SearchResult.MatchInfo, this returns "Test" and, for the second SearchResult.MatchInfo, this returns "Test".

This information may not be available depending on the backend and Android API level. To ensure it is available, call Features.isFeatureSupported(String).

public SearchResult.MatchRange getSnippetRange()

Gets the snippet SearchResult.MatchRange 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 SearchResult.MatchInfo, this returns [0, 9] and, for the second SearchResult.MatchInfo, this returns [0, 13].

public java.lang.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 SearchResult.MatchInfo, this returns "Test Name" and, for the second SearchResult.MatchInfo, this returns "Testing 1 2 3".

public void writeToParcel(Parcel dest, int flags)

To be implemented by child classes.

This is purely for code sync purpose. Have writeToParcel here so we can keep "@Override" in child classes.