2010-07-19 118 views
1

我已经实施了Google网站搜索/自定义搜索我的网站,并且它的所有工作和结果都格式化并且分页正常。但它永远不会返回它找到多少结果的计数,就像它在Google上搜索时一样。About 1,660,000 results (0.16 seconds)Google CSE:显示结果数

我想知道是否有人发现了任何可以做到的事情,我找不到任何有关文档的内容。

<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" /> 

回答

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> 
+0

哇,谢谢他们很好的隐藏了。你读过哪些文档来找出这个问题? – ozatomic 2010-07-21 23:32:37

+0

现在这似乎不起作用,我想知道他们是否再次隐藏它。 – 2011-04-01 02:22:48