Paul Pound
7 years ago
13 changed files with 381 additions and 4 deletions
@ -0,0 +1,27 @@ |
|||||||
|
/* |
||||||
|
Document : roblib_search_evergreen |
||||||
|
Created on : Apr 11, 2013, 2:27:50 PM |
||||||
|
Author : ppound |
||||||
|
Description: |
||||||
|
Purpose of the stylesheet follows. |
||||||
|
*/ |
||||||
|
|
||||||
|
.islandscholar-citation, .islandscholar-author{ |
||||||
|
font-size: smaller; |
||||||
|
} |
||||||
|
.islandscholar-hostTitle{ |
||||||
|
font-size: smaller; |
||||||
|
font-style: italic; |
||||||
|
} |
||||||
|
.islandscholar-genre, .islandscholar-volume{ |
||||||
|
padding-left: 10px; font-size: smaller; |
||||||
|
} |
||||||
|
|
||||||
|
.islandscholar-authors, .islandscholar-source { |
||||||
|
padding-left: 10px; |
||||||
|
} |
||||||
|
|
||||||
|
.islandscholar-label { |
||||||
|
font-size: smaller; font-weight: bolder; |
||||||
|
} |
||||||
|
|
@ -0,0 +1,99 @@ |
|||||||
|
Drupal.behaviors.roblib_search_islandscholar = { |
||||||
|
attach: function (context, settings) { |
||||||
|
url = settings.roblib_search_islandscholar.search_url; |
||||||
|
jQuery.getJSON(url, function (data) { |
||||||
|
var items = []; |
||||||
|
var numberOfDocs = 0; |
||||||
|
try { |
||||||
|
numberOfDocs = data.response.docs.length; |
||||||
|
} catch (err) { |
||||||
|
// do nothing leave docLength at 0
|
||||||
|
} |
||||||
|
if (numberOfDocs < 1) { |
||||||
|
jQuery('#' + 'roblib-search-content-islandscholar').empty().append('No Results'); |
||||||
|
jQuery('.' + 'pane-roblib-search-islandscholar-roblib-islandscholar-results').hide(); |
||||||
|
} else { |
||||||
|
var counter = 0; |
||||||
|
var divs = new Array(); |
||||||
|
var content = new Array(); |
||||||
|
jQuery.each(data.response.docs, function (key, val) { |
||||||
|
id = 'roblib-search-islandscholar-' + counter; |
||||||
|
content[counter] = ''; |
||||||
|
if (typeof val['mods_abstract_s'] !== 'undefined') { |
||||||
|
content[counter] = val['mods_abstract_s'][0]; |
||||||
|
} else { |
||||||
|
content[counter] = 'No abstract available'; |
||||||
|
} |
||||||
|
divs[counter++] = id; |
||||||
|
items.push('<div class ="roblib-search-row" id="' + id + '">\n\ |
||||||
|
<div class="roblib-title islandscholar">\n\ |
||||||
|
<a href="http://www.islandscholar.ca/fedora/repository/' + val.PID + '">' + val['dc.title'] + '</a></div>'); |
||||||
|
try { |
||||||
|
items.push('<div class="islandscholar-authors">'); |
||||||
|
jQuery.each(val["mods_author_lastname_first_ms"], function (key2, val2) { |
||||||
|
items.push('<span class="islandscholar-author">' + val2 + ';</span> ') |
||||||
|
}) |
||||||
|
items.push('</div>') |
||||||
|
} catch (e) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
items.push('<div class="islandscholar-source">'); |
||||||
|
|
||||||
|
|
||||||
|
if (typeof val.mods_relatedItem_host_titleInfo_title_s !== 'undefined') { |
||||||
|
items.push('<span class="islandscholar-hostTitle">' + val.mods_relatedItem_host_titleInfo_title_s + '</span> ') |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if (typeof val.mods_canonical_date_issued_s !== 'undefined') { |
||||||
|
items.push('<span class="islandscholar-citation">' + val.mods_canonical_date_issued_s + '</span> ') |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if (typeof val.mods_part_detail_volume_number_s !== 'undefined') { |
||||||
|
items.push('<span class="islandscholar-citation">Vol. </span><span class="islandscholar-citation">' + val.mods_part_detail_volume_number_s + '</span> ') |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if (typeof val.mods_part_detail_issue_number_s !== 'undefined') { |
||||||
|
items.push('<span class="islandscholar-citation">Issue </span><span class="islandscholar-citation">' + val.mods_part_detail_issue_number_s + ',</span> ') |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if (typeof val.mods_part_extent_start_s !== 'undefined') { |
||||||
|
items.push('<span class="islandscholar-citation">p</span><span class="islandscholar-citation">' + val.mods_part_extent_start_s + '</span>') |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if (typeof val.mods_part_extent_end_s !== 'undefined') { |
||||||
|
items.push('<span class="islandscholar-citation">-</span><span class="islandscholar-citation">' + val.mods_part_extent_end_s + ',</span>') |
||||||
|
} |
||||||
|
|
||||||
|
if (typeof val.mods_genre_s !== 'undefined') { |
||||||
|
items.push('<div class="islandscholar-label">' + val.mods_genre_s + '</div> '); |
||||||
|
} |
||||||
|
|
||||||
|
if (jQuery.inArray('PDF', val.fedora_datastreams_ms) > 0) { |
||||||
|
items.push('<div>full text</div>'); |
||||||
|
} |
||||||
|
|
||||||
|
items.push('</div>'); |
||||||
|
|
||||||
|
items.push('</div>'); |
||||||
|
}); |
||||||
|
|
||||||
|
|
||||||
|
jQuery('#roblib-search-content-islandscholar').empty().append(items.join('')); |
||||||
|
qtipify(divs, content, 'Abstract'); |
||||||
|
var number = data.response.numFound; |
||||||
|
var query = encodeURIComponent(data.responseHeader.params.q);//.'milk';
|
||||||
|
jQuery('#roblib-search-islandscholar-more').empty().append('<a id="islandscholar-see-more-result"' + |
||||||
|
' href="http://www.islandscholar.ca/islandora/search/' + query + '?type=dismax">see all results</a>'); |
||||||
|
|
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,8 @@ |
|||||||
|
name = Roblib Search IslandScholar |
||||||
|
dependencies[] = roblib_search |
||||||
|
configure = admin/roblib_search/islandscholar_search |
||||||
|
description = implements the Roblib Search IslandScholar results |
||||||
|
package = Roblib Search |
||||||
|
version = 7.x-dev |
||||||
|
core = 7.x |
||||||
|
stylesheets[all][] = css/roblib_search_islandscholar.css |
@ -0,0 +1,2 @@ |
|||||||
|
<?php |
||||||
|
|
@ -0,0 +1,197 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file |
||||||
|
* Implementation of Roblib search for searching several targets. |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* Implements hook_menu(). |
||||||
|
*/ |
||||||
|
function roblib_search_islandscholar_menu() { |
||||||
|
$items = array(); |
||||||
|
|
||||||
|
$items['admin/roblib_search/islandscholar_search'] = array( |
||||||
|
'title' => 'Roblib Islandscholar Search Target configuration', |
||||||
|
'description' => 'Configuration for the Roblib Islandscholar site search target', |
||||||
|
'page callback' => 'drupal_get_form', |
||||||
|
'page arguments' => array('roblib_search_islandscholar_config_form'), |
||||||
|
'access arguments' => array('access administration pages'), |
||||||
|
'type' => MENU_NORMAL_ITEM, |
||||||
|
); |
||||||
|
|
||||||
|
$items['roblib_search/islandscholar/ajax/%'] = array( |
||||||
|
'title' => 'islandscholar ajax', |
||||||
|
'page callback' => 'roblib_search_islandscholar_ajax', |
||||||
|
'page arguments' => array(3), |
||||||
|
'type' => MENU_CALLBACK, |
||||||
|
'access arguments' => array('search roblib islandscholar'), |
||||||
|
); |
||||||
|
|
||||||
|
return $items; |
||||||
|
} |
||||||
|
|
||||||
|
function roblib_search_islandscholar_config_form($form, &$form_state) { |
||||||
|
$form['roblib_search_islandscholar_url'] = array( |
||||||
|
'#type' => 'textfield', |
||||||
|
'#title' => t('Islandscholar Solr url'), |
||||||
|
'#default_value' => variable_get('roblib_search_islandscholar_url', 'http://www.islandscholar.ca:8080/solr/'), |
||||||
|
'#description' => t('The base Islandscholar Solr URL, for example http://www.islandscholar.ca:8080/solr/'), |
||||||
|
'#required' => TRUE, |
||||||
|
); |
||||||
|
$form['roblib_search_islandscholar_num_results'] = array( |
||||||
|
'#type' => 'textfield', |
||||||
|
'#title' => t('Number of results to return'), |
||||||
|
'#default_value' => variable_get('roblib_search_islandscholar_num_results', '5'), |
||||||
|
'#description' => t('The number of results to display in the Bento box'), |
||||||
|
'#required' => TRUE, |
||||||
|
); |
||||||
|
$form['roblib_search_islandscholar_fq'] = array( |
||||||
|
'#type' => 'textarea', |
||||||
|
'#title' => t('Filter Query'), |
||||||
|
'#default_value' => variable_get('roblib_search_islandscholar_fq', 'PID:ir* AND (RELS_EXT_hasModel_uri_ms:info\:fedora/ir\:thesisCModel OR RELS_EXT_hasModel_uri_ms:info\:fedora/ir\:citationCModel)'), |
||||||
|
'#description' => t('A query used to restrict the results to namespace and content models'), |
||||||
|
'#required' => TRUE, |
||||||
|
); |
||||||
|
|
||||||
|
$form['roblib_search_islandscholar_qf'] = array( |
||||||
|
'#type' => 'textarea', |
||||||
|
'#title' => t('Query Field'), |
||||||
|
'#default_value' => variable_get('roblib_search_islandscholar_qf', 'dc.title^2.5 dc.creator^5.0 dc.contributor^2.0 dc.description^2.0 dc.identifier^2.0 dc.type^2.0 catch_all_fields_mt^1.0'), |
||||||
|
'#description' => t('The fields to query and a weight for each field.'), |
||||||
|
'#required' => TRUE, |
||||||
|
); |
||||||
|
|
||||||
|
return system_settings_form($form); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Implements hook_permission(). |
||||||
|
*/ |
||||||
|
function roblib_search_islandscholar_permission() { |
||||||
|
return array( |
||||||
|
'search roblib islandscholar' => array( |
||||||
|
'title' => t('Search the islandscholar target'), |
||||||
|
'description' => t('Search all Roblib islandscholar target. This permission exposes the search blocks and allows you to see search results.'), |
||||||
|
), |
||||||
|
'administer roblib search_islandscholar' => array( |
||||||
|
'title' => t('Administer Roblib Search Evergreen'), |
||||||
|
'description' => t('Administer settings for the Roblib islandscholar search client.'), |
||||||
|
), |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Implements hook_theme(). |
||||||
|
*/ |
||||||
|
function roblib_search_islandscholar_theme() { |
||||||
|
// set path |
||||||
|
$path = drupal_get_path('module', 'roblib_search_islandscholar'); |
||||||
|
$file = 'theme.inc'; |
||||||
|
|
||||||
|
return array( |
||||||
|
// results page |
||||||
|
'roblib_search_islandscholar' => array( |
||||||
|
'path' => $path . '/theme', |
||||||
|
'file' => $file, |
||||||
|
'template' => 'roblib-search-islandscholar', |
||||||
|
'variables' => array('results' => NULL), |
||||||
|
) |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
function roblib_search_islandscholar_block_info() { |
||||||
|
|
||||||
|
$blocks['roblib_islandscholar_results'] = array( |
||||||
|
// info: The name of the block. |
||||||
|
'info' => t('Roblib Islandscholar Solr Search Results block'), |
||||||
|
// Block caching options (per role, per user, etc.) |
||||||
|
'cache' => DRUPAL_CACHE_PER_ROLE, // default |
||||||
|
); |
||||||
|
|
||||||
|
return $blocks; |
||||||
|
} |
||||||
|
|
||||||
|
function roblib_search_islandscholar_preprocess_panels_pane(&$variables, $hook){ |
||||||
|
if($variables['pane']->subtype == 'roblib_search_islandscholar-roblib_islandscholar_results'){ |
||||||
|
$variables['title_prefix'] = '<div class="roblib-search-header roblib-search-islandscholar-header">'; |
||||||
|
$variables['title_suffix'] ='</div>'; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Implements hook_block_view(). |
||||||
|
*/ |
||||||
|
function roblib_search_islandscholar_block_view($delta = '') { |
||||||
|
//The $delta parameter tells us which block is being requested. |
||||||
|
switch ($delta) { |
||||||
|
case 'roblib_islandscholar_results': |
||||||
|
$block['subject'] = t('IslandScholar'); |
||||||
|
$block['content'] = theme('roblib_search_islandscholar', array('results' => NULL)); |
||||||
|
break; |
||||||
|
} |
||||||
|
return $block; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* An endpoint for the islandscholar ajax call |
||||||
|
* |
||||||
|
* @param string $query |
||||||
|
* |
||||||
|
*/ |
||||||
|
function roblib_search_islandscholar_ajax($query) { |
||||||
|
$output = roblib_search_islandscholar_get_results($query); |
||||||
|
print $output; |
||||||
|
exit(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param $query |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
function roblib_search_islandscholar_get_search_url($query){ |
||||||
|
$solr_url = variable_get('roblib_search_islandscholar_url', 'http://localhost:8983/solr'); |
||||||
|
$num_results = variable_get('roblib_search_islandscholar_num_results', '5'); |
||||||
|
$data = array( |
||||||
|
'wt' => 'json', |
||||||
|
'q' => $query , |
||||||
|
'fq' => variable_get('roblib_search_islandscholar_fq','PID:ir* AND (RELS_EXT_hasModel_uri_ms:info\:fedora/ir\:thesisCModel OR RELS_EXT_hasModel_uri_ms:info\:fedora/ir\:citationCModel)'), |
||||||
|
'qf' => variable_get('roblib_search_islandscholar_qf','dc.title^2.5 dc.creator^5.0 dc.contributor^2.0 dc.description^2.0 dc.identifier^2.0 dc.type^2.0 catch_all_fields_mt^1.0'), |
||||||
|
'rows' => $num_results, |
||||||
|
'defType' => 'dismax', |
||||||
|
); |
||||||
|
$url = url($solr_url . '/select', array('query' => $data)); |
||||||
|
return $url; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param string $query |
||||||
|
* |
||||||
|
* @return string |
||||||
|
* json |
||||||
|
*/ |
||||||
|
function roblib_search_islandscholar_get_results($query) { |
||||||
|
$url = roblib_search_islandscholar_get_search_url($query); |
||||||
|
$results = drupal_http_request($url); |
||||||
|
if($results->code != '200'){ |
||||||
|
return ""; |
||||||
|
} |
||||||
|
return $results->data; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Implements hook_help(). |
||||||
|
*/ |
||||||
|
function roblib_search_islandscholar_help($path, $arg) { |
||||||
|
switch ($path) { |
||||||
|
case 'admin/help#roblib_search_islandscholar': |
||||||
|
return t( |
||||||
|
'<p> |
||||||
|
provides an Islandscholar target for the Roblib search module |
||||||
|
</p>' |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
@ -0,0 +1,13 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* @file roblib-search-islandscholar.tpl.php |
||||||
|
|
||||||
|
*/ |
||||||
|
?> |
||||||
|
<div class ="roblib-search-more" id="roblib-search-islandscholar-more">Search all Results</div> |
||||||
|
<div class ="roblib-search-content solr-site" id="roblib-search-content-islandscholar"> |
||||||
|
<img src="<?php print (empty($spinner_path) ? ' ' : $spinner_path); ?>"/>
|
||||||
|
</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_islandscholar_preprocess_roblib_search_islandscholar(&$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/islandscholar/ajax/'.urlencode($query); |
||||||
|
drupal_add_js(drupal_get_path('module', 'roblib_search_islandscholar') . '/js/islandscholar_results.js'); |
||||||
|
drupal_add_js(array('roblib_search_islandscholar' => array('search_url' => $search_url)), array('type' => 'setting')); |
||||||
|
} |
||||||
|
?> |
Loading…
Reference in new issue