SearchResult


public final class 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 getMatchInfos

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

See also
SearchResults

Summary

Nested types

public final class SearchResult.Builder

Builder for SearchResult objects.

public final class SearchResult.MatchInfo

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

Builder for MatchInfo objects.

public final class SearchResult.MatchRange

Class providing the position range of matching information.

Public methods

@NonNull String

Contains the database name that stored the GenericDocument.

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

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

@NonNull T
<T> getDocument(
    @NonNull Class<T> documentClass,
    @Nullable Map<StringList<String>> documentClassMap
)

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

@NonNull GenericDocument

Contains the matching GenericDocument.

@NonNull List<Double>

Returns the informational ranking signals of the GenericDocument, according to the expressions added in addInformationalRankingExpressions.

@NonNull List<SearchResult>

Gets a list of SearchResult joined from the join operation.

@NonNull List<SearchResult.MatchInfo>

Returns a list of MatchInfos providing information about how the document in getGenericDocument matched the query.

@NonNull String

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

double

Returns the ranking signal of the GenericDocument, according to the ranking strategy set in setRankingStrategy.

Public methods

getDatabaseName

Added in 1.1.0-alpha06
public @NonNull String getDatabaseName()

Contains the database name that stored the GenericDocument.

Returns
@NonNull String

Name of the database within which the document is stored

getDocument

Added in 1.1.0-alpha06
public @NonNull T <T> getDocument(@NonNull Class<T> documentClass)

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

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

Parameters
@NonNull Class<T> documentClass

the document class to be passed to toDocumentClass.

Returns
@NonNull T

Document object which matched the query.

Throws
androidx.appsearch.exceptions.AppSearchException

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

See also
GenericDocument

getDocument

Added in 1.1.0-alpha06
public @NonNull T <T> getDocument(
    @NonNull Class<T> documentClass,
    @Nullable Map<StringList<String>> documentClassMap
)

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

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

Parameters
@NonNull Class<T> documentClass

the document class to be passed to toDocumentClass.

@Nullable Map<StringList<String>> documentClassMap

the document class map to be passed to toDocumentClass.

Returns
@NonNull T

Document object which matched the query.

Throws
androidx.appsearch.exceptions.AppSearchException

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

See also
GenericDocument

getGenericDocument

Added in 1.1.0-alpha06
public @NonNull GenericDocument getGenericDocument()

Contains the matching GenericDocument.

Returns
@NonNull GenericDocument

Document object which matched the query.

getInformationalRankingSignals

Added in 1.1.0-alpha06
public @NonNull List<DoublegetInformationalRankingSignals()

Returns the informational ranking signals of the GenericDocument, according to the expressions added in addInformationalRankingExpressions.

getJoinedResults

Added in 1.1.0-alpha06
public @NonNull List<SearchResultgetJoinedResults()

Gets a list of SearchResult joined from the join operation.

These joined documents match the outer document as specified in the JoinSpec with parentPropertyExpression and childPropertyExpression. They are ordered according to the getNestedSearchSpec, and as many SearchResults as specified by getMaxJoinedResultCount will be returned. If no JoinSpec was specified, this returns an empty list.

This method is inefficient to call repeatedly, as new SearchResult objects are created each time.

Returns
@NonNull List<SearchResult>

a List of SearchResults containing joined documents.

getMatchInfos

Added in 1.1.0-alpha06
public @NonNull List<SearchResult.MatchInfogetMatchInfos()

Returns a list of MatchInfos providing information about how the document in getGenericDocument matched the query.

Returns
@NonNull List<SearchResult.MatchInfo>

List of matches based on SearchSpec. If snippeting is disabled using setSnippetCount or setSnippetCountPerProperty, for all results after that value, this method returns an empty list.

getPackageName

Added in 1.1.0-alpha06
public @NonNull String getPackageName()

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

Returns
@NonNull String

Package name that stored the document

getRankingSignal

Added in 1.1.0-alpha06
public double getRankingSignal()

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

Returns
double

Ranking signal of the document