SearchResult
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 |
|---|
class SearchResult.BuilderBuilder for |
|
This class represents match objects for any snippets that might be present in |
class SearchResult.MatchInfoThis class represents match objects for any snippets that might be present in |
|
Builder for |
class SearchResult.MatchRangeClass providing the position range of a text match information. |
|
This class represents match objects for any text match snippets that might be present in |
Public functions |
|
|---|---|
String |
Contains the database name that stored the |
T |
<T> getDocument(documentClass: Class<T!>)Contains the matching document, converted to the given document class. |
T |
<T> getDocument(Contains the matching document, converted to the given document class. |
GenericDocument |
Contains the matching |
(Mutable)List<Double!> |
Returns the informational ranking signals of the |
(Mutable)List<SearchResult!> |
Gets a list of |
(Mutable)List<SearchResult.MatchInfo!> |
Returns a list of |
String |
Contains the package name of the app that stored the |
(Mutable)Map<String!, (Mutable)List<String!>!> |
Returns the map from schema type names to the list of their parent types. |
Double |
Returns the ranking signal of the |
Public functions
getDatabaseName
fun getDatabaseName(): String
Contains the database name that stored the GenericDocument.
| Returns | |
|---|---|
String |
Name of the database within which the document is stored |
getDocument
fun <T> getDocument(documentClass: Class<T!>): T
Contains the matching document, converted to the given document class.
This is equivalent to calling getGenericDocument().toDocumentClass(T.class).
Calling this function repeatedly is inefficient. Prefer to retain the object returned by this function, rather than calling it multiple times.
| Parameters | |
|---|---|
documentClass: Class<T!> |
the document class to be passed to |
| Returns | |
|---|---|
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 | |
|---|---|
toDocumentClass |
getDocument
fun <T> getDocument(
documentClass: Class<T!>,
documentClassMap: (Mutable)Map<String!, (Mutable)List<String!>!>?
): T
Contains the matching document, converted to the given document class.
This is equivalent to calling getGenericDocument().toDocumentClass(T.class,
new DocumentClassMappingContext(documentClassMap, getParentTypeMap())).
Calling this function repeatedly is inefficient. Prefer to retain the object returned by this function, rather than calling it multiple times.
| Parameters | |
|---|---|
documentClass: Class<T!> |
the document class to be passed to |
documentClassMap: (Mutable)Map<String!, (Mutable)List<String!>!>? |
A map from AppSearch's type name specified by |
| Returns | |
|---|---|
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 | |
|---|---|
toDocumentClass |
getGenericDocument
fun getGenericDocument(): GenericDocument
Contains the matching GenericDocument.
| Returns | |
|---|---|
GenericDocument |
Document object which matched the query. |
getInformationalRankingSignals
fun getInformationalRankingSignals(): (Mutable)List<Double!>
Returns the informational ranking signals of the GenericDocument, according to the expressions added in addInformationalRankingExpressions.
getJoinedResults
fun getJoinedResults(): (Mutable)List<SearchResult!>
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 | |
|---|---|
(Mutable)List<SearchResult!> |
a List of SearchResults containing joined documents. |
getMatchInfos
fun getMatchInfos(): (Mutable)List<SearchResult.MatchInfo!>
Returns a list of MatchInfos providing information about how the document in getGenericDocument matched the query.
| Returns | |
|---|---|
(Mutable)List<SearchResult.MatchInfo!> |
List of matches based on |
getPackageName
fun getPackageName(): String
Contains the package name of the app that stored the GenericDocument.
| Returns | |
|---|---|
String |
Package name that stored the document |
getParentTypeMap
@ExperimentalAppSearchApi
fun getParentTypeMap(): (Mutable)Map<String!, (Mutable)List<String!>!>
Returns the map from schema type names to the list of their parent types.
The map includes entries for the GenericDocument's own type and all of the nested documents' types. Child types are guaranteed to appear before parent types in each list.
Parent types include transitive parents.
Calling this function repeatedly is inefficient. Prefer to retain the Map returned by this function, rather than calling it multiple times.
getRankingSignal
fun getRankingSignal(): Double
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:
RANKING_STRATEGY_NONE- this value will be 0RANKING_STRATEGY_DOCUMENT_SCORE- the value returned by callinggetScoreon the document returned bygetGenericDocumentRANKING_STRATEGY_CREATION_TIMESTAMP- the value returned by callinggetCreationTimestampMillison the document returned bygetGenericDocumentRANKING_STRATEGY_RELEVANCE_SCORE- an arbitrary double value where a higher value means more relevantRANKING_STRATEGY_USAGE_COUNT- the number of times usage has been reported for the document returned bygetGenericDocumentRANKING_STRATEGY_USAGE_LAST_USED_TIMESTAMP- the timestamp of the most recent usage that has been reported for the document returned bygetGenericDocument
| Returns | |
|---|---|
Double |
Ranking signal of the document |