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/search-faceted-navigation.md
+106-9Lines changed: 106 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ ms.date: 02/26/2025
13
13
14
14
# Add faceted navigation to a search app
15
15
16
-
Faceted navigation is used for self-directed drill-down filtering on query results in a search app, where your application offers form controls for scoping search to groups of documents (for example, categories or brands), and Azure AI Search provides the data structures and filters to back the experience.
16
+
Faceted navigation is used for self-directed drill-down filtering on query results in a search app, where your application offers form controls for scoping search to groups of documents (for example, categories or brands), and Azure AI Search provides the data structures and filters to back the experience.
17
17
18
18
In this article, learn how to return a faceted navigation structure in Azure AI Search.
19
19
@@ -175,9 +175,9 @@ Recall that facets are calculated from results in a query response. You only get
175
175
176
176
Interval facets on date time are computed based on the UTC time if `timeoffset` isn't specified. For example: for "facet=lastRenovationDate,interval:day", the day boundary starts at 00:00:00 UTC.
177
177
178
-
### Facet example
178
+
### Basic facet example
179
179
180
-
The following example works against the hotels sample index. It shows three facets for "Category", "Tags", and "Rating", with a count override on "Tags" and explicit whole number values set on "Rating", which is otherwise a float value in the index.
180
+
The following example works against the [hotels sample index](search-get-started-portal.md). You can use **JSON view** in Search Explorer to paste in the JSON query. This example shows three facets for "Category", "Tags", and "Rating", with a count override on "Tags" and explicit whole number values set on "Rating", which is otherwise a float value in the index.
181
181
182
182
```http
183
183
POST https://{{service_name}}.search.windows.net/indexes/hotels/docs/search?api-version={{api_version}}
@@ -192,12 +192,109 @@ POST https://{{service_name}}.search.windows.net/indexes/hotels/docs/search?api-
192
192
}
193
193
```
194
194
195
-
For each faceted navigation tree, there's a default limit of the top 10 facet instances found in search results. This default makes sense for navigation structures because it keeps the values list to a manageable size. You can override the default by assigning a value to "count". For example, `"Tags,count:5"` reduces the number of tags under the Tags section to the top five.
195
+
For each faceted navigation tree, there's a default limit of the top 10 facet instances found by the query. This default makes sense for navigation structures because it keeps the values list to a manageable size. You can override the default by assigning a value to "count". For example, `"Tags,count:5"` reduces the number of tags under the Tags section to the top five.
196
196
197
197
For Numeric and DateTime values only, you can explicitly set values on the facet field (for example, `facet=Rating,values:1|2|3|4|5`) to separate results into contiguous ranges (either ranges based on numeric values or time periods). Alternatively, you can add "interval", as in `facet=Rating,interval:1`.
198
198
199
199
Each range is built using 0 as a starting point, a value from the list as an endpoint, and then trimmed of the previous range to create discrete intervals.
200
200
201
+
### Distinct values example
202
+
203
+
You can formulate a query that returns a distinct value count for each facetable field. This example formulates a query that sets `top` to zero, returning just the counts, with no results.
204
+
205
+
For brevity, it includes just two fields marked as "facetable" in the hotels sample index.
206
+
207
+
```http
208
+
POST https://{{service_name}}.search.windows.net/indexes/hotels/docs/search?api-version={{api_version}}
209
+
{
210
+
"search": "*",
211
+
"count": true,
212
+
"top": 0,
213
+
"facets": [
214
+
"Category", "Address/StateProvince""
215
+
]
216
+
}
217
+
```
218
+
219
+
Results from this query are as follows:
220
+
221
+
```json
222
+
{
223
+
"@odata.count": 50,
224
+
"@search.facets": {
225
+
"Address/StateProvince": [
226
+
{
227
+
"count": 9,
228
+
"value": "WA"
229
+
},
230
+
{
231
+
"count": 6,
232
+
"value": "CA "
233
+
},
234
+
{
235
+
"count": 4,
236
+
"value": "FL"
237
+
},
238
+
{
239
+
"count": 3,
240
+
"value": "NY"
241
+
},
242
+
{
243
+
"count": 3,
244
+
"value": "OR"
245
+
},
246
+
{
247
+
"count": 3,
248
+
"value": "TX"
249
+
},
250
+
{
251
+
"count": 2,
252
+
"value": "GA"
253
+
},
254
+
{
255
+
"count": 2,
256
+
"value": "MA"
257
+
},
258
+
{
259
+
"count": 2,
260
+
"value": "TN"
261
+
},
262
+
{
263
+
"count": 1,
264
+
"value": "AZ"
265
+
}
266
+
],
267
+
"Category": [
268
+
{
269
+
"count": 13,
270
+
"value": "Budget"
271
+
},
272
+
{
273
+
"count": 12,
274
+
"value": "Suite"
275
+
},
276
+
{
277
+
"count": 7,
278
+
"value": "Boutique"
279
+
},
280
+
{
281
+
"count": 7,
282
+
"value": "Resort and Spa"
283
+
},
284
+
{
285
+
"count": 6,
286
+
"value": "Extended-Stay"
287
+
},
288
+
{
289
+
"count": 5,
290
+
"value": "Luxury"
291
+
}
292
+
]
293
+
},
294
+
"value": []
295
+
}
296
+
```
297
+
201
298
## Best practices for working with facets
202
299
203
300
This section is a collection of tips and workarounds that are helpful for application development.
@@ -230,9 +327,11 @@ If you want a static set of facets alongside a dynamic drilldown experience, you
230
327
231
328
When you design the user experience, remember to add a mechanism for clearing facets. A common approach for clearing facets is issuing an empty search request to reset the page.
232
329
233
-
### Trim facet results with more filters
330
+
### Handling large facet counts
234
331
235
-
Facet results are documents found in the search results that match a facet term. In the following example, in search results for *cloud computing*, 254 items also have *internal specification* as a content type. Items aren't necessarily mutually exclusive. If an item meets the criteria of both filters, it's counted in each one. This duplication is possible when faceting on `Collection(Edm.String)` fields, which are often used to implement document tagging.
332
+
Search results and facet results that are too large can be trimmed by [adding filters](search-filters.md). In the following example, in the query for *cloud computing*, 254 items have *internal specification* as a content type. If results are too large, adding filters can help your users re-scope the query by adding more criteria.
333
+
334
+
Items aren't necessarily mutually exclusive. If an item meets the criteria of both filters, it's counted in each one. This duplication is possible when faceting on `Collection(Edm.String)` fields, which are often used to implement document tagging.
236
335
237
336
```output
238
337
Search term: "cloud computing"
@@ -241,8 +340,6 @@ Content type
241
340
Video (10)
242
341
```
243
342
244
-
In general, if you find that facet results are consistently too large, we recommend that you add more filters to give users more options for narrowing the search.
245
-
246
343
## Next steps
247
344
248
-
We recommend the [C#: Add search to web apps](tutorial-csharp-overview.md) for an example of faceted navigation. The sample also includes filters, suggestions, and autocomplete. It uses JavaScript and React for the presentation layer.
345
+
We recommend the [C#: Add search to web apps](tutorial-csharp-overview.md) for an example of faceted navigation that includes code for the presentation layer. The sample also includes filters, suggestions, and autocomplete. It uses JavaScript and React for the presentation layer.
0 commit comments