gpt4 book ai didi

azure - 如何在Azure搜索中使用top和skip来更正分页?

转载 作者:行者123 更新时间:2023-12-03 04:49:48 24 4
gpt4 key购买 nike

根据此文档Total hits and Page Counts ,如果我想实现分页,我应该在查询中结合使用skip和top。

以下是我的 POST 查询

{
"count": true ,
"search": "apple",
"searchFields": "content",
"select": "itemID, content",
"searchMode": "all",
"queryType":"full",
"skip": 100,
"top":100

}

它应该返回类似 100 --> 200 的内容

{
"@odata.context": "https://example.search.windows.net/indexes('example-index-')/$metadata#docs(*)",
"@odata.count": 1611,
"@search.nextPageParameters": {
"count": true,
"search": "apple",
"searchFields": "content",
"select": "itemID, content",
"searchMode": "all",
"queryType": "full",
"skip": 200
},

但它只返回 top 100 ,而不是分页偏移到 100

 "@odata.context": "https://example.search.windows.net/indexes('example-index')/$metadata#docs(*)",
"@odata.count": 1611,

有什么我应该设置的吗?

最佳答案

如何实现分页的简短答案(来自 this article ):将 top 设置为您所需的页面大小,然后在每次请求时按该页面大小增加 skip 。以下是使用 GET 的 REST API 的示例:

GET /indexes/onlineCatalog/docs?search=*$top=15&$skip=0
GET /indexes/onlineCatalog/docs?search=*$top=15&$skip=15
GET /indexes/onlineCatalog/docs?search=*$top=15&$skip=30

REST API documentation还介绍了如何实现分页,以及 @odata.nextLink@search.nextPageParameters 的真正用途(也在 this related question 中介绍)。

引用 API 引用:

Continuation of Partial Search Responses

Sometimes Azure Search can't return all the requested results in a single Search response. This can happen for different reasons, such as when the query requests too many documents by not specifying $top or specifying a value for $top that is too large. In such cases, Azure Search will include the @odata.nextLink annotation in the response body, and also @search.nextPageParameters if it was a POST request. You can use the values of these annotations to formulate another Search request to get the next part of the search response. This is called a continuation of the original Search request, and the annotations are generally called continuation tokens. See the example in Response below for details on the syntax of these annotations and where they appear in the response body.

The reasons why Azure Search might return continuation tokens are implementation-specific and subject to change. Robust clients should always be ready to handle cases where fewer documents than expected are returned and a continuation token is included to continue retrieving documents. Also note that you must use the same HTTP method as the original request in order to continue. For example, if you sent a GET request, any continuation requests you send must also use GET (and likewise for POST).

Note

The purpose of @odata.nextLink and @search.nextPageParameters is to protect the service from queries that request too many results, not to provide a general mechanism for paging. If you want to page through results, use $top and $skip together. For example, if you want pages of size 10, your first request should have $top=10 and $skip=0, the second request should have $top=10 and $skip=10, the third request should have $top=10 and $skip=20, and so on.

关于azure - 如何在Azure搜索中使用top和skip来更正分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55258465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com