【问题标题】:Need help understanding results returned by Bing Web Search API v5需要帮助了解 Bing Web Search API v5 返回的结果
【发布时间】:2016-07-03 12:00:58
【问题描述】:

我更新了我之前使用beta version of the Bing Web Search API 创建的以下 sn-p 以使用newer domain nameapi.cognitive.microsoft.com/bing/v5.0/search Bing Web Search 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. 当添加 freshness=Month 请求参数时,它返回的结果比我不使用它时会得到的结果多吗?如果未指定新鲜度,默认行为不是获取所有结果吗?

【问题讨论】:

  • 我发现可以找到的网页内容较少。其他人有同样的观察吗?
  • 我不是 js 开发人员,但我正在用 python 写这个--> (github.com/rtruxal/py-cog-serv),当我复制你的第一个查询时,我得到的 totalEstimatedMatches 为 179000 而不是 737你的代码产生。不幸的是,这就是我所得到的。无法很好地阅读 JS,所以我无法识别问题。

标签: bing microsoft-cognitive web-search


【解决方案1】:
  1. Bing 没有 totalEstimatedMatches 的最大值。虽然重要的是要记住它是一个估计值,我们不知道估计值的具体含义。据我们所知,这可能意味着500 &lt; totalEstimatedMatches &lt; 2000。他们如何“估计”这个数字不在文档中。
  2. 我盯着你的第二个问题看了很久,才弄清楚不和谐在哪里。尝试将 &amp;responseFilter=Webpages 附加到您正在创建的所有 URL 的末尾。在将您的回复制成表格时,您似乎只计算了 webresults,但没有指定查询只返回 web 结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    • 2016-05-03
    • 1970-01-01
    相关资源
    最近更新 更多