Browse Source

added more solr targets

2.x-ebsco
Paul Pound 11 years ago
parent
commit
2299af7eb9
  1. 0
      targets/solr_site/css/roblib_search_solr_site.css
  2. 30
      targets/solr_site/js/solr_site_bestbet.js
  3. 31
      targets/solr_site/js/solr_site_databases.js
  4. 29
      targets/solr_site/js/solr_site_guides.js
  5. 27
      targets/solr_site/js/solr_site_results.js
  6. 0
      targets/solr_site/roblib_search_solr_site.info
  7. 0
      targets/solr_site/roblib_search_solr_site.install
  8. 156
      targets/solr_site/roblib_search_solr_site.module
  9. 4
      targets/solr_site/theme/roblib-search-solr-site-results.tpl.php
  10. 53
      targets/solr_site/theme/theme.inc

0
targets/solr_site/css/roblib_search_solr_site.css

30
targets/solr_site/js/solr_site_bestbet.js

@ -0,0 +1,30 @@
Drupal.behaviors.roblib_search_solr_site_bestbet = {
attach: function(context, settings) {
$url = settings.roblib_search_solr_site_bestbet.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-solr-site-bestbet').empty().append('No Results');
} else {
jQuery('#' + 'roblib-search-content-solr-site-bestbet').empty();
jQuery.each(data.response.docs, function(key, val) {
items.push('<div class ="roblib-search-row">\n\
<div class="roblib-title solr_site">\n\
<a href="' + val.url + '">' + val.label + '</a></div></div>');
});
jQuery('#' + 'roblib-search-content-solr-site-bestbet').empty().append(items.join(''));
}
});
}
}

31
targets/solr_site/js/solr_site_databases.js

@ -0,0 +1,31 @@
Drupal.behaviors.roblib_search_solr_site_databases = {
attach: function(context, settings) {
$url = settings.roblib_search_solr_site_databases.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-solr-site-databases').empty().append('No Results');
} else {
jQuery('#' + 'roblib-search-content-solr-site-databases').empty();
jQuery.each(data.response.docs, function(key, val) {
items.push('<div class="roblib-search-row">\n\
<div class="roblib-title databases">\n\
<a href="' + val.url + '">' + val.label + '</a></div></div>');
});
jQuery('#' + 'roblib-search-content-solr-site-databases').empty().append(items.join(''));
}
});
}
}

29
targets/solr_site/js/solr_site_guides.js

@ -0,0 +1,29 @@
Drupal.behaviors.roblib_search_solr_site_guides = {
attach: function(context, settings) {
$url = settings.roblib_search_solr_site_guides.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-solr-site-guides').empty().append('No Results');
} else {
jQuery('#' + 'roblib-search-content-solr-site-guides').empty();
jQuery.each(data.response.docs, function(key, val) {
items.push('<div class ="roblib-search-row">\n\
<div class="roblib-title guides">\n\
<a href="' + val.url + '">' + val.label + '</a></div></div>');
});
jQuery('#' + 'roblib-search-content-solr-site-guides').empty().append(items.join(''));
}
});
}
}

27
targets/solr_site/js/solr_site_results.js

