diff --git a/targets/islandscholar/css/roblib_search_islandscholar.css b/targets/islandscholar/css/roblib_search_islandscholar.css new file mode 100644 index 0000000..370bcf5 --- /dev/null +++ b/targets/islandscholar/css/roblib_search_islandscholar.css @@ -0,0 +1,21 @@ +/* + Document : roblib_search_evergreen + Created on : Apr 11, 2013, 2:27:50 PM + Author : ppound + Description: + Purpose of the stylesheet follows. +*/ + + .islandscholar-citation{ + font-size: smaller; + } +.islandscholar-hostTitle{ + font-size: smaller; +} +.islandscholar-author, .islandscholar-genre, .islandscholar-volume{ + padding-left: 10px; font-size: smaller; +} + +.islandscholar-label { + padding-left: 10px; font-size: smaller; font-weight: bolder; +} \ No newline at end of file diff --git a/targets/islandscholar/js/islandscholar_results.js b/targets/islandscholar/js/islandscholar_results.js new file mode 100644 index 0000000..5cacdf6 --- /dev/null +++ b/targets/islandscholar/js/islandscholar_results.js @@ -0,0 +1,115 @@ +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-site-roblib-search-islandscholar-results').hide(); + } else { + jQuery.each(data.response.docs, function(key, val) { + items.push('
\n\ +
\n\ + ' + val.Title_sorted + '
'); + try { + items.push('
'); + jQuery.each(val.author, function(key2, val2){ + items.push('' + val2 + '; ') + }) + items.push('
') + } catch (e){ + + } + try { + items.push('
'); + jQuery.each(val.genre, function(key2, val2){ + items.push('' + val2 + ' ') + }) + try{ + jQuery.each(val["mods.hostTitle"], function(key2, val2){ + items.push('' + val2 + ' ') + }) + } catch (err){ + + } + try{ + jQuery.each(val["mods.volume"], function(key2, val2){ + items.push('Vol. ' + val2 + ' ') + }) + } catch (err){ + + } + try{ + jQuery.each(val["mods.issue"], function(key2, val2){ + items.push('Issue ' + val2 + ', ') + }) + } catch (err){ + + } + try{ + jQuery.each(val["mods.pageStart"], function(key2, val2){ + items.push('p' + val2 + '') + }) + } catch (err){ + + } + try{ + jQuery.each(val["mods.pageEnd"], function(key2, val2){ + items.push('-' + val2 + ',') + }) + } catch (err){ + + } + try{ + if(jQuery.inArray('OBJ',val.hasDatastreams) > 0){ + items.push('
full text
') ; + } + } catch (err){ + + } + items.push('
') + } catch (e){ + + } + items.push('
'); + }); + + var number = parseInt(data.rows); + jQuery('#roblib-search-content-islandscholar').empty().append(items.join('')); + + items = showMoreItems(items, number); + } + }); + } + +} + +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('see ' + items.length + ' more results'); + jQuery('#see_more_result').click(function() { + items = showMoreItems(items, number); + }); + } + else + { + jQuery('#roblib-search-solr-site-more').empty().append('no more results'); + } + + + + return items; +} \ No newline at end of file diff --git a/targets/islandscholar/roblib_search_islandscholar.info b/targets/islandscholar/roblib_search_islandscholar.info new file mode 100644 index 0000000..ce23845 --- /dev/null +++ b/targets/islandscholar/roblib_search_islandscholar.info @@ -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 \ No newline at end of file diff --git a/targets/islandscholar/roblib_search_islandscholar.install b/targets/islandscholar/roblib_search_islandscholar.install new file mode 100644 index 0000000..a4abe2d --- /dev/null +++ b/targets/islandscholar/roblib_search_islandscholar.install @@ -0,0 +1,2 @@ + '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, + ); + + 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_search_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_block_view($delta = '') { + //The $delta parameter tells us which block is being requested. + switch ($delta) { + case 'roblib_search_islandscholar_results': + $block['subject'] = t('IslandScholar'); + $block['content'] = theme('roblib_search_islandscholar', array('results' => NULL)); + break; + } + return $block; +} + +function roblib_search_islandscholar_ajax($query) { + $output = roblib_search_islandscholar_get_results($query); + print $output; + exit(); +} + +/** + * + * @param string $query + * @return string + * json + */ +function roblib_search_islandscholar_get_results($query) { + $solr_url = variable_get('roblib_search_islandscholar_url', 'http://localhost:8983/solr'); + //$query = $solr_url . '/select?wt=json&q=test page'; + $num_results = variable_get('roblib_search_islandscholar_num_results', '5'); + $data = array( + 'wt' => 'json', + 'q' => $query, + 'fq' => 'PID:ir*', + ); + $url = url($solr_url . '/select', array('query' => $data)); + $results = drupal_http_request($url); + if($results->code != '200'){ + return ""; + } + $temp = substr($results->data, 1); + //$out = '{"rows":"' . $num_results . '",' . $results->data; + return $results->data; +} + +/** + * Implements hook_help(). + */ +function roblib_search_islandscholar_help($path, $arg) { + switch ($path) { + case 'admin/help#roblib_search_islandscholar': + return t( + '

+provides an Islandscholar target for the Roblib search module +

' + ); + } +} + diff --git a/targets/islandscholar/theme/roblib-search-islandscholar.tpl.php b/targets/islandscholar/theme/roblib-search-islandscholar.tpl.php new file mode 100644 index 0000000..a00f761 --- /dev/null +++ b/targets/islandscholar/theme/roblib-search-islandscholar.tpl.php @@ -0,0 +1,24 @@ + + +
+ + +
+
Search all Results
\ No newline at end of file diff --git a/targets/islandscholar/theme/theme.inc b/targets/islandscholar/theme/theme.inc new file mode 100644 index 0000000..18ed5d0 --- /dev/null +++ b/targets/islandscholar/theme/theme.inc @@ -0,0 +1,24 @@ + array('search_url' => $search_url)), array('type' => 'setting')); +} +?>