azure认知服务——需要帮助理解Bing Web搜索API v5返回的结果



我已经更新了我之前用Bing Web搜索API的测试版创建的以下代码片段,以使用新的域名:api.cognitive.microsoft.com/bing/v5.0/search Bing Web搜索API现在使用的域名-

请替换您自己的Bing API密钥来运行示例

<!DOCTYPE html>
<html>
<head>
    <title>Bing Search v5 - show all results</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script>
var total;
var ofst = 0;
var pgcnt=50;
var results = '';
var burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=Bill Gates&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us&freshness=Month"; //737 results
//var burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=Bill Gates&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us"; //304 results
//var burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=site:mvark.blogspot.com&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us&freshness=Month"; 
$(function() { 
function xhr_get(url) {
  return $.ajax({
  url: url,
  beforeSend: function(xhrObj){
                // Request headers
                xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","abc123"); //replace value with your own key
            },
  type: "GET",
  })
 .done(function(data) {
      		total = data.webPages.totalEstimatedMatches; 
		len = data.webPages.value.length
		for (i=0; i<len; i++ )
		{
		   results += "<p><a href='" + data.webPages.value[i].url + "'>" + data.webPages.value[i].name + "</a>: " + data.webPages.value[i].snippet + "</p>";
		}
		$('#content').html(results);
	ofst += pgcnt;
	if (total > ofst) { 
	burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=Bill Gates&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us&freshness=Month"; 
	//burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=Bill Gates&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us"; 
	//burl = "https://api.cognitive.microsoft.com/bing/v5.0/search/?q=site:mvark.blogspot.com&count=" + pgcnt + "&offset=" + ofst + "&mkt=en-us&freshness=Month"; 
	xhr_get(burl);
	}
	else { console.log('No more results to show'); 
	}
  })
}
xhr_get(burl);
});
</script> 
Results:  <div id="content">Fetching...</div>
</body>
</html>

我看到了之前返回的结果之间的差异&现在结果出来了。我想知道我的代码是否有问题,导致行为改变,并回答以下问题:

  1. 对于一些搜索关键字,我看到返回的最大结果现在正好是1000 (totalEstimatedMatches=1000),尽管如果我通过Bing的网站搜索,会有更多的结果。1000是最大限制吗?是否有一些限制?
  2. 新鲜度=月请求参数被添加,它返回更多的结果,我会得到,如果我不使用它?是不是默认的行为,以获取所有结果,如果新鲜度没有指定?
    Bing没有totalEstimatedMatches的最大值。尽管重要的是要记住这是一个估计,我们不知道估计具体意味着什么。据我们所知,它可能意味着500 < totalEstimatedMatches < 2000。他们如何"估计"这个数字并没有出现在文档中。
  1. 我盯着你的第二个问题看了很长时间才弄清楚不和谐在哪里。尝试将&responseFilter=Webpages附加到您正在制作的所有url的末尾。当你把你的回答制成表格时,看起来你只计算了网页结果,但没有指定你的查询只返回网页结果。

最新更新