我已经为我的网站实施了Google网站搜索/自定义搜索,这一切都正常,结果格式化,分页正常。但它永远不会返回它在Google About 1,660,000 results (0.16 seconds)
我想知道是否有人发现了任何事情,我在文档中找不到任何内容。
<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'en'});
google.setOnLoadCallback(function() {
var customSearchControl = new google.search.CustomSearchControl('GOOGLEIDGOESHERE');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.setNoResultsString("No results found.")
customSearchControl.draw('cse');
}, true);
</script>
<link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" />
答案 0 :(得分:2)
您将需要使用SearchCompleteCallback并深入隐藏在混淆的JavaScript库中,您将找到estimatedResultCount属性。这是一个快速示例,用计数弹出警报。你可以通过使用jquery以你喜欢的任何格式插入一些带有计数的html来定制它以满足你的需求。
<div id="cse" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'en'});
google.setOnLoadCallback(function() {
var customSearchControl = new google.search.CustomSearchControl('GOOGLEIDGOESHERE');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
customSearchControl.setNoResultsString("No results found.")
customSearchControl.setSearchCompleteCallback(null,
function() { searchCompleteCallback(customSearchControl) });
customSearchControl.draw('cse');
}, true);
function searchCompleteCallback(customSearchControl) {
alert(customSearchControl.e[0].g.cursor.estimatedResultCount);
}
</script>