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-capacity-planning.md
+3-2Lines changed: 3 additions & 2 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: 02/14/2020
11
+
ms.date: 03/30/2020
12
12
---
13
13
14
14
# Adjust capacity in Azure Cognitive Search
@@ -34,7 +34,8 @@ A single service must have sufficient resources to handle all workloads (indexin
34
34
35
35
As a general rule, search applications tend to need more replicas than partitions, particularly when the service operations are biased toward query workloads. The section on [high availability](#HA) explains why.
36
36
37
-
Adding more replicas or partitions increases your cost of running the service. Be sure to check the [pricing calculator](https://azure.microsoft.com/pricing/calculator/) to understand the billing implications of adding more nodes. The [chart below](#chart) can help you cross-reference the number of search units required for a specific configuration.
37
+
> [!NOTE]
38
+
> Adding more replicas or partitions increases the cost of running the service, and can introduce slight variations in how results are ordered. Be sure to check the [pricing calculator](https://azure.microsoft.com/pricing/calculator/) to understand the billing implications of adding more nodes. The [chart below](#chart) can help you cross-reference the number of search units required for a specific configuration. For more information on how additional replicas impact query processing, see [Ordering results](search-pagination-page-layout.md#ordering-results).
Copy file name to clipboardExpand all lines: articles/search/search-pagination-page-layout.md
+60-82Lines changed: 60 additions & 82 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,98 +8,95 @@ author: HeidiSteen
8
8
ms.author: heidist
9
9
ms.service: cognitive-search
10
10
ms.topic: conceptual
11
-
ms.date: 01/24/2020
11
+
ms.date: 04/01/2020
12
12
---
13
13
14
14
# How to work with search results in Azure Cognitive Search
15
-
This article provides guidance on how to implement standard elements of a search results page, such as total counts, document retrieval, sort orders, and navigation. Page-related options that contribute data or information to your search results are specified through the [Search Document](https://docs.microsoft.com/rest/api/searchservice/Search-Documents) requests sent to your Azure Cognitive Search service.
16
15
17
-
In the REST API, requests include a GET command, path, and query parameters that inform the service what is being requested, and how to formulate the response. In the .NET SDK, the equivalent API is [DocumentSearchResult Class](https://docs.microsoft.com/dotnet/api/microsoft.azure.search.models.documentsearchresult-1).
16
+
This article explains how to get a query response that comes back with a total count of matching documents, paginated results, sorted results, and hit-highlighted terms.
18
17
19
-
To quickly generate a search page for your client, explore these options:
18
+
The structure of a response is determined by parameters in the query: [Search Document](https://docs.microsoft.com/rest/api/searchservice/Search-Documents) in the REST API, or [DocumentSearchResult Class](https://docs.microsoft.com/dotnet/api/microsoft.azure.search.models.documentsearchresult-1) in the .NET SDK.
20
19
21
-
+ Use the [application generator](search-create-app-portal.md) in the portal to create an HTML page with a search bar, faceted navigation, and results area.
22
-
+ Follow the [Create your first app in C#](tutorial-csharp-create-first-app.md) tutorial to create a functional client.
20
+
## Result composition
23
21
24
-
Several code samples include a web front-end interface, which you can find here: [New York City Jobs demo app](https://aka.ms/azjobsdemo), [JavaScript sample code with a live demo site](https://github.com/liamca/azure-search-javascript-samples), and [CognitiveSearchFrontEnd](https://github.com/LuisCabrer/CognitiveSearchFrontEnd).
22
+
While a search document might consist of a large number of fields, typically only a few are needed to represent each document in the result set. On a query request, append `$select=<field list>` to specify which fields show up in the response. A field must be attributed as **Retrievable** in the index to be included in a result.
25
23
26
-
> [!NOTE]
27
-
> A valid request includes a number of elements, such as a service URL and path, HTTP verb, `api-version`, and so on. For brevity, we trimmed the examples to highlight just the syntax that is relevant to pagination. For more information about request syntax, see [Azure Cognitive Search REST APIs](https://docs.microsoft.com/rest/api/searchservice).
28
-
>
29
-
30
-
## Total hits and Page Counts
31
-
32
-
Showing the total number of results returned from a query, and then returning those results in smaller chunks, is fundamental to virtually all search pages.
33
-
34
-
![][1]
35
-
36
-
In Azure Cognitive Search, you use the `$count`, `$top`, and `$skip` parameters to return these values. The following example shows a sample request for total hits on an index called "online-catalog", returned as `@odata.count`:
37
-
38
-
GET /indexes/online-catalog/docs?$count=true
39
-
40
-
Retrieve documents in groups of 15, and also show the total hits, starting at the first page:
41
-
42
-
GET /indexes/online-catalog/docs?search=*&$top=15&$skip=0&$count=true
43
-
44
-
Paginating results requires both `$top` and `$skip`, where `$top` specifies how many items to return in a batch, and `$skip` specifies how many items to skip. In the following example, each page shows the next 15 items, indicated by the incremental jumps in the `$skip` parameter.
45
-
46
-
GET /indexes/online-catalog/docs?search=*&$top=15&$skip=0&$count=true
47
-
48
-
GET /indexes/online-catalog/docs?search=*&$top=15&$skip=15&$count=true
49
-
50
-
GET /indexes/online-catalog/docs?search=*&$top=15&$skip=30&$count=true
24
+
Fields that work best include those that contrast and differentiate among documents, providing sufficient information to invite a click-through response on the part of the user. On an e-commerce site, it might be a product name, description, brand, color, size, price, and rating. For the hotels-sample-index built-in sample, it might be fields in the following example:
51
25
52
-
## Layout
26
+
```http
27
+
POST /indexes/hotels-sample-index/docs/search?api-version=2019-05-06
On a search results page, you might want to show a thumbnail image, a subset of fields, and a link to a full product page.
35
+
> [!NOTE]
36
+
> If want to include image files in a result, such as a product photo or logo, store them outside of Azure Cognitive Search, but include a field in your index to reference the image URL in the search document. Sample indexes that support images in the results include the **realestate-sample-us** demo, featured in this [quickstart](search-create-app-portal.md), and the [New York City Jobs demo app](https://aka.ms/azjobsdemo).
55
37
56
-
![][2]
38
+
## Results returned
57
39
58
-
In Azure Cognitive Search, you would use `$select` and a [Search API request](https://docs.microsoft.com/rest/api/searchservice/search-documents) to implement this experience.
40
+
By default, the search engine returns up to the first 50 matches, as determined by search score if the query is full text search, or in an arbitrary order for exact match queries.
59
41
60
-
To return a subset of fields for a tiled layout:
42
+
To return a different number of matching documents, add `$top` and `$skip` parameters to the query request. The following list explains the logic.
61
43
62
-
GET /indexes/online-catalog/docs?search=*&$select=productName,imageFile,description,price,rating
44
+
+ Add `$count=true` to get a count of the total number of matching documents within an index.
63
45
64
-
Images and media files are not directly searchable and should be stored in another storage platform, such as Azure Blob storage, to reduce costs. In the index and documents, define a field that stores the URL address of the external content. You can then use the field as an image reference. The URL to the image should be in the document.
46
+
+ Return the first set of 15 matching documents plus a count of total matches: `GET /indexes/<INDEX-NAME>/docs?search=<QUERY STRING>&$top=15&$skip=0&$count=true`
65
47
66
-
To retrieve a product description page for an **onClick** event, use [Lookup Document](https://docs.microsoft.com/rest/api/searchservice/Lookup-Document) to pass in the key of the document to retrieve. The data type of the key is `Edm.String`. In this example, it is *246810*.
48
+
+ Return the second set, skipping the first 15 to get the next 15: `$top=15&$skip=15`. Do the same for the third set of 15: `$top=15&$skip=30`
67
49
68
-
GET /indexes/online-catalog/docs/246810
50
+
The results of paginated queries are not guaranteed to be stable if the underlying index is changing. Paging changes the value of `$skip` for each page, but each query is independent and operates on the current view of the data as it exists in the index at query time (in other words, there is no caching or snapshot of results, such as those found in a general purpose database).
51
+
52
+
Following is an example of how you might get duplicates. Assume an index with four documents:
69
53
70
-
## Sort by relevance, rating, or price
54
+
{ "id": "1", "rating": 5 }
55
+
{ "id": "2", "rating": 3 }
56
+
{ "id": "3", "rating": 2 }
57
+
{ "id": "4", "rating": 1 }
58
+
59
+
Now assume you want results returned two at a time, ordered by rating. You would execute this query to get the first page of results: `$top=2&$skip=0&$orderby=rating desc`, producing the following results:
71
60
72
-
Sort orders often default to relevance, but it's common to make alternative sort orders readily available so that customers can quickly reshuffle existing results into a different rank order.
61
+
{ "id": "1", "rating": 5 }
62
+
{ "id": "2", "rating": 3 }
63
+
64
+
On the service, assume a fifth document is added to the index in between query calls: `{ "id": "5", "rating": 4 }`. Shortly thereafter, you execute a query to fetch the second page: `$top=2&$skip=2&$orderby=rating desc`, and get these results:
73
65
74
-
![][3]
66
+
{ "id": "2", "rating": 3 }
67
+
{ "id": "3", "rating": 2 }
68
+
69
+
Notice that document 2 is fetched twice. This is because the new document 5 has a greater value for rating, so it sorts before document 2 and lands on the first page. While this behavior might be unexpected, it's typical of how a search engine behaves.
75
70
76
-
In Azure Cognitive Search, sorting is based on the `$orderby` expression, for all fields that are indexed as `"Sortable": true.` An `$orderby` clause is an OData expression. For information about syntax, see [OData expression syntax for filters and order-by clauses](query-odata-filter-orderby-syntax.md).
71
+
## Ordering results
77
72
78
-
Relevance is strongly associated with scoring profiles. You can use the default scoring, which relies on text analysis and statistics to rank order all results, with higher scores going to documents with more or stronger matches on a search term.
73
+
For full text search queries, results are automatically ranked by a search score, calculated based on term frequency and proximity in a document, with higher scores going to documents having more or stronger matches on a search term. Search scores convey general sense of relevance, relative to other documents in the same results set, and are not guaranteed to be consistent from one query to the next.
79
74
80
-
Alternative sort orders are typically associated with **onClick** events that call back to a method that builds the sort order. For example, given this page element:
75
+
As you work with queries, you might notice small discrepancies in ordered results. There are several explanations for why this might occur.
81
76
82
-
![][4]
77
+
| Condition | Description |
78
+
|-----------|-------------|
79
+
| Data volatility | The contents of an index varies as you add, modify, or delete documents. Term frequencies will change as index updates are processed over time, affecting the search scores of matching documents. |
80
+
| Query execution location | For services using multiple replicas, queries are issued against each replica in parallel. The index statistics used to calculate a search score are calculated on a per-replica basis, with results merged and ordered in the query response. Replicas are mostly mirrors of each other, but statistics can differ due to small differences in state. For example, one replica might have deleted documents contributing to their statistics, which were merged out of other replicas. Generally, differences in per-replica statistics are more noticeable in smaller indexes. |
81
+
| Breaking a tie between identical search scores | Discrepancies in ordered results can also occur when search documents have identical scores. In this case, as you rerun the same query, there is no guarantee which document will appear first. |
83
82
84
-
You would create a method that accepts the selected sort option as input, and returns an ordered list for the criteria associated with that option.
83
+
### Consistent ordering
85
84
86
-
![][5]
85
+
Given the flex in search scoring, you might want to explore other options if consistency in result orders is an application requirement. The easiest approach is sorting by a field value, such as rating or date. For scenarios where you want to sort by a specific field, such as a rating or date, you can explicitly define an [`$orderby` expression](query-odata-filter-orderby-syntax.md), which can be applied to any field that is indexed as **Sortable**.
87
86
88
-
> [!NOTE]
89
-
> While the default scoring is sufficient for many scenarios, we recommend basing relevance on a custom scoring profile instead. A custom scoring profile gives you a way to boost items that are more beneficial to your business. See [Add scoring profiles](index-add-scoring-profiles.md) for more information.
90
-
>
87
+
Another option is using a [custom scoring profile](index-add-scoring-profiles.md). Scoring profiles give you more control over the ranking of items in search results, with the ability to boost matches found in specific fields. The additional scoring logic can help override minor differences among replicas because the search scores for each document are farther apart. We recommend the [ranking algorithm](index-ranking-similarity.md) for this approach.
91
88
92
89
## Hit highlighting
93
90
94
-
You can apply formatting to matching terms in search results, making it easy to spot the match. Hit highlighting instructions are provided on the [query request](https://docs.microsoft.com/rest/api/searchservice/search-documents).
91
+
Hit highlighting refers to text formatting (such as bold or yellow highlights) applied to matching term in a result, making it easy to spot the match. Hit highlighting instructions are provided on the [query request](https://docs.microsoft.com/rest/api/searchservice/search-documents). The search engine encloses the matching term in tags, `highlightPreTag` and `highlightPostTag`, and your code handles the response (for example, applying a bold font).
95
92
96
-
Formatting is applied to whole term queries. Queries on partial terms, such as fuzzy search or wildcard search that result in query expansion in the engine, cannot use hit highlighting.
93
+
Formatting is applied to whole term queries. In the following example, the terms "sandy", "sand", "beaches", "beach" found within the Description field are tagged for highlighting. Queries on partial terms, such as fuzzy search or wildcard search that result in query expansion in the engine, cannot use hit highlighting.
97
94
98
95
```http
99
-
POST /indexes/hotels/docs/search?api-version=2019-05-06
96
+
POST /indexes/hotels-sample-index/docs/search?api-version=2019-05-06
100
97
{
101
-
"search": "something",
102
-
"highlight": "Description"
98
+
"search": "sandy beaches",
99
+
"highlight": "Description"
103
100
}
104
101
```
105
102
@@ -108,30 +105,11 @@ POST /indexes/hotels/docs/search?api-version=2019-05-06
108
105
>
109
106
> When you are writing client code that implements hit highlighting, be aware of this change. Note that this will not impact you unless you create a completely new search service.
110
107
111
-
## Faceted navigation
112
-
113
-
Search navigation is common on a results page, often located at the side or top of a page. In Azure Cognitive Search, faceted navigation provides self-directed search based on predefined filters. See [Faceted navigation in Azure Cognitive Search](search-faceted-navigation.md) for details.
114
-
115
-
## Filters at the page level
116
-
117
-
If your solution design included dedicated search pages for specific types of content (for example, an online retail application that has departments listed at the top of the page), you can insert a [filter expression](search-filters.md) alongside an **onClick** event to open a page in a pre-filtered state.
118
-
119
-
You can send a filter with or without a search expression. For example, the following request will filter on brand name, returning only those documents that match it.
120
-
121
-
GET /indexes/online-catalog/docs?$filter=brandname eq 'Microsoft' and category eq 'Games'
122
-
123
-
See [Search Documents (Azure Cognitive Search API)](https://docs.microsoft.com/rest/api/searchservice/Search-Documents) for more information about `$filter` expressions.
108
+
## Next steps
124
109
125
-
## See Also
110
+
To quickly generate a search page for your client, consider these options:
-[Faceted Navigation in Azure Cognitive Search](search-faceted-navigation.md)
112
+
+[Application Generator](search-create-app-portal.md), in the portal, creates an HTML page with a search bar, faceted navigation, and results area that includes images.
113
+
+[Create your first app in C#](tutorial-csharp-create-first-app.md) is a tutorial that builds a functional client. Sample code demonstrates paginated queries, hit highlighting, and sorting.
Several code samples include a web front-end interface, which you can find here: [New York City Jobs demo app](https://aka.ms/azjobsdemo), [JavaScript sample code with a live demo site](https://github.com/liamca/azure-search-javascript-samples), and [CognitiveSearchFrontEnd](https://github.com/LuisCabrer/CognitiveSearchFrontEnd).
0 commit comments