SearchSpec
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 |
---|
class SearchSpec.Builder Builder for |
Constants |
|
---|---|
const Int |
Cosine similarity as metric for embedding search and ranking. |
const Int |
Use the default metric set in |
const Int |
Dot product similarity as metric for embedding search and ranking. |
const Int |
Euclidean distance as metric for embedding search and ranking. |
const Int |
Results should be grouped together by namespace for the purpose of enforcing a limit on the number of results returned per namespace. |
const Int |
Results should be grouped together by package for the purpose of enforcing a limit on the number of results returned per package. |
const 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. |
const Int |
ORDER_ASCENDING = 1 Search results will be returned in an ascending order. |
const Int |
ORDER_DESCENDING = 0 Search results will be returned in a descending order. |
const Int |
Ranked by the advanced ranking expression provided. |
const Int |
Ranked by document creation timestamps. |
const Int |
Ranked by app-provided document scores. |
const Int |
Ranked by the aggregated ranking signal of the joined documents. |
const Int |
No Ranking, results are returned in arbitrary order. |
const Int |
Ranked by document relevance score. |
const Int |
Ranked by number of usages from a system UI surface. |
const Int |
Ranked by timestamp of last usage from a system UI surface. |
const Int |
Ranked by number of usages, as reported by the app. |
const Int |
Ranked by timestamp of last usage, as reported by the app. |
const String! |
SCHEMA_TYPE_WILDCARD = "*" Schema type to be used in |
const Int |
Query terms will only match exact tokens in the index. |
const Int |
Query terms will match indexed tokens when the query term is a prefix of the token. |
Public functions |
|
---|---|
String |
Get the advanced ranking expression, or "" if |
Int |
Returns the default embedding metric type used for embedding search (see |
(Mutable)List<EmbeddingVector!> |
Returns the list of |
(Mutable)List<String!> |
Returns the list of document ids to search over. |
(Mutable)List<String!> |
Returns the list of namespaces to search over. |
(Mutable)List<String!> |
Returns the list of package name filters to search over. |
(Mutable)Map<String!, (Mutable)List<String!>!> |
Returns the map of schema and target properties to search over. |
(Mutable)List<String!> |
Returns the list of schema types to search for. |
(Mutable)List<String!> |
Returns the informational ranking expressions. |
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). |
(Mutable)Map<String!, (Mutable)List<PropertyPath!>!> |
Returns a map from schema type to property paths to be used for projection. |
(Mutable)Map<String!, (Mutable)List<String!>!> |
Returns a map from schema type to property paths to be used for projection. |
(Mutable)Map<String!, (Mutable)Map<PropertyPath!, Double!>!> |
Returns properties weights to be used for scoring. |
(Mutable)Map<String!, (Mutable)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 |
String? |
Gets a tag to indicate the source of this search, or |
(Mutable)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. |
Constants
EMBEDDING_SEARCH_METRIC_TYPE_COSINE
const val EMBEDDING_SEARCH_METRIC_TYPE_COSINE = 1: Int
Cosine similarity as metric for embedding search and ranking.
EMBEDDING_SEARCH_METRIC_TYPE_DEFAULT
const val EMBEDDING_SEARCH_METRIC_TYPE_DEFAULT = 0: Int
Use the default metric set in getDefaultEmbeddingSearchMetricType
for embedding search and ranking.
EMBEDDING_SEARCH_METRIC_TYPE_DOT_PRODUCT
const val EMBEDDING_SEARCH_METRIC_TYPE_DOT_PRODUCT = 2: Int
Dot product similarity as metric for embedding search and ranking.
EMBEDDING_SEARCH_METRIC_TYPE_EUCLIDEAN
const val EMBEDDING_SEARCH_METRIC_TYPE_EUCLIDEAN = 3: Int
Euclidean distance as metric for embedding search and ranking.
GROUPING_TYPE_PER_NAMESPACE
const val GROUPING_TYPE_PER_NAMESPACE = 2: Int
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
const val GROUPING_TYPE_PER_PACKAGE = 1: Int
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)
const val GROUPING_TYPE_PER_SCHEMA = 4: Int
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
const val ORDER_ASCENDING = 1: Int
Search results will be returned in an ascending order.
ORDER_DESCENDING
const val ORDER_DESCENDING = 0: Int
Search results will be returned in a descending order.
RANKING_STRATEGY_ADVANCED_RANKING_EXPRESSION
const val RANKING_STRATEGY_ADVANCED_RANKING_EXPRESSION = 9: Int
Ranked by the advanced ranking expression provided.
RANKING_STRATEGY_CREATION_TIMESTAMP
const val RANKING_STRATEGY_CREATION_TIMESTAMP = 2: Int
Ranked by document creation timestamps.
RANKING_STRATEGY_DOCUMENT_SCORE
const val RANKING_STRATEGY_DOCUMENT_SCORE = 1: Int
Ranked by app-provided document scores.
RANKING_STRATEGY_JOIN_AGGREGATE_SCORE
const val RANKING_STRATEGY_JOIN_AGGREGATE_SCORE = 8: Int
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
const val RANKING_STRATEGY_NONE = 0: Int
No Ranking, results are returned in arbitrary order.
RANKING_STRATEGY_RELEVANCE_SCORE
const val RANKING_STRATEGY_RELEVANCE_SCORE = 3: Int
Ranked by document relevance score.
RANKING_STRATEGY_SYSTEM_USAGE_COUNT
const val RANKING_STRATEGY_SYSTEM_USAGE_COUNT = 6: Int
Ranked by number of usages from a system UI surface.
RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP
const val RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP = 7: Int
Ranked by timestamp of last usage from a system UI surface.
RANKING_STRATEGY_USAGE_COUNT
const val RANKING_STRATEGY_USAGE_COUNT = 4: Int
Ranked by number of usages, as reported by the app.
RANKING_STRATEGY_USAGE_LAST_USED_TIMESTAMP
const val RANKING_STRATEGY_USAGE_LAST_USED_TIMESTAMP = 5: Int
Ranked by timestamp of last usage, as reported by the app.
SCHEMA_TYPE_WILDCARD
const val SCHEMA_TYPE_WILDCARD = "*": String!
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
const val TERM_MATCH_EXACT_ONLY = 1: Int
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
const val TERM_MATCH_PREFIX = 2: Int
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 functions
getAdvancedRankingExpression
fun getAdvancedRankingExpression(): String
Get the advanced ranking expression, or "" if setRankingStrategy
was not called.
getDefaultEmbeddingSearchMetricType
fun getDefaultEmbeddingSearchMetricType(): Int
Returns the default embedding metric type used for embedding search (see search
) and ranking (see setRankingStrategy
).
getEmbeddingParameters
fun getEmbeddingParameters(): (Mutable)List<EmbeddingVector!>
Returns the list of EmbeddingVector
that can be referenced in the query through the "getEmbeddingParameter({index})" function.
See also | |
---|---|
search |
getFilterDocumentIds
@ExperimentalAppSearchApi
fun getFilterDocumentIds(): (Mutable)List<String!>
Returns the list of document ids to search over.
If empty, the query will search over all documents.
getFilterNamespaces
fun getFilterNamespaces(): (Mutable)List<String!>
Returns the list of namespaces to search over.
If empty, the query will search over all namespaces.
getFilterPackageNames
fun getFilterPackageNames(): (Mutable)List<String!>
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
fun getFilterProperties(): (Mutable)Map<String!, (Mutable)List<String!>!>
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
fun getFilterSchemas(): (Mutable)List<String!>
Returns the list of schema types to search for.
If empty, the query will search over all schema types.
getInformationalRankingExpressions
fun getInformationalRankingExpressions(): (Mutable)List<String!>
Returns the informational ranking expressions.
See also | |
---|---|
SearchSpec.Builder |
getJoinSpec
fun getJoinSpec(): JoinSpec?
Returns specification on which documents need to be joined.
getMaxSnippetSize
fun getMaxSnippetSize(): Int
Returns the maximum size of a snippet in characters.
getOrder
fun getOrder(): Int
Returns the order of returned search results (descending or ascending).
getProjectionPaths
fun getProjectionPaths(): (Mutable)Map<String!, (Mutable)List<PropertyPath!>!>
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 | |
---|---|
(Mutable)Map<String!, (Mutable)List<PropertyPath!>!> |
A mapping of schema types to lists of projection |
getProjections
fun getProjections(): (Mutable)Map<String!, (Mutable)List<String!>!>
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
fun getPropertyWeightPaths(): (Mutable)Map<String!, (Mutable)Map<PropertyPath!, Double!>!>
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
fun getPropertyWeights(): (Mutable)Map<String!, (Mutable)Map<String!, Double!>!>
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.
getRankingStrategy
fun getRankingStrategy(): Int
Returns the ranking strategy.
getResultCountPerPage
fun getResultCountPerPage(): Int
Returns the number of results per page in the result set.
getResultGroupingLimit
fun getResultGroupingLimit(): Int
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
fun getResultGroupingTypeFlags(): Int
Get the type of grouping limit to apply, or 0 if setResultGrouping
was not called.
getSearchSourceLogTag
fun getSearchSourceLogTag(): String?
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
fun getSearchStringParameters(): (Mutable)List<String!>
Returns the list of String parameters that can be referenced in the query through the "getSearchStringParameter({index})" function.
See also | |
---|---|
search |
getSnippetCount
fun getSnippetCount(): Int
Returns how many documents to generate snippets for.
getSnippetCountPerProperty
fun getSnippetCountPerProperty(): Int
Returns how many matches for each property of a matching document to generate snippets for.
getTermMatch
fun getTermMatch(): Int
Returns how the query terms should match terms in the index.
isListFilterHasPropertyFunctionEnabled
fun isListFilterHasPropertyFunctionEnabled(): Boolean
Returns whether the LIST_FILTER_HAS_PROPERTY_FUNCTION feature is enabled.
isListFilterMatchScoreExpressionFunctionEnabled
@ExperimentalAppSearchApi
fun isListFilterMatchScoreExpressionFunctionEnabled(): Boolean
Returns whether the LIST_FILTER_MATCH_SCORE_EXPRESSION_FUNCTION feature is enabled.
isListFilterQueryLanguageEnabled
fun isListFilterQueryLanguageEnabled(): Boolean
Returns whether the LIST_FILTER_QUERY_LANGUAGE feature is enabled.
isNumericSearchEnabled
fun isNumericSearchEnabled(): Boolean
Returns whether the NUMERIC_SEARCH feature is enabled.
isScorablePropertyRankingEnabled
@ExperimentalAppSearchApi
fun isScorablePropertyRankingEnabled(): Boolean
Returns whether the ScorablePropertyRanking feature is enabled.
isVerbatimSearchEnabled
fun isVerbatimSearchEnabled(): Boolean
Returns whether the VERBATIM_SEARCH feature is enabled.