获取Azure搜索中的实际匹配数 [英] Get actual count of matches in Azure Search

查看:84
本文介绍了获取Azure搜索中的实际匹配数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Azure搜索一次最多返回1,000个结果.对于客户端上的分页,我希望匹配的总数以便能够在底部显示正确数量的分页按钮,并能够告诉用户那里有多少结果是.但是,如果数量超过一千,我如何获得实际数量?我所知道的是,至少有 1,000个匹配项.

Azure Search returns a maximum of 1,000 results at a time. For paging on the client, I want the total count of matches in order to be able to display the correct number of paging buttons at the bottom and in order to be able to tell the user how many results there are. However, if there are over a thousand, how do I get the actual count? All I know is that there were at least 1,000 matches.

我需要能够在SDK中执行此操作.

I need to be able to do this from within the SDK.

推荐答案

如果要获取索引中的文档总数,则可以设置搜索结果的属性Count .

If you want to get total number of documents in an index, one thing you could do is set IncludeTotalResultCount to true in your search parameters. Once you do that when you execute the query, you will see the count of total documents in an index in Count property of search results.

这是一个示例代码:

        var credentials = new SearchCredentials("account-key (query or admin key)");
        var indexClient = new SearchIndexClient("account-name", "index-name", credentials);
        var searchParameters = new SearchParameters()
        {
            QueryType = QueryType.Full,
            IncludeTotalResultCount = true
        };
        var searchResults = await indexClient.Documents.SearchAsync("*", searchParameters);
        Console.WriteLine("Total documents in index (approx) = " + searchResults.Count.GetValueOrDefault());//Prints the total number of documents in the index

请注意:

  • 这个数字是大概的.
  • 获取计数是一项昂贵的操作,因此在实现分页时,只应对第一个请求进行计数.

这篇关于获取Azure搜索中的实际匹配数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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