SearchSpec

public final class SearchSpec extends Object
implements Parcelable

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.

Nested Class Summary

class SearchSpec.Builder Builder for objects

Constant Summary

int GROUPING_TYPE_PER_NAMESPACE Results should be grouped together by namespace for the purpose of enforcing a limit on the number of results returned per namespace.
int GROUPING_TYPE_PER_PACKAGE Results should be grouped together by package for the purpose of enforcing a limit on the number of results returned per package.
int 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.
int ORDER_ASCENDING Search results will be returned in an ascending order.
int ORDER_DESCENDING Search results will be returned in a descending order.
String PROJECTION_SCHEMA_TYPE_WILDCARD This constant is deprecated. use SCHEMA_TYPE_WILDCARD instead.
int RANKING_STRATEGY_ADVANCED_RANKING_EXPRESSION Ranked by the advanced ranking expression provided.
int RANKING_STRATEGY_CREATION_TIMESTAMP Ranked by document creation timestamps.
int RANKING_STRATEGY_DOCUMENT_SCORE Ranked by app-provided document scores.
int RANKING_STRATEGY_JOIN_AGGREGATE_SCORE Ranked by the aggregated ranking signal of the joined documents.
int RANKING_STRATEGY_NONE No Ranking, results are returned in arbitrary order.
int RANKING_STRATEGY_RELEVANCE_SCORE Ranked by document relevance score.
int RANKING_STRATEGY_SYSTEM_USAGE_COUNT Ranked by number of usages from a system UI surface.
int RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP Ranked by timestamp of last usage from a system UI surface.
int RANKING_STRATEGY_USAGE_COUNT Ranked by number of usages, as reported by the app.
int RANKING_STRATEGY_USAGE_LAST_USED_TIMESTAMP Ranked by timestamp of last usage, as reported by the app.
String SCHEMA_TYPE_WILDCARD Schema type to be used in SearchSpec.Builder.addFilterProperties(String, Collection) and SearchSpec.Builder.addProjection(String, Collection) to apply property paths to all results, excepting any types that have had their own, specific property paths set.
int TERM_MATCH_EXACT_ONLY Query terms will only match exact tokens in the index.
int TERM_MATCH_PREFIX Query terms will match indexed tokens when the query term is a prefix of the token.

Inherited Constant Summary

Field Summary

public static final Creator<SearchSpec> CREATOR Creator class for SearchSpec.

Public Method Summary

String
getAdvancedRankingExpression()
Get the advanced ranking expression, or "" if SearchSpec.Builder.setRankingStrategy(String) was not called.
List<String>
getFilterNamespaces()
Returns the list of namespaces to search over.
List<String>
getFilterPackageNames()
Returns the list of package name filters to search over.
Map<StringList<String>>
getFilterProperties()
Returns the map of schema and target properties to search over.
List<String>
getFilterSchemas()
Returns the list of schema types to search for.
JoinSpec
getJoinSpec()
Returns specification on which documents need to be joined.
int
getMaxSnippetSize()
Returns the maximum size of a snippet in characters.
int
getOrder()
Returns the order of returned search results (descending or ascending).
Map<StringList<PropertyPath>>
getProjectionPaths()
Returns a map from schema type to property paths to be used for projection.
Map<StringList<String>>
getProjections()
Returns a map from schema type to property paths to be used for projection.
Map<StringMap<PropertyPathDouble>>
getPropertyWeightPaths()
Returns properties weights to be used for scoring.
Map<StringMap<StringDouble>>
getPropertyWeights()
Returns properties weights to be used for scoring.
int
getRankingStrategy()
Returns the ranking strategy.
int
getResultCountPerPage()
Returns the number of results per page in the result set.
int
getResultGroupingLimit()
Get the maximum number of results to return for each group.
int
getResultGroupingTypeFlags()
Get the type of grouping limit to apply, or 0 if SearchSpec.Builder.setResultGrouping(int, int) was not called.
String
getSearchSourceLogTag()
Gets a tag to indicate the source of this search, or null if SearchSpec.Builder.setSearchSourceLogTag(String) was not called.
int
getSnippetCount()
Returns how many documents to generate snippets for.
int
getSnippetCountPerProperty()
Returns how many matches for each property of a matching document to generate snippets for.
int
getTermMatch()
Returns how the query terms should match terms in the index.
boolean
isListFilterHasPropertyFunctionEnabled()
Returns whether the LIST_FILTER_HAS_PROPERTY_FUNCTION feature is enabled.
boolean
isListFilterQueryLanguageEnabled()
Returns whether the LIST_FILTER_QUERY_LANGUAGE feature is enabled.
boolean
isNumericSearchEnabled()
Returns whether the NUMERIC_SEARCH feature is enabled.
boolean
isVerbatimSearchEnabled()
Returns whether the VERBATIM_SEARCH feature is enabled.
void
writeToParcel(Parcel dest, int flags)

Inherited Method Summary

Constants

public static final int GROUPING_TYPE_PER_NAMESPACE

Results should be grouped together by namespace for the purpose of enforcing a limit on the number of results returned per namespace.

Constant Value: 2

public static final int GROUPING_TYPE_PER_PACKAGE

Results should be grouped together by package for the purpose of enforcing a limit on the number of results returned per package.

Constant Value: 1

