Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取Azure搜索中的实际匹配数_Azure_Azure Cognitive Search_Azure Search .net Sdk - Fatal编程技术网

获取Azure搜索中的实际匹配数

获取Azure搜索中的实际匹配数,azure,azure-cognitive-search,azure-search-.net-sdk,Azure,Azure Cognitive Search,Azure Search .net Sdk,Azure搜索一次最多返回1000个结果。对于客户端上的分页,我需要匹配的总计数,以便能够在底部显示正确数量的分页按钮,并且能够告诉用户有多少个结果。但是,如果有超过1000个,我如何获得实际计数?我只知道至少有1000场比赛 我需要能够从SDK中执行此操作。如果要获取索引中的文档总数,可以在搜索参数中将其设置为true。执行查询时执行此操作后,您将在搜索结果属性的索引中看到文档总数 下面是一个示例代码: var credentials = new SearchCredentia

Azure搜索一次最多返回1000个结果。对于客户端上的分页,我需要匹配的总计数,以便能够在底部显示正确数量的分页按钮,并且能够告诉用户有多少个结果。但是,如果有超过1000个,我如何获得实际计数?我只知道至少有1000场比赛


我需要能够从SDK中执行此操作。

如果要获取索引中的文档总数,可以在搜索参数中将其设置为
true
。执行查询时执行此操作后,您将在搜索结果属性的索引中看到文档总数

下面是一个示例代码:

        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
请注意:

  • 此计数为近似值
  • 获取计数是一项昂贵的操作,因此在实现分页时,您应该只在第一个请求时执行此操作

对于使用POST API的REST客户端,只需在有效负载中包含
“count”:“true”
。您可以在
@odata.count
中获得计数


Ref:

感谢您在结果的第一页上提供了使用它的提示。我将只让IncludeTotalResultCount=skip==0。如果其他人遇到相同的问题,参数名称从11.0.0开始更改为“includeTotalCount”(根据更改日志)。在这篇评论中,我看到的大多数示例都显示了旧的参数名,它为count返回了“undefined”(至少从11.0.3开始)。