SearchResult

public final class SearchResult
extends Object

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


This class represents one of the results obtained from an AppSearch query.

This allows clients to obtain:

  • The document which matched, using getGenericDocument()
  • Information about which properties in the document matched, and "snippet" information containing textual summaries of the document's matches, using getMatches()

"Snippet" refers to a substring of text from the content of document that is returned as a part of search result.

See also:

Summary

Nested classes

class SearchResult.Builder

Builder for SearchResult objects. 

class SearchResult.MatchInfo

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

class SearchResult.MatchRange

Class providing the position range of matching information. 

Public methods

String getDatabaseName()

Contains the database name that stored the GenericDocument.

<T> T getDocument(Class<T> documentClass)

Contains the matching document, converted to the given document class.

GenericDocument getGenericDocument()

Contains the matching GenericDocument.

List<SearchResult.MatchInfo> getMatches()

Contains a list of Snippets that matched the request.

String getPackageName()

Contains the package name of the app that stored the GenericDocument.

double getRankingSignal()

Returns the ranking signal of the GenericDocument, according to the ranking strategy set in SearchSpec.Builder.setRankingStrategy(int).

Inherited methods

Public methods

getDatabaseName

public String getDatabaseName ()

Contains the database name that stored the GenericDocument.

Returns
String Name of the database within which the document is stored

getDocument

public T getDocument (Class<T> documentClass)

Contains the matching document, converted to the given document class.

This is equivalent to calling getGenericDocument().toDocumentClass(T.class).

Parameters
documentClass Class

Returns
T Document object which matched the query.

Throws
AppSearchException if no factory for this document class could be found on the classpath.

getGenericDocument

public GenericDocument getGenericDocument ()

Contains the matching GenericDocument.

Returns
GenericDocument Document object which matched the query.

getMatches

public List<SearchResult.MatchInfo> getMatches ()

Contains a list of Snippets that matched the request.

Returns
List<SearchResult.MatchInfo> List of matches based on SearchSpec. If snippeting is disabled using SearchSpec.Builder.setSnippetCount(int) or SearchSpec.Builder.setSnippetCountPerProperty(int), for all results after that value, this method returns an empty list.

getPackageName

public String getPackageName ()

Contains the package name of the app that stored the GenericDocument.

Returns
String Package name that stored the document

getRankingSignal

public double getRankingSignal ()

Returns the ranking signal of the GenericDocument, according to the ranking strategy set in SearchSpec.Builder.setRankingStrategy(int). The meaning of the ranking signal and its value is determined by the selected ranking strategy:

Returns
double Ranking signal of the document