为什么不能将ContinuationToken用于Azure搜索API中的页面调度? [英] Why can't ContinuationToken be used for paging in Azure Search API?

查看:175
本文介绍了为什么不能将ContinuationToken用于Azure搜索API中的页面调度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读Azure搜索.NET SDK的文档后,我发现ContinuationToken属性不应该用于分页(这与REST API中的@odata.nextLink@search.nextPageParameter属性相同).

Reading the documentation for the Azure Search .NET SDK, I see that the ContinuationToken property is not supposed to used for pagination (this is the same as the @odata.nextLink and @search.nextPageParameter properties in the REST API).

请注意,此属性并不旨在帮助您实现搜索结果的分页.您可以使用顶部"和跳过"搜索参数来实现分页. 来源

Note that this property is not meant to help you implement paging of search results. You can implement paging using the Top and Skip search parameters. Source

为什么我不能使用它进行分页?我遇到一种情况,我想运行查询,然后逐页浏览结果的静态副本.我不希望这些查询结果在我的脚下改变,因为当我浏览它们时,新文档已添加到基础数据库中.就我而言,在提交初始查询和导航到另一页之间的一两分钟内,可能会添加成百上千个结果.我该怎么办?

Why can't I use it for pagination? I have a situation where I want to run a query and then step through a static copy of the results page by page. I don't want those query results to change beneath my feet, however, as I am navigating through them, as new documents are added to the underlying database. In my case, there could be hundreds or thousands of results that get added in the minute or two between submitting the initial query and navigating to another page. How could I accomplish this?

推荐答案

您的问题可以分为两个部分:

Your question can be addressed in two parts:

  1. 为什么不建议使用ContinuationToken进行分页?
  2. 如何实现分页以使页面之间的结果保持完全稳定?
  1. Why is it not recommended to use ContinuationToken to implement pagination?
  2. How can pagination be implemented such that results remain completely stable from page to page?

这些实际上是不相关的问题,因为关于ContinuationToken的任何内容都不能保证搜索结果的稳定性.无论使用$top$skip还是ContinuationToken,Azure搜索均不能保证分页的一致性.

These are actually unrelated questions, since nothing about ContinuationToken guarantees the stability of the search results. Azure Search makes no consistency guarantees around paging, whether you use $top and $skip or ContinuationToken.

对于问题#1,不建议使用ContinuationToken进行分页的原因是Azure搜索控制何时返回令牌,而不是您的应用程序代码.如果您对Azure搜索决定如何以及何时决定向您返回令牌的假设,则将来的服务更新可能会破坏这些假设. ContinuationToken的目的是防止对太多文档的请求使服务不堪重负,因此,您应假定是否返回令牌完全由服务自行决定.

For question #1, the reason ContinuationToken is not recommended for paging is that Azure Search controls when the token is returned, not your application code. If you make assumptions about how and when Azure Search decides to return you a token, there's a chance those assumptions may break with a future service update. The intent of ContinuationToken is to prevent requests for too many documents from overwhelming the service, so you should assume that it is entirely at the service's discretion whether it will return a token.

对于问题2,由于Azure搜索不提供一致性保证,因此您无法完全避免在多个页面中显示同一文档,缺少文档或在文档中看到这些文档时将其删除的问题.结果.即使您想要构建自己的结果快照并在应用程序代码中对其进行分页,一开始也无法构建一致的快照.但是,如果您唯一的担心是避免在结果中显示新文档,则可以在索引中包括一个创建的时间戳字段,并在每个搜索请求中对此字段进行过滤.

For question #2, since Azure Search doesn't provide consistency guarantees, you can't completely avoid issues like the same document showing up in multiple pages, missing documents, or documents that are deleted by the time they are seen in results. Even if you wanted to build your own snapshot of the results and page over them in your application code, building a consistent snapshot isn't possible in the first place. However, if your only concern is to avoid showing new documents in the results, you can include a created timestamp field in your index and filter on that in every search request.

坦率地说,除非您试图导出索引的全部内容,否则我会问是否需要围绕分页提供如此强大的一致性保证. Google和Bing均不提供此类保证,因此可以说已经为此设定了用户期望.如果您要导出数据,不幸的是,今天使用Azure搜索并不容易.在这种情况下,请对此进行投票用户语音项,以帮助团队确定此方案的优先级.

Frankly, unless you're trying to export the entire contents of your index, I would question the need for such strong consistency guarantees around paging. Google and Bing make no such guarantees, so arguably user expectations are already set around this. If you are trying to export your data, this is unfortunately not easy with Azure Search today. In that case, please vote on this User Voice item to help the team prioritize this scenario.

这篇关于为什么不能将ContinuationToken用于Azure搜索API中的页面调度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