SearchResult.MatchInfo


public final class SearchResult.MatchInfo


This class represents match objects for any snippets that might be present in SearchResults from a query.

A MatchInfo contains either a TextMatchInfo representing a text match snippet, or an EmbeddingMatchInfo representing an embedding match snippet.

Summary

Nested types

Builder for MatchInfo objects.

Public methods

@Nullable SearchResult.EmbeddingMatchInfo

Retrieves the embedding-based match information.

@NonNull CharSequence

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

@NonNull SearchResult.MatchRange

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

@NonNull String

Gets the full text corresponding to the given entry.

@NonNull String

Gets the property path corresponding to the given entry.

@NonNull PropertyPath

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

@NonNull CharSequence

Gets the snippet corresponding to the given entry.

@NonNull SearchResult.MatchRange

Gets the snippet MatchRange corresponding to the given entry.

@NonNull CharSequence
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SEARCH_RESULT_MATCH_INFO_SUBMATCH)
getSubmatch()

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)
getSubmatchRange()

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

@Nullable SearchResult.TextMatchInfo

Retrieves the text-based match information.

Public methods

getEmbeddingMatch

Added in 1.1.0-rc01
@ExperimentalAppSearchApi
public @Nullable SearchResult.EmbeddingMatchInfo getEmbeddingMatch()

Retrieves the embedding-based match information. Only populated when shouldRetrieveEmbeddingMatchInfos is true.

Returns
@Nullable SearchResult.EmbeddingMatchInfo

A EmbeddingMatchInfo instance, or null if the match is not an embedding match.

getExactMatch

Added in 1.1.0-rc01
public @NonNull CharSequence getExactMatch()

Gets the exact term of the given entry that matched the query. Returns an empty CharSequence if the match is not text-based.

getExactMatchRange

Added in 1.1.0-rc01
public @NonNull SearchResult.MatchRange getExactMatchRange()

Gets the MatchRange of the exact term of the given entry that matched the query. Returns [0, 0] if the match is not text-based.

getFullText

Added in 1.1.0-rc01
public @NonNull String getFullText()

Gets the full text corresponding to the given entry. Returns an empty string if the match is not text-based.

getPropertyPath

Added in 1.1.0-rc01
public @NonNull 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"

getPropertyPathObject

Added in 1.1.0-rc01
public @NonNull PropertyPath getPropertyPathObject()

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

Methods such as 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.

getSnippet

Added in 1.1.0-rc01
public @NonNull CharSequence getSnippet()

Gets the snippet corresponding to the given entry. Returns an empty CharSequence if the match is not text-based.

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.

getSnippetRange

Added in 1.1.0-rc01
public @NonNull SearchResult.MatchRange getSnippetRange()

Gets the snippet MatchRange corresponding to the given entry. Returns [0,0] if the match is not text-based.

Only populated when set maxSnippetSize >0 in setMaxSnippetSize.

getSubmatch

Added in 1.1.0-rc01
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SEARCH_RESULT_MATCH_INFO_SUBMATCH)
public @NonNull CharSequence getSubmatch()

Gets the exact term subsequence of the given entry that matched the query. Returns an empty CharSequence if the match is not text-based.

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

getSubmatchRange

Added in 1.1.0-rc01
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SEARCH_RESULT_MATCH_INFO_SUBMATCH)
public @NonNull SearchResult.MatchRange getSubmatchRange()

Gets the MatchRange of the submatch term subsequence of the given entry that matched the query. Returns [0, 0] if the match is not text-based.

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

getTextMatch

Added in 1.1.0-rc01
@ExperimentalAppSearchApi
public @Nullable SearchResult.TextMatchInfo getTextMatch()

Retrieves the text-based match information.

Returns
@Nullable SearchResult.TextMatchInfo

A TextMatchInfo instance, or null if the match is not text-based.