SearchResult.MatchInfo

public static final class SearchResult.MatchInfo
extends Object

java.lang.Object
   ↳ androidx.appsearch.app.SearchResult.MatchInfo


This class represents a match objects for any Snippets that might be present in SearchResults from query. Using this class user can get the full text, exact matches and Snippets of document content for a given match.

Class Example 1: A document contains 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".

getPropertyPath() returns "subject"

getFullText() returns "A commonly used fake word is foo. Another nonsense word that’s used a lot is bar."

getExactMatchRange() returns [29, 32]

getExactMatch() returns "foo"

getSnippetRange() returns [26, 33]

getSnippet() returns "is foo."

Class Example 2: A document contains a property name sender which contains 2 property names name and email, so we will have 2 property paths: sender.name and sender.email.

Let sender.name = "Test Name Jr." and sender.email = "TestNameJr@gmail.com"

If the queryExpression is "Test". We will have 2 matches.

Match-1

getPropertyPath() returns "sender.name"

getFullText() returns "Test Name Jr."

getExactMatchRange() returns [0, 4]

getExactMatch() returns "Test"

getSnippetRange() returns [0, 9]

getSnippet() returns "Test Name"

Match-2

getPropertyPath() returns "sender.email"

getFullText() returns "TestNameJr@gmail.com"

getExactMatchRange() returns [0, 20]

getExactMatch() returns "TestNameJr@gmail.com"

getSnippetRange() returns [0, 20]

getSnippet() returns "TestNameJr@gmail.com"

Summary

Nested classes

class SearchResult.MatchInfo.Builder

Builder for SearchResult.MatchInfo objects. 

Public methods

CharSequence getExactMatch()

Gets the SearchResult.MatchRange corresponding to the given entry.

SearchResult.MatchRange getExactMatchRange()

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

String getFullText()

Gets the full text corresponding to the given entry.

String getPropertyPath()

Gets the property path corresponding to the given entry.

CharSequence getSnippet()

Gets the snippet corresponding to the given entry.

SearchResult.MatchRange getSnippetRange()

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

Inherited methods

Public methods

getExactMatch

public CharSequence getExactMatch ()

Gets the SearchResult.MatchRange corresponding to the given entry.

For class example 1 this returns "foo"

Returns
CharSequence

getExactMatchRange

public SearchResult.MatchRange getExactMatchRange ()

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

For class example 1 this returns [29, 32]

Returns
SearchResult.MatchRange

getFullText

public String getFullText ()

Gets the full text corresponding to the given entry.

For class example this returns "A commonly used fake word is foo. Another nonsense word that's used a lot is bar."

Returns
String

getPropertyPath

public 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"

Returns
String

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.

For class example 1 this returns "foo. Another"

Returns
CharSequence

getSnippetRange

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).

For class example 1 this returns [29, 41].

Returns
SearchResult.MatchRange