Skip to content

Commit e310ec2

Browse files
authored
Merge pull request #112155 from HeidiSteen/heidist-search
[Azure Cog Search] Autocomplete/suggestion fields
2 parents de27d91 + bd4cb7c commit e310ec2

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

articles/search/index-add-suggesters.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: HeidiSteen
88
ms.author: heidist
99
ms.service: cognitive-search
1010
ms.topic: conceptual
11-
ms.date: 04/14/2020
11+
ms.date: 04/21/2020
1212
---
1313

1414
# 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
2929

3030
## What is a suggester?
3131

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

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
3535

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

39-
## Define a suggester
38+
+ Use string fields only
4039

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
4241

4342
### Choose fields
4443

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

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

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
5053

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.
5362
5463
### When to create a suggester
5564

@@ -59,8 +68,7 @@ If you try to create a suggester using pre-existing fields, the API will disallo
5968

6069
## Create using REST
6170

62-
In the REST API, add suggesters through [Create Index](https://docs.microsoft.com/rest/api/searchservice/create-index) or
63-
[Update Index](https://docs.microsoft.com/rest/api/searchservice/update-index).
71+
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).
6472

6573
```json
6674
{
@@ -158,7 +166,7 @@ POST /indexes/myxboxgames/docs/autocomplete?search&api-version=2019-05-06
158166

159167
## Next steps
160168

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

163171
> [!div class="nextstepaction"]
164172
> [Add autocomplete and suggestions to client code](search-autocomplete-tutorial.md)

articles/search/search-autocomplete-tutorial.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ Responses for autocomplete and suggestions are what you might expect for the pat
6060

6161
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.
6262

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

6565
| Parameter | Usage |
6666
|-----------|-------|
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'`). |
6970
| **$top** | Limit the results to a specific number (`$top=5`).|
7071

7172
## Add user interaction code
@@ -145,6 +146,8 @@ public ActionResult Suggest(bool highlights, bool fuzzy, string term)
145146
// Call suggest API and return results
146147
SuggestParameters sp = new SuggestParameters()
147148
{
149+
Select = HotelName,
150+
SearchFields = HotelName,
148151
UseFuzzyMatching = fuzzy,
149152
Top = 5
150153
};

0 commit comments

Comments
 (0)