ppound
3 years ago
8 changed files with 115 additions and 160 deletions
@ -1,47 +1,43 @@
|
||||
Drupal.behaviors.roblib_search_solr_site_results = { |
||||
attach: function (context, settings) { |
||||
url = settings.roblib_search_solr_site_results.search_url; |
||||
query = settings.roblib_search_solr_site_results.search_query; |
||||
baseUrl = settings.roblib_search_solr_site_results.base_url; |
||||
default_site_type = settings.roblib_search_solr_site_results.default_site_type + '/'; |
||||
jQuery.getJSON(url, function (data) { |
||||
var items = []; |
||||
total_found = data.response.numFound; |
||||
var numberOfDocs = 0; |
||||
try { |
||||
numberOfDocs = data.response.docs.length; |
||||
} catch (err) { |
||||
// do nothing leave docLength at 0
|
||||
} |
||||
if (numberOfDocs < 1) { |
||||
jQuery('#' + 'roblib-search-content-solr-site-results').empty().append('No Results'); |
||||
jQuery('.' + 'pane-roblib-search-solr-site-roblib-search-solr-site-results').hide(); |
||||
} else { |
||||
jQuery('#' + 'roblib-search-content-solr-site-results').empty(); |
||||
var counter = 0; |
||||
var divs = new Array(); |
||||
var content = new Array(); |
||||
jQuery.each(data.response.docs, function (key, val) { |
||||
id = 'roblib_search_solr_results_' + counter; |
||||
content[counter] = val.teaser; |
||||
divs[counter++] = id; |
||||
items.push('<div class ="roblib-search-row" id="' + id + '">\n\ |
||||
attach: function (context, settings) { |
||||
if (context == document) { |
||||
query = $current_path.replace('roblib_search/', ''); |
||||
solrUrl = settings.solr_site_search_url + query; |
||||
baseUrl = settings.solr_site_base_url + query; |
||||
jQuery.getJSON(baseUrl, function (data) { |
||||
var items = []; |
||||
total_found = data.resultCount; |
||||
|
||||
if (total_found < 1) { |
||||
jQuery('#' + 'roblib-search-content-solr-site-results').empty().append('No Results'); |
||||
jQuery('.' + 'pane-roblib-search-solr-site-roblib-search-solr-site-results').hide(); |
||||
} else { |
||||
jQuery('#' + 'roblib-search-content-solr-site-results').empty(); |
||||
var counter = 0; |
||||
var divs = new Array(); |
||||
var content = new Array(); |
||||
jQuery.each(data.results, function (key, val) { |
||||
id = 'roblib_search_solr_results_' + counter; |
||||
content[counter] = val.teaser; |
||||
divs[counter++] = id; |
||||
items.push('<div class ="roblib-search-row" id="' + id + '">\n\ |
||||
<span class="roblib-title results">\n\ |
||||
<a href="' + val.url + '">' + val.label + '</a></span>' + |
||||
'\n\<span class="roblib-solr-bundle">(' + val.bundle_name + ')</span> <span class="roblib-solr-teaser"> ' + val.teaser + '</span></div>'); |
||||
}); |
||||
jQuery('#' + 'roblib-search-content-solr-site-results').empty().append(items.join('')); |
||||
} |
||||
if (numberOfDocs > 0) { |
||||
results_url = '<a href="' + baseUrl + '/search/' + default_site_type + query + '?f[0]=(-bundle:bestbet)"' + '>see all results (' |
||||
+ total_found + ') </a>'; |
||||
move_me_div_url = '<a href="' + baseUrl + '/search/' + default_site_type + query + '?f[0]=(-bundle:bestbet)"' + '>Library Site (' |
||||
+ total_found + ') </a>'; |
||||
jQuery('#' + 'roblib-search-solr-site-results-more').empty().append(results_url); |
||||
jQuery('#' + 'roblib-solr-more-results-results').empty().append(results_url); |
||||
jQuery('#' + 'roblib-solr-search-toc-results').empty().append(move_me_div_url); |
||||
} |
||||
}); |
||||
} |
||||
<a href="' + val.url + '">' + val.title + '</a></span>' + |
||||
'\n\<span class="roblib-solr-bundle">(' + val.type + ')</span> <span class="roblib-solr-teaser"> ' + val.body + '</span></div>'); |
||||
}); |
||||
jQuery('#' + 'roblib-search-content-solr-site-results').empty().append(items.join('')); |
||||
} |
||||
if (total_found > 0) { |
||||
results_url = '<a href="' + solrUrl + '">see all results (' |
||||
+ total_found + ') </a>'; |
||||
move_me_div_url = '<a href="' + solrUrl + '">Library Site (' |
||||
+ total_found + ') </a>'; |
||||
jQuery('#' + 'roblib-search-solr-site-results-more').empty().append(results_url); |
||||
jQuery('#' + 'roblib-solr-more-results-results').empty().append(results_url); |
||||
jQuery('#' + 'roblib-solr-search-toc-results').empty().append(move_me_div_url); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
@ -1,24 +1,8 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @file roblib-search-solr-site-results.tpl.php |
||||
* |
||||
* |
||||
* Variables available: |
||||
* - $variables: all array elements of $variables can be used as a variable. e.g. $base_url equals $variables['base_url'] |
||||
* |
||||
*/ |
||||
?> |
||||
<? |
||||
// Get rid of warnings in admin interface |
||||
if (!isset($type)){ |
||||
$type = 'results'; |
||||
} |
||||
?> |
||||
<div class ="roblib-search-more" id="roblib-search-solr-site-<?php echo $type;?>-more"></div> |
||||
<div class ="roblib-search-content solr-site-<?php echo $type;?>" id="roblib-search-content-solr-site-<?php echo $type;?>"> |
||||
<img src="<?php print (empty($spinner_path) ? ' ' : $spinner_path); ?>"/> |
||||
<div class ="roblib-search-more" id="roblib-search-solr-site-{{ solr_type }}-more"></div> |
||||
<div class ="roblib-search-content solr-site-{{ solr_type }}" id="roblib-search-content-solr-site-{{ solr_type }}"> |
||||
<img src="{{ spinner_path }}"/> |
||||
</div> |
||||
|
||||
<div id="roblib-solr-more-results-<?php print($type)?>" class="roblib-solr-more-button "></div> |
||||
<div id="roblib-solr-search-toc-<?php print($type)?>" class="roblib-bento-toc moveme-please"></div> |
||||
<div id="roblib-solr-more-results-{{ solr_type }}" class="roblib-solr-more-button "></div> |
||||
<div id="roblib-solr-search-toc-{{ solr_type }}" class="roblib-bento-toc moveme-please"></div> |
||||
|
@ -1,43 +0,0 @@
|
||||
<?php |
||||
|
||||
/* |
||||
* |
||||
*/ |
||||
|
||||
/** |
||||
* @param array $variables |
||||
* @param string $type |
||||
* |
||||
* @return string |
||||
*/ |
||||
function roblib_search_solr_site_preprocess_roblib_search_solr_site(&$variables){ |
||||
//function roblib_search_solr_site_preprocessor(&$variables, $type) { |
||||
global $base_url; |
||||
$type = $variables['type']; |
||||
if (!isset($query)) { |
||||
if (isset($_GET['roblib_query'])) { |
||||
$query = $_GET['roblib_query']; |
||||
} |
||||
else { |
||||
return ''; |
||||
} |
||||
} |
||||
$spinner_path = $base_url . '/' . drupal_get_path('module', 'roblib_search') . '/img/' . 'spinner.gif'; |
||||
$variables['spinner_path'] = $spinner_path; |
||||
$variables['type'] = $type; |
||||
$query = urlencode($query); |
||||
$search_url = $base_url . '/roblib_search/solr_site/' . $type . '/' . $query; |
||||
drupal_add_js(drupal_get_path('module', 'roblib_search_solr_site') . '/js/solr_site_' . $type . '.js'); |
||||
$key = 'roblib_search_solr_site_' . $type; |
||||
$default_module = variable_get('search_default_module', 'site') == 'apachesolr_search' |
||||
? 'site' : variable_get('search_default_module', 'site'); |
||||
|
||||
drupal_add_js(array( |
||||
$key => array( |
||||
'search_url' => $search_url, |
||||
'search_query' => $query, |
||||
'base_url' => $base_url, |
||||
'default_site_type' => $default_module |
||||
) |
||||
), array('type' => 'setting')); |
||||
} |
Loading…
Reference in new issue