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.
197 lines
6.2 KiB
197 lines
6.2 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, |
|
); |
|
$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>' |
|
); |
|
} |
|
} |
|
|
|
|