Google CSE:显示结果计数

发布于 2024-09-10 17:43:13 字数 976 浏览 3 评论 0原文

我已经为我的网站实现了 Google 站点搜索/自定义搜索,一切正常,结果格式化且分页良好。但它永远不会像在 Google 上搜索时那样返回找到的结果数量 大约 1,660,000 个结果(0.16 秒)

我想知道是否有人找到了可以执行此操作的任何内容,但我找不到文档中的任何内容。

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

I've implemented Google site search / Custom search for my website and it is all working and results are formatted and paging fine. But it never returns a count of how many results it found like it does when you search on Google About 1,660,000 results (0.16 seconds)

I was wondering if anyone had found anything to do this i can't find anything in there documentation.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剪不断理还乱 2024-09-17 17:43:13

您将需要使用 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>

You will need to use the SearchCompleteCallback and buried deep within the obfuscated javascript library, you will find the estimatedResultCount property. Here's a quick example that pops up an alert with the count. You can tailor this to meet your needs by using jquery to insert some html with the count in any format you like.

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文