ppound
3 years ago
8 changed files with 115 additions and 160 deletions
@ -1,47 +1,43 @@ |
|||||||
Drupal.behaviors.roblib_search_solr_site_results = { |
Drupal.behaviors.roblib_search_solr_site_results = { |
||||||
attach: function (context, settings) { |
attach: function (context, settings) { |
||||||
url = settings.roblib_search_solr_site_results.search_url; |
if (context == document) { |
||||||
query = settings.roblib_search_solr_site_results.search_query; |
query = $current_path.replace('roblib_search/', ''); |
||||||
baseUrl = settings.roblib_search_solr_site_results.base_url; |
solrUrl = settings.solr_site_search_url + query; |
||||||
default_site_type = settings.roblib_search_solr_site_results.default_site_type + '/'; |
baseUrl = settings.solr_site_base_url + query; |
||||||
jQuery.getJSON(url, function (data) { |
jQuery.getJSON(baseUrl, function (data) { |
||||||
var items = []; |
var items = []; |
||||||
total_found = data.response.numFound; |
total_found = data.resultCount; |
||||||
var numberOfDocs = 0; |
|
||||||
try { |
if (total_found < 1) { |
||||||
numberOfDocs = data.response.docs.length; |
jQuery('#' + 'roblib-search-content-solr-site-results').empty().append('No Results'); |
||||||
} catch (err) { |
jQuery('.' + 'pane-roblib-search-solr-site-roblib-search-solr-site-results').hide(); |
||||||
// do nothing leave docLength at 0
|
} else { |
||||||
} |
jQuery('#' + 'roblib-search-content-solr-site-results').empty(); |
||||||
if (numberOfDocs < 1) { |
var counter = 0; |
||||||
jQuery('#' + 'roblib-search-content-solr-site-results').empty().append('No Results'); |
var divs = new Array(); |
||||||
jQuery('.' + 'pane-roblib-search-solr-site-roblib-search-solr-site-results').hide(); |
var content = new Array(); |
||||||
} else { |
jQuery.each(data.results, function (key, val) { |
||||||
jQuery('#' + 'roblib-search-content-solr-site-results').empty(); |
id = 'roblib_search_solr_results_' + counter; |
||||||
var counter = 0; |
content[counter] = val.teaser; |
||||||
var divs = new Array(); |
divs[counter++] = id; |
||||||
var content = new Array(); |
items.push('<div class ="roblib-search-row" id="' + id + '">\n\ |
||||||
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\ |
|
||||||
<span class="roblib-title results">\n\ |
<span class="roblib-title results">\n\ |
||||||
<a href="' + val.url + '">' + val.label + '</a></span>' + |
<a href="' + val.url + '">' + val.title + '</a></span>' + |
||||||
'\n\<span class="roblib-solr-bundle">(' + val.bundle_name + ')</span> <span class="roblib-solr-teaser"> ' + val.teaser + '</span></div>'); |
'\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('')); |
jQuery('#' + 'roblib-search-content-solr-site-results').empty().append(items.join('')); |
||||||
} |
} |
||||||
if (numberOfDocs > 0) { |
if (total_found > 0) { |
||||||
results_url = '<a href="' + baseUrl + '/search/' + default_site_type + query + '?f[0]=(-bundle:bestbet)"' + '>see all results (' |
results_url = '<a href="' + solrUrl + '">see all results (' |
||||||
+ total_found + ') </a>'; |
+ total_found + ') </a>'; |
||||||
move_me_div_url = '<a href="' + baseUrl + '/search/' + default_site_type + query + '?f[0]=(-bundle:bestbet)"' + '>Library Site (' |
move_me_div_url = '<a href="' + solrUrl + '">Library Site (' |
||||||
+ total_found + ') </a>'; |
+ total_found + ') </a>'; |
||||||
jQuery('#' + 'roblib-search-solr-site-results-more').empty().append(results_url); |
jQuery('#' + 'roblib-search-solr-site-results-more').empty().append(results_url); |
||||||
jQuery('#' + 'roblib-solr-more-results-results').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); |
jQuery('#' + 'roblib-solr-search-toc-results').empty().append(move_me_div_url); |
||||||
} |
} |
||||||
}); |
}); |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
} |
} |
||||||
|
@ -1,24 +1,8 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
<div class ="roblib-search-more" id="roblib-search-solr-site-{{ solr_type }}-more"></div> |
||||||
* @file roblib-search-solr-site-results.tpl.php |
<div class ="roblib-search-content solr-site-{{ solr_type }}" id="roblib-search-content-solr-site-{{ solr_type }}"> |
||||||
* |
<img src="{{ spinner_path }}"/> |
||||||
* |
|
||||||
* 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> |
</div> |
||||||
|
|
||||||
<div id="roblib-solr-more-results-<?php print($type)?>" class="roblib-solr-more-button "></div> |
<div id="roblib-solr-more-results-{{ solr_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-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