Paul Pound
12 years ago
9 changed files with 284 additions and 6 deletions
@ -0,0 +1,9 @@
|
||||
/* |
||||
Document : roblib_search_evergreen |
||||
Created on : Apr 11, 2013, 2:27:50 PM |
||||
Author : ppound |
||||
Description: |
||||
Purpose of the stylesheet follows. |
||||
*/ |
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
Drupal.behaviors.roblib_search_solr_site= { |
||||
attach: function(context, settings) {
|
||||
url = settings.roblib_search_solr_site.search_url; |
||||
jQuery.getJSON(url, function(data) { |
||||
var items = [];
|
||||
if(data.length < 1){ |
||||
jQuery('#' + 'roblib-search-content-solr-site').empty().append('No Results');
|
||||
} else { |
||||
jQuery.each(data.response.docs, function(key, val) {
|
||||
items.push('<div class ="roblib-search-row">'); |
||||
items.push('<div class="roblib-title solr-site">'); |
||||
items.push('<a href="'+val.url+'">' + val.label + '</a>'); |
||||
items.push('</div>') |
||||
items.push('</div>'); |
||||
});
|
||||
}
|
||||
jQuery('#roblib-search-content-solr-site').empty().append(items.join(''));
|
||||
}); |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,8 @@
|
||||
name = Roblib Search Solr site |
||||
dependencies[] = roblib_search |
||||
configure = admin/roblib_search/solr_site_search |
||||
description = implements the Roblib Search local Solr site bento results |
||||
package = Roblib Search |
||||
version = 7.x-dev |
||||
core = 7.x |
||||
stylesheets[all][] = css/roblib_search_solr_site.css |
@ -0,0 +1,190 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @file |
||||
* Implementation of Roblib search for searching several targets. |
||||
*/ |
||||
|
||||
/** |
||||
* Implements hook_boot(). |
||||
* @global type $conf |
||||
*/ |
||||
function roblib_search_solr_site_boot() { |
||||
/* below is an example from islandora_solr module for internationalization |
||||
* global $conf; |
||||
|
||||
// Allow i18n, by using multilingual variables. |
||||
if (module_exists('i18n')) { |
||||
$vars = array( |
||||
'islandora_solr_facets', |
||||
'islandora_solr_result_fields', |
||||
'islandora_solr_searchterms' |
||||
); |
||||
|
||||
if (isset($conf['i18n_variables']) && is_array($conf['i18n_variables'])) { |
||||
$conf['i18n_variables'] = array_merge($vars, $conf['i18n_variables']); |
||||
} |
||||
else { |
||||
$conf['i18n_variables'] = $vars; |
||||
} |
||||
} */ |
||||
} |
||||
|
||||
/** |
||||
* Implements hook_menu(). |
||||
*/ |
||||
function roblib_search_solr_site_menu() { |
||||
$items = array(); |
||||
|
||||
$items['admin/roblib_search/solr_site_search'] = array( |
||||
'title' => 'Roblib Solr Search Target configuration', |
||||
'description' => 'Configuration for the Roblib Solr site search target', |
||||
'page callback' => 'drupal_get_form', |
||||
'page arguments' => array('roblib_search_solr_site_config_form'), |
||||
'access arguments' => array('access administration pages'), |
||||
'type' => MENU_NORMAL_ITEM, |
||||
); |
||||
|
||||
$items['roblib_search/solr_site/ajax/%'] = array( |
||||
'title' => 'solr_site ajax', |
||||
'page callback' => 'roblib_search_solr_site_ajax', |
||||
'page arguments' => array(3), |
||||
'type' => MENU_CALLBACK, |
||||
'access arguments' => array('search roblib solr_site'), |
||||
); |
||||
|
||||
return $items; |
||||
} |
||||
|
||||
function roblib_search_solr_site_config_form($form, &$form_state) { |
||||
/* |
||||
* $url = variable_get('roblib_search_solr_site_url', 'http://137.149.200.52'); |
||||
$url_suffix = variable_get('roblib_search_solr_site_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query='); |
||||
$number_of_records = variable_get('roblib_search_solr_site_num_results', '5'); |
||||
*/ |
||||
$form['roblib_search_solr_site_url'] = array( |
||||
'#type' => 'textfield', |
||||
'#title' => t('Solr url'), |
||||
'#default_value' => variable_get('roblib_search_solr_site_url', 'http://localhost:8983/solr'), |
||||
'#description' => t('The base Solr URL, for example http://localhost:8983/solr'), |
||||
'#required' => TRUE, |
||||
); |
||||
$form['roblib_search_solr_site_num_results'] = array( |
||||
'#type' => 'textfield', |
||||
'#title' => t('Number of results to return'), |
||||
'#default_value' => variable_get('roblib_search_solr_site_num_results', '5'), |
||||
'#description' => t('The number of results to display in the Bento box'), |
||||
'#required' => TRUE, |
||||
); |
||||
|
||||
return system_settings_form($form); |
||||
} |
||||
|
||||
/** |
||||
* Implements hook_permission(). |
||||
*/ |
||||
function roblib_search_solr_site_permission() { |
||||
return array( |
||||
'search roblib solr_site' => array( |
||||
'title' => t('Search the solr_site target'), |
||||
'description' => t('Search all Roblib solr_site target. This permission exposes the search blocks and allows you to see search results.'), |
||||
), |
||||
'administer roblib search_solr_site' => array( |
||||
'title' => t('Administer Roblib Search Evergreen'), |
||||
'description' => t('Administer settings for the Roblib solr_site search client.'), |
||||
), |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* Implements hook_theme(). |
||||
*/ |
||||
function roblib_search_solr_site_theme() { |
||||
// set path |
||||
$path = drupal_get_path('module', 'roblib_search_solr_site'); |
||||
$file = 'theme.inc'; |
||||
|
||||
return array( |
||||
// results page |
||||
'roblib_search_solr_site' => array( |
||||
'path' => $path . '/theme', |
||||
'file' => $file, |
||||
'template' => 'roblib-search-solr_site', |
||||
'variables' => array('results' => NULL), |
||||
) |
||||
); |
||||
} |
||||
|
||||
function roblib_search_solr_site_block_info() { |
||||
|
||||
$blocks['roblib_search_solr_site_results'] = array( |
||||
// info: The name of the block. |
||||
'info' => t('Roblib Solr Search Results block'), |
||||
// Block caching options (per role, per user, etc.) |
||||
'cache' => DRUPAL_CACHE_PER_ROLE, // default |
||||
); |
||||
|
||||
return $blocks; |
||||
} |
||||
|
||||
function roblib_search_solr_site_block_view($delta = '') { |
||||
//The $delta parameter tells us which block is being requested. |
||||
switch ($delta) { |
||||
case 'roblib_search_solr_site_results': |
||||
// The subject is displayed at the top of the block. Note that it |
||||
// should be passed through t() for translation. The title configured |
||||
// for the block using Drupal UI supercedes this one. |
||||
$block['subject'] = t('Site Results'); |
||||
// The content of the block is typically generated by calling a custom |
||||
// function. |
||||
$block['content'] = theme('roblib_search_solr_site', array('results' => NULL)); |
||||
break; |
||||
} |
||||
return $block; |
||||
} |
||||
|
||||
function roblib_search_solr_site_ajax($query) { |
||||
$output = roblib_search_solr_site_get_results($query); |
||||
print $output; |
||||
exit(); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $query |
||||
* @return string |
||||
* json |
||||
*/ |
||||
function roblib_search_solr_site_get_results($query) { |
||||
$solr_url = variable_get('roblib_search_solr_site_url', 'http://localhost:8983/solr'); |
||||
//$query = $solr_url . '/select?wt=json&q=test page'; |
||||
$num_results = variable_get('roblib_search_solr_site_num_results', '5'); |
||||
$data = array( |
||||
'wt' => 'json', |
||||
'q' => $query, |
||||
'rows' => $num_results, |
||||
); |
||||
$url = url($solr_url.'/select', array('query' => $data)); |
||||
$results = drupal_http_request($url); |
||||
|
||||
return $results->data; |
||||
} |
||||
|
||||
/** |
||||
* Implements hook_help(). |
||||
* |
||||
* @param type $path |
||||
* @param type $arg |
||||
* @return type |
||||
*/ |
||||
function roblib_search_solr_site_help($path, $arg) { |
||||
switch ($path) { |
||||
case 'admin/help#roblib_search_solr_site': |
||||
return t( |
||||
'<p> |
||||
provides a target for the Roblib search module |
||||
</p>' |
||||
); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,24 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* @file islandora-solr-wrapper.tpl.php |
||||
* Islandora solr search results wrapper template |
||||
* |
||||
* Variables available: |
||||
* - $variables: all array elements of $variables can be used as a variable. e.g. $base_url equals $variables['base_url'] |
||||
* - $base_url: The base url of the current website. eg: http://example.com . |
||||
* - $user: The user object. |
||||
* |
||||
* |
||||
* - $results: Rendered search results (primary profile) |
||||
* |
||||
* |
||||
* @see template_preprocess_roblib_search_wrapper() |
||||
*/ |
||||
?> |
||||
|
||||
<div class ="roblib-search-content solr-site" id="roblib-search-content-solr-site"> |
||||
<img src="<?php print (empty($spinner_path) ? ' ' : $spinner_path); ?>"/>
|
||||
|
||||
</div> |
||||
<div class ="roblib-search-more" id="roblib-search-solr-site-more">Search all Results</div> |
@ -0,0 +1,24 @@
|
||||
<?php |
||||
|
||||
/* |
||||
* all we do here is pass a url to some javascript so results can be loaded |
||||
* indepentantly |
||||
*/ |
||||
|
||||
function roblib_search_solr_site_preprocess_roblib_search_solr_site(&$variables) { |
||||
global $base_url; |
||||
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; |
||||
$search_url = $base_url .'/roblib_search/solr_site/ajax/'.urlencode($query); |
||||
drupal_add_js(drupal_get_path('module', 'roblib_search_solr_site') . '/js/solr_site_results.js'); |
||||
drupal_add_js(array('roblib_search_solr_site' => array('search_url' => $search_url)), array('type' => 'setting')); |
||||
} |
||||
?> |
Loading…
Reference in new issue