Browse Source

see more No. result if have more results

2.x-ebsco
yqjiang 12 years ago
parent
commit
542e0b782e
  1. 40
      targets/solr_site/js/solr_site_results.js
  2. 6
      targets/solr_site/roblib_search_solr_site.module

40
targets/solr_site/js/solr_site_results.js

@ -1,22 +1,46 @@
Drupal.behaviors.roblib_search_solr_site= { Drupal.behaviors.roblib_search_solr_site = {
attach: function(context, settings) { attach: function(context, settings) {
url = settings.roblib_search_solr_site.search_url; url = settings.roblib_search_solr_site.search_url;
jQuery.getJSON(url, function(data) { jQuery.getJSON(url, function(data) {
var items = []; var items = [];
if(data.length < 1){ if (data.length < 1) {
jQuery('#' + 'roblib-search-content-solr-site').empty().append('No Results'); jQuery('#' + 'roblib-search-content-solr-site').empty().append('No Results');
} else { } else {
jQuery.each(data.response.docs, function(key, val) { jQuery.each(data.response.docs, function(key, val) {
items.push('<div class ="roblib-search-row">'); items.push('<div class ="roblib-search-row">\n\
items.push('<div class="roblib-title solr-site">'); <div class="roblib-title solr-site">\n\
items.push('<a href="'+val.url+'">' + val.label + '</a>'); <a href="' + val.url + '">' + val.label + '</a></div></div>');
items.push('</div>')
items.push('</div>');
}); });
var number = parseInt(data.rows);
jQuery('#' + 'roblib-search-content-solr-site').empty();
items = showMoreItems(items, number);
} }
jQuery('#roblib-search-content-solr-site').empty().append(items.join(''));
}); });
} }
} }
function showMoreItems(items, number) {
for (var i = 0; i < number; i++) {
jQuery('#' + 'roblib-search-content-solr-site').append(items.pop());
}
if (items.length > 0)
{
jQuery('#roblib-search-solr-site-more').empty().append('<a id="see_more_result">see ' + items.length + ' more results</a>');
jQuery('#see_more_result').click(function() {
items = showMoreItems(items, number);
});
}
else
{
jQuery('#roblib-search-solr-site-more').empty().append('no more results');
}
return items;
}

6
targets/solr_site/roblib_search_solr_site.module

@ -162,12 +162,12 @@ function roblib_search_solr_site_get_results($query) {
$data = array( $data = array(
'wt' => 'json', 'wt' => 'json',
'q' => $query, 'q' => $query,
'rows' => $num_results,
); );
$url = url($solr_url.'/select', array('query' => $data)); $url = url($solr_url.'/select', array('query' => $data));
$results = drupal_http_request($url); $results = drupal_http_request($url);
$temp = substr($results->data, 1);
return $results->data; $out = '{"rows":"'.$num_results.'",'.$temp;
return $out;
} }
/** /**

Loading…
Cancel
Save