public static final int 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.

Constant Value: 4

public static final int ORDER_ASCENDING

Search results will be returned in an ascending order.

Constant Value: 1

public static final int ORDER_DESCENDING

Search results will be returned in a descending order.

Constant Value: 0

public static final String PROJECTION_SCHEMA_TYPE_WILDCARD

This constant is deprecated.
use SCHEMA_TYPE_WILDCARD instead.

Schema type to be used in SearchSpec.Builder.addProjection(String, Collection) to apply property paths to all results, excepting any types that have had their own, specific property paths set.

Constant Value: "*"

public static final int RANKING_STRATEGY_ADVANCED_RANKING_EXPRESSION

Ranked by the advanced ranking expression provided.

Constant Value: 9

public static final int RANKING_STRATEGY_CREATION_TIMESTAMP

Ranked by document creation timestamps.

Constant Value: 2

public static final int RANKING_STRATEGY_DOCUMENT_SCORE

Ranked by app-provided document scores.

Constant Value: 1

public static final int RANKING_STRATEGY_JOIN_AGGREGATE_SCORE

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 SearchSpec.Builder.setJoinSpec(JoinSpec). This ranking strategy may not be used if no JoinSpec is provided.

Constant Value: 8

public static final int RANKING_STRATEGY_NONE

No Ranking, results are returned in arbitrary order.

Constant Value: 0

public static final int RANKING_STRATEGY_RELEVANCE_SCORE

Ranked by document relevance score.

Constant Value: 3

public static final int RANKING_STRATEGY_SYSTEM_USAGE_COUNT

Ranked by number of usages from a system UI surface.

Constant Value: 6

public static final int RANKING_STRATEGY_SYSTEM_USAGE_LAST_USED_TIMESTAMP

Ranked by timestamp of last usage from a system UI surface.

Constant Value: 7

public static final int RANKING_STRATEGY_USAGE_COUNT

Ranked by number of usages, as reported by the app.

Constant Value: 4

public static final int RANKING_STRATEGY_USAGE_LAST_USED_TIMESTAMP

Ranked by timestamp of last usage, as reported by the app.

Constant Value: 5

public static final String SCHEMA_TYPE_WILDCARD

Schema type to be used in SearchSpec.Builder.addFilterProperties(String, Collection) and SearchSpec.Builder.addProjection(String, Collection) to apply property paths to all results, excepting any types that have had their own, specific property paths set.

Constant Value: "*"

public static final int TERM_MATCH_EXACT_ONLY

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".

Constant Value: 1

public static final int TERM_MATCH_PREFIX

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".

Constant Value: 2

Fields

public static final Creator<SearchSpec> CREATOR

Creator class for SearchSpec.

Public Methods

public String getAdvancedRankingExpression ()

Get the advanced ranking expression, or "" if SearchSpec.Builder.setRankingStrategy(String) was not called.

public List<String> getFilterNamespaces ()

Returns the list of namespaces to search over.

If empty, the query will search over all namespaces.

public 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.

public Map<StringList<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.

public List<String> getFilterSchemas ()

Returns the list of schema types to search for.

If empty, the query will search over all schema types.

public JoinSpec getJoinSpec ()

Returns specification on which documents need to be joined.

public int getMaxSnippetSize ()

Returns the maximum size of a snippet in characters.

public int getOrder ()

Returns the order of returned search results (descending or ascending).

public Map<StringList<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
  • A mapping of schema types to lists of projection PropertyPath objects.

public Map<StringList<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.

Returns
  • A mapping of schema types to lists of projection strings.

public Map<StringMap<PropertyPathDouble>> 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.

Returns
  • a Map of schema type to an inner-map of property paths of the schema type to the weight to set for that property.

public Map<StringMap<StringDouble>> 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.

Returns
  • a Map of schema type to an inner-map of property paths of the schema type to the weight to set for that property.

public int getRankingStrategy ()

Returns the ranking strategy.

public int getResultCountPerPage ()

Returns the number of results per page in the result set.

public int getResultGroupingLimit ()

Get the maximum number of results to return for each group.

Returns

public int getResultGroupingTypeFlags ()

Get the type of grouping limit to apply, or 0 if SearchSpec.Builder.setResultGrouping(int, int) was not called.

public String getSearchSourceLogTag ()

Gets a tag to indicate the source of this search, or null if SearchSpec.Builder.setSearchSourceLogTag(String) 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 SearchSpec.Builder.setSearchSourceLogTag(String) 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.

public int getSnippetCount ()

Returns how many documents to generate snippets for.

public int getSnippetCountPerProperty ()

Returns how many matches for each property of a matching document to generate snippets for.

public int getTermMatch ()

Returns how the query terms should match terms in the index.

public boolean isListFilterHasPropertyFunctionEnabled ()

Returns whether the LIST_FILTER_HAS_PROPERTY_FUNCTION feature is enabled.

public boolean isListFilterQueryLanguageEnabled ()

Returns whether the LIST_FILTER_QUERY_LANGUAGE feature is enabled.

public boolean isNumericSearchEnabled ()

Returns whether the NUMERIC_SEARCH feature is enabled.

public boolean isVerbatimSearchEnabled ()

Returns whether the VERBATIM_SEARCH feature is enabled.

public void writeToParcel (Parcel dest, int flags)