You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/index-add-suggesters.md
+23-15Lines changed: 23 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ author: HeidiSteen
8
8
ms.author: heidist
9
9
ms.service: cognitive-search
10
10
ms.topic: conceptual
11
-
ms.date: 04/14/2020
11
+
ms.date: 04/21/2020
12
12
---
13
13
14
14
# Create a suggester to enable autocomplete and suggested results in a query
@@ -29,27 +29,36 @@ Search-as-you-type support is enabled on a per-field basis for string fields. Yo
29
29
30
30
## What is a suggester?
31
31
32
-
A suggester is a data structure that supports search-as-you-type behaviors by storing prefixes for matching on partial queries. Similar to tokenized terms, prefixes are stored in inverted indexes, one for each field specified in a suggester fields collection.
32
+
A suggester is an internal data structure that supports search-as-you-type behaviors by storing prefixes for matching on partial queries. As with tokenized terms, prefixes are stored in inverted indexes, one for each field specified in a suggester fields collection.
33
33
34
-
When creating prefixes, a suggester has its own analysis chain, similar to the one used for full text search. However, unlike analysis in full text search, a suggester can only operate over fields that use the standard Lucene analyzer (default) or a [language analyzer](index-add-language-analyzers.md). Fields that use [custom analyzers](index-add-custom-analyzers.md) or [predefined analyzers](index-add-custom-analyzers.md#predefined-analyzers-reference) (with the exception of standard Lucene) are explicitly disallowed to prevent poor outcomes.
34
+
## Define a suggester
35
35
36
-
> [!NOTE]
37
-
> If you need to work around the analyzer constraint, use two separate fields for the same content. This will allow one of the fields to have a suggester, while the other can be set up with a custom analyzer configuration.
36
+
To create a suggester, add one to an [index schema](https://docs.microsoft.com/rest/api/searchservice/create-index) and [set each property](#property-reference). The best time to create a suggester is when you are also defining the field that will use it.
38
37
39
-
## Define a suggester
38
+
+ Use string fields only
40
39
41
-
To create a suggester, add one to an [index schema](https://docs.microsoft.com/rest/api/searchservice/create-index) and [set each property](#property-reference). In the index, you can have one suggester (specifically, one suggester in the suggesters collection). The best time to create a suggester is when you are also defining the field that will use it.
40
+
+ Use the default standard Lucene analyzer (`"analyzer": null`) or a [language analyzer](index-add-language-analyzers.md) (for example, `"analyzer": "en.Microsoft"`) on the field
42
41
43
42
### Choose fields
44
43
45
-
Although a suggester has several properties, it is primarily a collection of fields for which you are enabling a search-as-you-type experience. For suggestions in particular, choose fields that best represent a single result. Names, titles, or other unique fields that distinguish among multiple matches work best. If fields consist of repetitive values, the suggestions consist of identical results and a user won't know which one to click.
44
+
Although a suggester has several properties, it is primarily a collection of string fields for which you are enabling a search-as-you-type experience. There is one suggester for each index, so the suggester list must include all fields that contribute content for both suggestions and autocomplete.
45
+
46
+
Autocomplete benefits from a larger pool of fields to draw from because the additional content has more term completion potential.
47
+
48
+
Suggestions, on the other hand, produce better results when your field choice is selective. Remember that the suggestion is a proxy for a search document so you will want fields that best represent a single result. Names, titles, or other unique fields that distinguish among multiple matches work best. If fields consist of repetitive values, the suggestions consist of identical results and a user won't know which one to click.
46
49
47
-
Make sure each field uses an analyzer that performs lexical analysis during indexing. You can use either the default standard Lucene analyzer (`"analyzer": null`) or a [language analyzer](index-add-language-analyzers.md) (for example, `"analyzer": "en.Microsoft"`).
50
+
To satisfy both search-as-you-type experiences, add all of the fields that you need for autocomplete, but then use **$select**, **$top**, **$filter**, and **searchFields** to control results for suggestions.
48
51
49
-
Your choice of an analyzer determines how fields are tokenized and subsequently prefixed. For example, for a hyphenated string like "context-sensitive", using a language analyzer will result in these token combinations: "context", "sensitive", "context-sensitive". Had you used the standard Lucene analyzer, the hyphenated string would not exist.
52
+
### Choose analyzers
50
53
51
-
> [!TIP]
52
-
> Consider using the [Analyze Text API](https://docs.microsoft.com/rest/api/searchservice/test-analyzer) for insight into how terms are tokenized and subsequently prefixed. Once you build an index, you can try various analyzers on a string to view the tokens it emits.
54
+
Your choice of an analyzer determines how fields are tokenized and subsequently prefixed. For example, for a hyphenated string like "context-sensitive", using a language analyzer will result in these token combinations: "context", "sensitive", "context-sensitive". Had you used the standard Lucene analyzer, the hyphenated string would not exist.
55
+
56
+
When evaluating analyzers, consider using the [Analyze Text API](https://docs.microsoft.com/rest/api/searchservice/test-analyzer) for insight into how terms are tokenized and subsequently prefixed. Once you build an index, you can try various analyzers on a string to view token output.
57
+
58
+
Fields that use [custom analyzers](index-add-custom-analyzers.md) or [predefined analyzers](index-add-custom-analyzers.md#predefined-analyzers-reference) (with the exception of standard Lucene) are explicitly disallowed to prevent poor outcomes.
59
+
60
+
> [!NOTE]
61
+
> If you need to work around the analyzer constraint, for example if you need a keyword or ngram analyzer for certain query scenarios, you should use two separate fields for the same content. This will allow one of the fields to have a suggester, while the other can be set up with a custom analyzer configuration.
53
62
54
63
### When to create a suggester
55
64
@@ -59,8 +68,7 @@ If you try to create a suggester using pre-existing fields, the API will disallo
59
68
60
69
## Create using REST
61
70
62
-
In the REST API, add suggesters through [Create Index](https://docs.microsoft.com/rest/api/searchservice/create-index) or
In the REST API, add suggesters through [Create Index](https://docs.microsoft.com/rest/api/searchservice/create-index) or [Update Index](https://docs.microsoft.com/rest/api/searchservice/update-index).
64
72
65
73
```json
66
74
{
@@ -158,7 +166,7 @@ POST /indexes/myxboxgames/docs/autocomplete?search&api-version=2019-05-06
158
166
159
167
## Next steps
160
168
161
-
We recommend the following example to see how the requests are formulated.
169
+
We recommend the following article to learn more about how requests formulation.
162
170
163
171
> [!div class="nextstepaction"]
164
172
> [Add autocomplete and suggestions to client code](search-autocomplete-tutorial.md)
Copy file name to clipboardExpand all lines: articles/search/search-autocomplete-tutorial.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,12 +60,13 @@ Responses for autocomplete and suggestions are what you might expect for the pat
60
60
61
61
Responses are shaped by the parameters on the request. For Autocomplete, set [**autocompleteMode**](https://docs.microsoft.com/rest/api/searchservice/autocomplete#autocomplete-modes) to determine whether text completion occurs on one or two terms. For Suggestions, the field you choose determines the contents of the response.
62
62
63
-
To further refine the response, include more parameters on the request. The following parameters apply to both Autocomplete and Suggestions.
63
+
For suggestions, you should further refine the response to avoid duplicates or what appears to be unrelated results. To control results, include more parameters on the request. The following parameters apply to both autocomplete and suggestions, but are perhaps more necessary for suggestions, especially when a suggester includes multiple fields.
64
64
65
65
| Parameter | Usage |
66
66
|-----------|-------|
67
-
|**$select**| If you have multiple **sourceFields**, use **$select** to choose which field contributes values (`$select=GameTitle`). |
68
-
|**$filter**| Apply match criteria on the result set (`$filter=ActionAdventure`). |
67
+
|**$select**| If you have multiple **sourceFields** in a suggester, use **$select** to choose which field contributes values (`$select=GameTitle`). |
68
+
|**searchFields**| Constrain the query to specific fields. |
69
+
|**$filter**| Apply match criteria on the result set (`$filter=Category eq 'ActionAdventure'`). |
69
70
|**$top**| Limit the results to a specific number (`$top=5`).|
0 commit comments