Azure搜索一次最多返回1,000个结果。对于客户端上的分页,我想要匹配的总计数,以便能够在底部显示正确数量的分页按钮,以便能够告诉用户有多少结果是。但是,如果有超过一千,我如何获得实际数量?我所知道的是至少 1,000次匹配。
我需要能够在SDK中执行此操作。
答案 0 :(得分:1)
如果您想获得索引中的文档总数,您可以做的一件事就是在搜索参数中将IncludeTotalResultCount
设置为$(document).ready(function(){
var s = 4;
$(".btn").on('click', function(){
var n = $("li.selected").first().index();
if (n >= 0) {
if ($("li").first().is(".selected") && $("li").last().is(".selected")) {
n = $("li").not(".selected").first().nextAll(".selected").first().index();
}
$("li").removeClass("selected");
var markStart = n - s;
if (markStart < 0) {
$("li")
.slice(0, n)
.addClass("selected");
markStart = $("li").length - s + n;
}
$("li")
.slice(markStart, markStart + s)
.addClass("selected");
}
});
});
。在执行查询时执行此操作后,您将在搜索结果的Count
属性中看到索引中的总文档数。
以下是该示例代码:
.btn{ text-decoration:none; background:blue; color:#fff; padding:5px; border-radius:4px;float:left;}
ul{ list-style:none;float:left;clear:both;}
ul li{ padding:5px;background:#555; color:#fff; float:left; border-radius:2px; margin:2px; }
.selected{ background:red;}
请注意:
答案 1 :(得分:0)
对于使用POST API的REST客户端,只需将"count": "true"
包括在有效负载中即可。您可以在@odata.count
中获得计数。
参考:https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents