Pregunta

He implementado Google site search / búsqueda Personalizada para mi página web y de todos los que trabajan y los resultados son de formato y paginación bien.Pero nunca devuelve un recuento de cómo muchos de los resultados encontrados, como lo hace cuando usted busca en Google About 1,660,000 results (0.16 seconds)

Me preguntaba si alguien había encontrado nada que hacer esto no puedo encontrar nada en hay documentación.

<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" />
¿Fue útil?

Solución

Usted tendrá que utilizar el SearchCompleteCallback y enterrado profundamente dentro de la biblioteca de javascript ofuscado, usted encontrará la estimatedResultCount de la propiedad.Aquí está un ejemplo rápido que aparece una alerta con el conde.Usted puede personalizar este para satisfacer sus necesidades mediante el uso de jquery para insertar un html con el conde en el formato que desees.

<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>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top