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"

getSubmatchRange() returns [29, 32]

getSubmatch() 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"

getSubmatchRange() returns [0, 4]

getSubmatch() 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"

getSubmatchRange() returns [0, 4]

getSubmatch() returns "Test"

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 exact term of the given entry that matched the query.

SearchResult.MatchRange getExactMatchRange()

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

String getFullText()

Gets the full text corresponding to the given entry.

String getPropertyPath()

Gets the property path corresponding to the given entry.