'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

' ); } }