SearchSpec
public final class SearchSpec
This class represents the specification logic for AppSearch. It can be used to set the type of search, like prefix or exact only or apply filters to search for a specific schema type only etc.
Summary
Nested types |
|---|
public final class SearchSpec.BuilderBuilder for |
Constants |
|
|---|---|
static final int |
Cosine similarity as metric for embedding search and ranking. |
static final int |
Use the default metric set in |
static final int |
Dot product similarity as metric for embedding search and ranking. |
static final int |
Euclidean distance as metric for embedding search and ranking. |
static final int |
Results should be grouped together by namespace for the purpose of enforcing a limit on the number of results returned per namespace. |
static final int |
Results should be grouped together by package for the purpose of enforcing a limit on the number of results returned per package. |
static final int |
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SEARCH_SPEC_GROUPING_TYPE_PER_SCHEMA)Results should be grouped together by schema type for the purpose of enforcing a limit on the number of results returned per schema type. |
static final int |
ORDER_ASCENDING = 1Search results will be returned in an ascending order. |
static final int |
ORDER_DESCENDING = 0Search results will be returned in a descending order. |
static final int |
Ranked by the advanced ranking expression provided. |
static final int |
Ranked by document creation timestamps. |
static final int |
Ranked by app-provided document scores. |
static final int |
Ranked by the aggregated ranking signal of the joined documents. |
static final int |
No Ranking, results are returned in arbitrary order. |
static final int |
Ranked by document relevance score. |
static final int |
Ranked by number of usages from a system UI surface. |
static final int |
Ranked by timestamp of last usage from a system UI surface. |
static final int |
Ranked by number of usages, as reported by the app. |
static final int |
Ranked by timestamp of last usage, as reported by the app. |
static final String |
SCHEMA_TYPE_WILDCARD = "*"Schema type to be used in |
static final int |
Query terms will only match exact tokens in the index. |
static final int |
Query terms will match indexed tokens when the query term is a prefix of the token. |
Public methods |
|
|---|---|
@NonNull String |
Get the advanced ranking expression, or "" if |
int |
Returns the default embedding metric type used for embedding search (see |
@NonNull List<EmbeddingVector> |
Returns the list of |
@NonNull List<String> |
Returns the list of document ids to search over. |
@NonNull List<String> |
Returns the list of namespaces to search over. |
@NonNull List<String> |
Returns the list of package name filters to search over. |
@NonNull Map<String, List<String>> |
Returns the map of schema and target properties to search over. |
@NonNull List<String> |
Returns the list of schema types to search for. |
@NonNull List<String> |
Returns the informational ranking expressions. |
@Nullable JoinSpec |
Returns specification on which documents need to be joined. |
int |
Returns the maximum size of a snippet in characters. |
int |
getOrder()Returns the order of returned search results (descending or ascending). |
@NonNull Map<String, List<PropertyPath>> |
Returns a map from schema type to property paths to be used for projection. |
@NonNull Map<String, List<String>> |
Returns a map from schema type to property paths to be used for projection. |
@NonNull Map<String, Map<PropertyPath, Double>> |
Returns properties weights to be used for scoring. |
@NonNull Map<String, Map<String, Double>> |
Returns properties weights to be used for scoring. |
int |
Returns the ranking strategy. |
int |
Returns the number of results per page in the result set. |
int |
Get the maximum number of results to return for each group. |
int |
Get the type of grouping limit to apply, or 0 if |
@Nullable String |
Gets a tag to indicate the source of this search, or |
@NonNull List<String> |
Returns the list of String parameters that can be referenced in the query through the "getSearchStringParameter({index})" function. |
int |
Returns how many documents to generate snippets for. |
int |
Returns how many matches for each property of a matching document to generate snippets for. |
int |
Returns how the query terms should match terms in the index. |
boolean |
Returns whether the LIST_FILTER_HAS_PROPERTY_FUNCTION feature is enabled. |
boolean |
Returns whether the LIST_FILTER_MATCH_SCORE_EXPRESSION_FUNCTION feature is enabled. |
boolean |
Returns whether the LIST_FILTER_QUERY_LANGUAGE feature is enabled. |
boolean |
Returns whether the NUMERIC_SEARCH feature is enabled. |
boolean |
Returns whether the ScorablePropertyRanking feature is enabled. |
boolean |
Returns whether the VERBATIM_SEARCH feature is enabled. |
boolean |
Returns whether to retrieve embedding match infos as a part of |
Constants
EMBEDDING_SEARCH_METRIC_TYPE_COSINE
public static final int EMBEDDING_SEARCH_METRIC_TYPE_COSINE = 1
Cosine similarity as metric for embedding search and ranking.
EMBEDDING_SEARCH_METRIC_TYPE_DEFAULT
public static final int EMBEDDING_SEARCH_METRIC_TYPE_DEFAULT = 0
Use the default metric set in getDefaultEmbeddingSearchMetricType for embedding search and ranking.
EMBEDDING_SEARCH_METRIC_TYPE_DOT_PRODUCT
public static final int EMBEDDING_SEARCH_METRIC_TYPE_DOT_PRODUCT = 2
Dot product similarity as metric for embedding search and ranking.
EMBEDDING_SEARCH_METRIC_TYPE_EUCLIDEAN
public static final int EMBEDDING_SEARCH_METRIC_TYPE_EUCLIDEAN = 3
Euclidean distance as metric for embedding search and ranking.
GROUPING_TYPE_PER_NAMESPACE
public static final int GROUPING_TYPE_PER_NAMESPACE = 2
Results should be grouped together by namespace for the purpose of enforcing a limit on the number of results returned per namespace.
GROUPING_TYPE_PER_PACKAGE
public static final int GROUPING_TYPE_PER_PACKAGE = 1
Results should be grouped together by package for the purpose of enforcing a limit on the number of results returned per package.
GROUPING_TYPE_PER_SCHEMA
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SEARCH_SPEC_GROUPING_TYPE_PER_SCHEMA)
public static final int GROUPING_TYPE_PER_SCHEMA = 4
Results should be grouped together by schema type for the purpose of enforcing a limit on the number of results returned per schema type.
ORDER_ASCENDING
public static final int ORDER_ASCENDING = 1
Search results will be returned in an ascending order.
ORDER_DESCENDING
public static final int ORDER_DESCENDING = 0
Search results will be returned in a descending order.
RANKING_STRATEGY_ADVANCED_RANKING_EXPRESSION
public static final int RANKING_STRATEGY_ADVANCED_RANKING_EXPRESSION = 9
Ranked by the advanced ranking expression provided.
RANKING_STRATEGY_CREATION_TIMESTAMP
public static final int RANKING_STRATEGY_CREATION_TIMESTAMP = 2
Ranked by document creation timestamps.
RANKING_STRATEGY_DOCUMENT_SCORE
public static final int RANKING_STRATEGY_DOCUMENT_SCORE = 1
Ranked by app-provided document scores.
RANKING_STRATEGY_JOIN_AGGREGATE_SCORE
public static final int RANKING_STRATEGY_JOIN_AGGREGATE_SCORE = 8
Ranked by the aggregated ranking signal of the joined documents.
Which aggregation strategy is used to determine a ranking signal is specified in the JoinSpec set by setJoinSpec. This ranking strategy may not be used if no JoinSpec is provided.
| See also | |
|---|---|
build |
RANKING_STRATEGY_NONE
public static final int RANKING_STRATEGY_NONE = 0
No Ranking, results are returned in arbitrary order.
RANKING_STRATEGY_RELEVANCE_SCORE
public static final int RANKING_STRATEGY_RELEVANCE_SCORE = 3
Ranked by document relevance score.
RANKING_STRATEGY_SYSTEM_USAGE_COUNT
public static final int RANKING_STRATEGY_SYSTEM_USAGE_COUNT = 6
Ranked by number of usages from a system UI surface.
RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP
public static final int RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP = 7
Ranked by timestamp of last usage from a system UI surface.
RANKING_STRATEGY_USAGE_COUNT
public static final int RANKING_STRATEGY_USAGE_COUNT = 4
Ranked by number of usages, as reported by the app.
RANKING_STRATEGY_USAGE_LAST_USED_TIMESTAMP
public static final int RANKING_STRATEGY_USAGE_LAST_USED_TIMESTAMP = 5
Ranked by timestamp of last usage, as reported by the app.
SCHEMA_TYPE_WILDCARD
public static final String SCHEMA_TYPE_WILDCARD = "*"
Schema type to be used in addFilterProperties and addProjection to apply property paths to all results, excepting any types that have had their own, specific property paths set.
TERM_MATCH_EXACT_ONLY
public static final int TERM_MATCH_EXACT_ONLY = 1
Query terms will only match exact tokens in the index.
For example, a query term "foo" will only match indexed token "foo", and not "foot" or "football".
TERM_MATCH_PREFIX
public static final int TERM_MATCH_PREFIX = 2
Query terms will match indexed tokens when the query term is a prefix of the token.
For example, a query term "foo" will match indexed tokens like "foo", "foot", and "football".
Public methods
getAdvancedRankingExpression
public @NonNull String getAdvancedRankingExpression()
Get the advanced ranking expression, or "" if setRankingStrategy was not called.
getDefaultEmbeddingSearchMetricType
public int getDefaultEmbeddingSearchMetricType()
Returns the default embedding metric type used for embedding search (see search) and ranking (see setRankingStrategy).
getEmbeddingParameters
public @NonNull List<EmbeddingVector> getEmbeddingParameters()
Returns the list of EmbeddingVector that can be referenced in the query through the "getEmbeddingParameter({index})" function.
| See also | |
|---|---|
search |
getFilterDocumentIds
@ExperimentalAppSearchApi
public @NonNull List<String> getFilterDocumentIds()
Returns the list of document ids to search over.
If empty, the query will search over all documents.
getFilterNamespaces
public @NonNull List<String> getFilterNamespaces()
Returns the list of namespaces to search over.
If empty, the query will search over all namespaces.
getFilterPackageNames
public @NonNull List<String> getFilterPackageNames()
Returns the list of package name filters to search over.
If empty, the query will search over all packages that the caller has access to. If package names are specified which caller doesn't have access to, then those package names will be ignored.
getFilterProperties
public @NonNull Map<String, List<String>> getFilterProperties()
Returns the map of schema and target properties to search over.
If empty, will search over all schema and properties.
Calling this function repeatedly is inefficient. Prefer to retain the Map returned by this function, rather than calling it multiple times.
getFilterSchemas
public @NonNull List<String> getFilterSchemas()
Returns the list of schema types to search for.
If empty, the query will search over all schema types.
getInformationalRankingExpressions
public @NonNull List<String> getInformationalRankingExpressions()
Returns the informational ranking expressions.
| See also | |
|---|---|
SearchSpec.Builder |
getJoinSpec
public @Nullable JoinSpec getJoinSpec()
Returns specification on which documents need to be joined.
getMaxSnippetSize
public int getMaxSnippetSize()
Returns the maximum size of a snippet in characters.
getOrder
public int getOrder()
Returns the order of returned search results (descending or ascending).
getProjectionPaths
public @NonNull Map<String, List<PropertyPath>> getProjectionPaths()
Returns a map from schema type to property paths to be used for projection.
If the map is empty, then all properties will be retrieved for all results.
Calling this function repeatedly is inefficient. Prefer to retain the Map returned by this function, rather than calling it multiple times.
| Returns | |
|---|---|
@NonNull Map<String, List<PropertyPath>> |
A mapping of schema types to lists of projection |
getProjections
public @NonNull Map<String, List<String>> getProjections()
Returns a map from schema type to property paths to be used for projection.
If the map is empty, then all properties will be retrieved for all results.
Calling this function repeatedly is inefficient. Prefer to retain the Map returned by this function, rather than calling it multiple times.
getPropertyWeightPaths
public @NonNull Map<String, Map<PropertyPath, Double>> getPropertyWeightPaths()
Returns properties weights to be used for scoring.
Calling this function repeatedly is inefficient. Prefer to retain the Map returned by this function, rather than calling it multiple times.
getPropertyWeights
public @NonNull Map<String, Map<String, Double>> getPropertyWeights()
Returns properties weights to be used for scoring.
Calling this function repeatedly is inefficient. Prefer to retain the Map returned by this function, rather than calling it multiple times.
getResultCountPerPage
public int getResultCountPerPage()
Returns the number of results per page in the result set.
getResultGroupingLimit
public int getResultGroupingLimit()
Get the maximum number of results to return for each group.
| Returns | |
|---|---|
int |
the maximum number of results to return for each group or 0 if |
getResultGroupingTypeFlags
public int getResultGroupingTypeFlags()
Get the type of grouping limit to apply, or 0 if setResultGrouping was not called.
getSearchSourceLogTag
public @Nullable String getSearchSourceLogTag()
Gets a tag to indicate the source of this search, or null if setSearchSourceLogTag was not called.
Some AppSearch implementations may log a hash of this tag using statsd. This tag may be used for tracing performance issues and crashes to a component of an app.
Call setSearchSourceLogTag and give a unique value if you want to distinguish this search scenario with other search scenarios during performance analysis.
Under no circumstances will AppSearch log the raw String value using statsd, but it will be provided as-is to custom AppSearchLogger implementations you have registered in your app.
getSearchStringParameters
public @NonNull List<String> getSearchStringParameters()
Returns the list of String parameters that can be referenced in the query through the "getSearchStringParameter({index})" function.
| See also | |
|---|---|
search |
getSnippetCount
public int getSnippetCount()
Returns how many documents to generate snippets for.
getSnippetCountPerProperty
public int getSnippetCountPerProperty()
Returns how many matches for each property of a matching document to generate snippets for.
getTermMatch
public int getTermMatch()
Returns how the query terms should match terms in the index.
isListFilterHasPropertyFunctionEnabled
public boolean isListFilterHasPropertyFunctionEnabled()
Returns whether the LIST_FILTER_HAS_PROPERTY_FUNCTION feature is enabled.
isListFilterMatchScoreExpressionFunctionEnabled
@ExperimentalAppSearchApi
public boolean isListFilterMatchScoreExpressionFunctionEnabled()
Returns whether the LIST_FILTER_MATCH_SCORE_EXPRESSION_FUNCTION feature is enabled.
isListFilterQueryLanguageEnabled
public boolean isListFilterQueryLanguageEnabled()
Returns whether the LIST_FILTER_QUERY_LANGUAGE feature is enabled.
isNumericSearchEnabled
public boolean isNumericSearchEnabled()
Returns whether the NUMERIC_SEARCH feature is enabled.
isScorablePropertyRankingEnabled
@ExperimentalAppSearchApi
public boolean isScorablePropertyRankingEnabled()
Returns whether the ScorablePropertyRanking feature is enabled.
isVerbatimSearchEnabled
public boolean isVerbatimSearchEnabled()
Returns whether the VERBATIM_SEARCH feature is enabled.
shouldRetrieveEmbeddingMatchInfos
@ExperimentalAppSearchApi
public boolean shouldRetrieveEmbeddingMatchInfos()
Returns whether to retrieve embedding match infos as a part of getMatchInfos