You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
5.4 KiB
181 lines
5.4 KiB
<?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, |
|
); |
|
|
|
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('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' => 'PID:ir* AND (rels.hasModel:info\:fedora/islandora\:thesisCModel OR rels.hasModel:info\:fedora/islandora\:citationCModel)', |
|
'qf' => 'mods.title^3.0 mods.subTitle^2.5 mods.author^5.0 mods.department^2.0 mods.abstract^1.5 dc.title^2.5 mods.subject^1.5 dc.creator^5.0 dc.contributor^2.0 dc.description^2.0 mods.genre^1.0 mods.hostTitle^2.0 mods.issn^1.0 mods.date^2.0 pdf.text^2.0 dsm.PDF^2.0 collection_title^1.0', |
|
'rows' => $num_results, |
|
); |
|
$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>' |
|
); |
|
} |
|
} |
|
|
|
|