@ -1,8 +1,7 @@
Drupal.behaviors.roblib_search_solr_site = {
Drupal.behaviors.roblib_search_solr_site_results = {
attach: function(context, settings) {
url = settings.roblib_search_solr_site.search_url;
query = settings.roblib_search_solr_site.search_query;
jQuery.getJSON(url, function(data) {
$url = settings.roblib_search_solr_site_results.search_url;
jQuery.getJSON($url, function(data) {
var items = [];
var numberOfDocs = 0;
try {
@ -11,27 +10,21 @@ Drupal.behaviors.roblib_search_solr_site = {
// do nothing leave docLength at 0
}
if (numberOfDocs < 1) {
jQuery('#' + 'roblib-search-content-solr-site').empty().append('No Results');
//<section class="panel-pane pane-block pane-roblib-search-solr-site-roblib-search-solr-site-results block">
jQuery('#' + 'roblib-search-content-solr-site-results').empty().append('No Results');
jQuery('.' + 'pane-roblib-search-solr-site-roblib-search-solr-site-results').hide();
} else {
jQuery('#' + 'roblib-search-content-solr-site-results').empty();
jQuery.each(data.response.docs, function(key, val) {
items.push('<div class ="roblib-search-row">\n\
<div class="roblib-title solr-site">\n\
<div class="roblib-title results">\n\
<a href="' + val.url + '">' + val.label + '</a></div></div>');
//items.push('<div class ="roblib-solr-site-teaser">' + val.teaser + '</div>')
});
jQuery('#roblib-search-content-solr-site').empty().append(items.join(''));
var number = data.response.numFound;
var scholarUrl = "http://www.islandscholar.ca/islandora/solr/search/"
jQuery('#' + 'roblib-search-solr-site-more').empty().append('<a id="solr-site-see-more-result"' +
'href="/search/site/' + query + '">see all ' + number + ' results</a>');
});
jQuery('#' + 'roblib-search-content-solr-site-results').empty().append(items.join(''));
}
});
}
}

0
targets/solr_site/roblib_search_solr_site.info

0
targets/solr_site/roblib_search_solr_site.install

156
targets/solr_site/roblib_search_solr_site.module

@ -21,23 +21,43 @@ function roblib_search_solr_site_menu() {
'type' => MENU_NORMAL_ITEM,
);
$items['roblib_search/solr_site/ajax/%'] = array(
'title' => 'solr_site ajax',
'page callback' => 'roblib_search_solr_site_ajax',
$items['roblib_search/solr_site/bestbet/%'] = array(
'title' => 'BestBet',
'page callback' => 'roblib_search_solr_site_bestbet',
'page arguments' => array(3),
'type' => MENU_CALLBACK,
'access arguments' => array('search roblib solr_site'),
);
$items['roblib_search/solr_site/databases/%'] = array(
'title' => 'solr_site databases',
'page callback' => 'roblib_search_solr_site_databases',
'page arguments' => array(3),
'type' => MENU_CALLBACK,
'access arguments' => array('search roblib solr_site'),
);
$items['roblib_search/solr_site/guides/%'] = array(
'title' => 'solr_site guides',
'page callback' => 'roblib_search_solr_site_guides',
'page arguments' => array(3),
'type' => MENU_CALLBACK,
'access arguments' => array('search roblib solr_site'),
);
$items['roblib_search/solr_site/results/%'] = array(
'title' => 'solr_site guides',
'page callback' => 'roblib_search_solr_site_results',
'page arguments' => array(3),
'type' => MENU_CALLBACK,
'access arguments' => array('search roblib solr_site'),
);
return $items;
}
function roblib_search_solr_site_config_form($form, &$form_state) {
/*
* $url = variable_get('roblib_search_solr_site_url', 'http://137.149.200.52');
$url_suffix = variable_get('roblib_search_solr_site_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query=');
$number_of_records = variable_get('roblib_search_solr_site_num_results', '5');
*/
$form['roblib_search_solr_site_url'] = array(
'#type' => 'textfield',
'#title' => t('Solr url'),
@ -82,20 +102,59 @@ function roblib_search_solr_site_theme() {
return array(
// results page
'roblib_search_solr_site' => array(
'roblib_search_solr_site_bestbet' => array(
'path' => $path . '/theme',
'file' => $file,
'template' => 'roblib-search-solr-site-results',
'variables' => array('results' => NULL),
),
'roblib_search_solr_site_databases' => array(
'path' => $path . '/theme',
'file' => $file,
'template' => 'roblib-search-solr-site-results',
'variables' => array('results' => NULL),
),
'roblib_search_solr_site_guides' => array(
'path' => $path . '/theme',
'file' => $file,
'template' => 'roblib-search-solr-site-results',
'variables' => array('results' => NULL),
),
'roblib_search_solr_site_results' => array(
'path' => $path . '/theme',
'file' => $file,
'template' => 'roblib-search-solr-site',
'template' => 'roblib-search-solr-site-results',
'variables' => array('results' => NULL),
)
),
);
}
function roblib_search_solr_site_block_info() {
$blocks['roblib_search_solr_site_bestbet'] = array(
// info: The name of the block.
'info' => t('Roblib Solr Search Best bets'),
// Block caching options (per role, per user, etc.)
'cache' => DRUPAL_CACHE_PER_ROLE, // default
);
$blocks['roblib_search_solr_site_db'] = array(
// info: The name of the block.
'info' => t('Roblib Solr Search Databases Block'),
// Block caching options (per role, per user, etc.)
'cache' => DRUPAL_CACHE_PER_ROLE, // default
);
$blocks['roblib_search_solr_site_guides'] = array(
// info: The name of the block.
'info' => t('Roblib Solr Search Guides Block'),
// Block caching options (per role, per user, etc.)
'cache' => DRUPAL_CACHE_PER_ROLE, // default
);
$blocks['roblib_search_solr_site_results'] = array(
// info: The name of the block.
'info' => t('Roblib Solr Search Results block'),
'info' => t('Roblib Solr Search Results Block'),
// Block caching options (per role, per user, etc.)
'cache' => DRUPAL_CACHE_PER_ROLE, // default
);
@ -104,24 +163,47 @@ function roblib_search_solr_site_block_info() {
}
function roblib_search_solr_site_block_view($delta = '') {
//The $delta parameter tells us which block is being requested.
switch ($delta) {
case 'roblib_search_solr_site_bestbet':
$block['subject'] = t('Best Bets');
$block['content'] = theme('roblib_search_solr_site_bestbet', array('results' => NULL));
break;
case 'roblib_search_solr_site_db':
$block['subject'] = t('Databases');
$block['content'] = theme('roblib_search_solr_site_databases', array('results' => NULL));
break;
case 'roblib_search_solr_site_guides':
$block['subject'] = t('Guides');
$block['content'] = theme('roblib_search_solr_site_guides', array('results' => NULL));
break;
case 'roblib_search_solr_site_results':
// The subject is displayed at the top of the block. Note that it
// should be passed through t() for translation. The title configured
// for the block using Drupal UI supercedes this one.
$block['subject'] = t('Library Website');
// The content of the block is typically generated by calling a custom
// function.
$block['content'] = theme('roblib_search_solr_site', array('results' => NULL));
$block['subject'] = t('Library Site');
$block['content'] = theme('roblib_search_solr_site_results', array('results' => NULL));
break;
}
return $block;
}
function roblib_search_solr_site_ajax($query) {
$output = roblib_search_solr_site_get_results($query);
print $output;
function roblib_search_solr_site_results($query) {
print roblib_search_solr_site_get_results($query, '-bundle:bestbet OR -budle:guide OR -bundle:database');
exit();
}
function roblib_search_solr_site_bestbet($query) {
print roblib_search_solr_site_get_results($query, 'bundle:bestbet');
exit();
}
function roblib_search_solr_site_databases($query) {
print roblib_search_solr_site_get_results($query, 'bundle:database');
exit();
}
function roblib_search_solr_site_guides($query) {
print roblib_search_solr_site_get_results($query, 'bundle:guide');
exit();
}
@ -131,32 +213,25 @@ function roblib_search_solr_site_ajax($query) {
* @return string
* json
*/
function roblib_search_solr_site_get_results($query) {
$url = roblib_search_solr_site_get_search_url($query);
$results = drupal_http_request($url);
if($results->code != '200'){
return "";
}
return $results->data;
}
/**
* @param $query
* @return string
*/
function roblib_search_solr_site_get_search_url($query){
function roblib_search_solr_site_get_results($query = NULL, $type ) {
$solr_url = variable_get('roblib_search_solr_site_url', 'http://localhost:8983/solr');
$num_results = variable_get('roblib_search_solr_site_num_results', '5');
$data = array(
'q' => $query,
'fq' => $type,
'wt' => 'json',
'q' => $query ,
'fq' => '-bundle:guide OR -bundle:bestbet OR -bundle:database',
'rows' => $num_results,
);
$url = url($solr_url . '/select', array('query' => $data));
return $url;
$results = drupal_http_request($url);
if ($results->code != '200') {
return "";
}
return $results->data;
}
/**
* Implements hook_help().
*/
@ -170,4 +245,3 @@ provides a target for the Roblib search module
);
}
}

4
targets/solr_site/theme/roblib-search-solr-site.tpl.php → targets/solr_site/theme/roblib-search-solr-site-results.tpl.php

@ -16,7 +16,7 @@
* @see template_preprocess_roblib_search_wrapper()
*/
?>
<div class ="roblib-search-more" id="roblib-search-solr-site-more">Search all Results</div>
<div class ="roblib-search-content solr-site" id="roblib-search-content-solr-site">
<div class ="roblib-search-more" id="roblib-search-solr-site-<?php echo $type;?>-more"></div>
<div class ="roblib-search-content solr-site-<?php echo $type;?>" id="roblib-search-content-solr-site-<?php echo $type;?>">
<img src="<?php print (empty($spinner_path) ? ' ' : $spinner_path); ?>"/>
</div>

53
targets/solr_site/theme/theme.inc

@ -1,11 +1,45 @@
<?php
/*
* all we do here is pass a url to some javascript so results can be loaded
* indepentantly
*
*/
function roblib_search_solr_site_preprocess_roblib_search_solr_site(&$variables) {
/**
* @param $variables
*/
function roblib_search_solr_site_preprocess_roblib_search_solr_site_bestbet(&$variables) {
roblib_search_solr_site_preprocessor($variables, 'bestbet');
}
/**
* @param $variables
*/
function roblib_search_solr_site_preprocess_roblib_search_solr_site_results(&$variables) {
roblib_search_solr_site_preprocessor($variables, 'results');
}
/**
* @param $variables
*/
function roblib_search_solr_site_preprocess_roblib_search_solr_site_databases(&$variables) {
roblib_search_solr_site_preprocessor($variables, 'databases');
}
/**
* @param $variables
*/
function roblib_search_solr_site_preprocess_roblib_search_solr_site_guides(&$variables) {
roblib_search_solr_site_preprocessor($variables, 'guides');
}
/**
* @param array $variables
* @param string $type
*
* @return string
*/
function roblib_search_solr_site_preprocessor(&$variables, $type) {
global $base_url;
if (!isset($query)) {
if (isset($_GET['roblib_query'])) {
@ -15,12 +49,11 @@ function roblib_search_solr_site_preprocess_roblib_search_solr_site(&$variables)
return '';
}
}
$spinner_path = $base_url . '/' . drupal_get_path('module', 'roblib_search') . '/img/'.'spinner.gif';
$spinner_path = $base_url . '/' . drupal_get_path('module', 'roblib_search') . '/img/' . 'spinner.gif';
$variables['spinner_path'] = $spinner_path;
$search_url = $base_url .'/roblib_search/solr_site/ajax/'.urlencode($query);
drupal_add_js(drupal_get_path('module', 'roblib_search_solr_site') . '/js/solr_site_results.js');
drupal_add_js(array('roblib_search_solr_site' => array('search_url' => $search_url,
'search_query' => urlencode($query))), array('type' => 'setting'));
$variables['type'] = $type;
$search_url = $base_url . '/roblib_search/solr_site/' . $type . '/' . urlencode($query);
drupal_add_js(drupal_get_path('module', 'roblib_search_solr_site') . '/js/solr_site_' . $type . '.js');
$key = 'roblib_search_solr_site_' . $type;
drupal_add_js(array($key => array('search_url' => $search_url)), array('type' => 'setting'));
}
?>

Loading…
Cancel
Save