# SearchSuggestionSpec

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/app/SearchSuggestionSpec.java+class:androidx.appsearch.app.SearchSuggestionSpec) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***

<br />

```
public final class SearchSuggestionSpec
```

<br />

*** ** * ** ***

This class represents the specification logic for AppSearch. It can be used to set the filter and settings of search a suggestions.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSession#searchSuggestionAsync(java.lang.String,androidx.appsearch.app.SearchSuggestionSpec)` |   |

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec.Builder` Builder for `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec`. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec#SUGGESTION_RANKING_STRATEGY_DOCUMENT_COUNT() = 0` Ranked by the document count that contains the term. |
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec#SUGGESTION_RANKING_STRATEGY_NONE() = 2` No Ranking, results are returned in arbitrary order. |
| `static final int` | `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec#SUGGESTION_RANKING_STRATEGY_TERM_FREQUENCY() = 1` Ranked by the term appear frequency. |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html>>` | `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec#getFilterDocumentIds()()` Returns the map of namespace and target document ids to search over. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html>` | `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec#getFilterNamespaces()()` Returns the list of namespaces to search over. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html>>` | `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec#getFilterProperties()()` Returns the map of schema and target properties to search over. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html>` | `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec#getFilterSchemas()()` Returns the list of schema to search the suggestion over. |
| `int` | `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec#getMaximumResultCount()()` Returns the maximum number of wanted suggestion that will be returned in the result object. |
| `int` | `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec#getRankingStrategy()()` Returns the ranking strategy. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html>` | `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec#getSearchStringParameters()()` Returns the list of String parameters that can be referenced in the query through the "getSearchStringParameter({index})" function. |

## Constants

### SUGGESTION_RANKING_STRATEGY_DOCUMENT_COUNT

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public static final int SUGGESTION_RANKING_STRATEGY_DOCUMENT_COUNT = 0
```

Ranked by the document count that contains the term.

Suppose the following document is in the index.

```
Doc1 contains: term1 term2 term2 term2
```

```
Doc2 contains: term1
```

Then, suppose that a search suggestion for "t" is issued with the DOCUMENT_COUNT, the returned `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionResult`s will be: term1, term2. The term1 will have higher score and appear in the results first.

### SUGGESTION_RANKING_STRATEGY_NONE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public static final int SUGGESTION_RANKING_STRATEGY_NONE = 2
```

No Ranking, results are returned in arbitrary order.

### SUGGESTION_RANKING_STRATEGY_TERM_FREQUENCY

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public static final int SUGGESTION_RANKING_STRATEGY_TERM_FREQUENCY = 1
```

Ranked by the term appear frequency.

Suppose the following document is in the index.

```
Doc1 contains: term1 term2 term2 term2
```

```
Doc2 contains: term1
```

Then, suppose that a search suggestion for "t" is issued with the TERM_FREQUENCY, the returned `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionResult`s will be: term2, term1. The term2 will have higher score and appear in the results first.

## Public methods

### getFilterDocumentIds

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public @NonNull Map<String, List<String>> getFilterDocumentIds()
```

Returns the map of namespace and target document ids to search over.

The keys of the returned map are namespaces, and the values are the target document ids in that namespace to search over.

If `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec.Builder#addFilterDocumentIds(java.lang.String,java.lang.String...)` was never called, returns an empty map. In this case AppSearch will search over all namespace and document ids.

Calling this function repeatedly is inefficient. Prefer to retain the Map returned by this function, rather than calling it multiple times.

### getFilterNamespaces

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public @NonNull List<String> getFilterNamespaces()
```

Returns the list of namespaces to search over.

If empty, will search over all namespaces.

### getFilterProperties

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public @NonNull Map<String, List<String>> getFilterProperties()
```

Returns the map of schema and target properties to search over.

The keys of the returned map are schema types, and the values are the target property path in that schema to search over.

If `https://developer.android.com/reference/androidx/appsearch/app/SearchSuggestionSpec.Builder#addFilterPropertyPaths(java.lang.String,java.util.Collection<androidx.appsearch.app.PropertyPath>)` was never called, returns an empty map. In this case AppSearch will search over all schemas and properties.

Calling this function repeatedly is inefficient. Prefer to retain the Map returned by this function, rather than calling it multiple times.

### getFilterSchemas

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public @NonNull List<String> getFilterSchemas()
```

Returns the list of schema to search the suggestion over.

If empty, will search over all schemas.

### getMaximumResultCount

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public int getMaximumResultCount()
```

Returns the maximum number of wanted suggestion that will be returned in the result object.

### getRankingStrategy

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public int getRankingStrategy()
```

Returns the ranking strategy.

### getSearchStringParameters

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
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 |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSession#search(java.lang.String,androidx.appsearch.app.SearchSpec)` |   |