Browse Source

now reads default search module type for database for link back to see all results

2.x-ebsco
Paul Pound 10 years ago
parent
commit
35bf2c9d71
  1. 31
      targets/eds/roblib_search_eds.module
  2. 3
      targets/solr_site/js/solr_site_databases.js
  3. 3
      targets/solr_site/js/solr_site_guides.js
  4. 3
      targets/solr_site/js/solr_site_results.js
  5. 4
      targets/solr_site/roblib_search_solr_site.module
  6. 3
      targets/solr_site/theme/theme.inc

31
targets/eds/roblib_search_eds.module

@ -198,13 +198,7 @@ function roblib_search_eds_block_info() {
function roblib_search_eds_block_view($delta = '') {
switch ($delta) {
case 'roblib_search_eds_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('Books & Media');
// The content of the block is typically generated by calling a custom
// function.
// $block['content'] = roblib_search_eds_get_results();
$block['content'] = theme('roblib_search_eds', array('results' => NULL));
break;
@ -257,10 +251,23 @@ function roblib_search_eds_get_results($query = NULL, $type = NULL) {
//$params = "query=AND,$query&view=detailed&includefacets=n&$limiters&resultsperpage=$number_per_page";
$params = "query=AND,$query&view=detailed&includefacets=n&resultsperpage=$number_per_page";
$output = $eds_api->apiSearch($params);
$output = roblib_search_eds_get_detailed_result($output, $query, $eds_api);
roblib_search_eds_get_detailed_result($output, $query, $eds_api);
return json_encode($output);
}
/**
* For each result query ebsco again to get the detailed record.
*
* and insert a new DetailedRecord element in each record.
*
* @param array $output
* The orginal search results array
* @param string $query
* The orginal query
* @param object $eds_api
* an ebco API PHP object
*/
function roblib_search_eds_get_detailed_result(&$output, $query, &$eds_api) {
foreach ($output['records'] as &$record) {
$db = $record['DbId'];
@ -268,9 +275,17 @@ function roblib_search_eds_get_detailed_result(&$output, $query, &$eds_api) {
$arr = $eds_api->apiRetrieve($an, $db, $query);
$record['DetailedRecord'] = $arr['Items'];
}
return $output;
}
/**
* Creates the limiter string to append to the end of a query.
*
* @param string $type
* The type of search we want (Articles or Books)
*
* @return string
* The limiters to append to the query.
*/
function roblib_search_eds_get_query_limiters($type) {
$limiters = 'n';
switch ($type) {

3
targets/solr_site/js/solr_site_databases.js

@ -3,6 +3,7 @@ Drupal.behaviors.roblib_search_solr_site_databases = {
$url = settings.roblib_search_solr_site_databases.search_url;
query = settings.roblib_search_solr_site_results.search_query;
baseUrl = settings.roblib_search_solr_site_results.base_url;
default_site_type = settings.roblib_search_solr_site_results.default_site_type + '/';
jQuery.getJSON($url, function(data) {
var items = [];
var numberOfDocs = 0;
@ -35,7 +36,7 @@ Drupal.behaviors.roblib_search_solr_site_databases = {
}
if (numberOfDocs > 0)
{
jQuery('#' + 'roblib-search-solr-site-databases-more').empty().append('<a href="'+ baseUrl + '/search/site/' + query +'?f[0]=bundle%3Adatabase">see all results</a>');
jQuery('#' + 'roblib-search-solr-site-databases-more').empty().append('<a href="'+ baseUrl + '/search/' + default_site_type + query +'?f[0]=bundle%3Adatabase">see all results</a>');
}
});
}

3
targets/solr_site/js/solr_site_guides.js

@ -3,6 +3,7 @@ Drupal.behaviors.roblib_search_solr_site_guides = {
$url = settings.roblib_search_solr_site_guides.search_url;
query = settings.roblib_search_solr_site_results.search_query;
baseUrl = settings.roblib_search_solr_site_results.base_url;
default_site_type = settings.roblib_search_solr_site_results.default_site_type + '/';
jQuery.getJSON($url, function(data) {
var items = [];
var numberOfDocs = 0;
@ -33,7 +34,7 @@ Drupal.behaviors.roblib_search_solr_site_guides = {
}
if (numberOfDocs > 0)
{
jQuery('#' + 'roblib-search-solr-site-guides-more').empty().append('<a href="'+ baseUrl + '/search/site/' + query +'?f[0]=im_field_keywords%3A627">see all results</a>');
jQuery('#' + 'roblib-search-solr-site-guides-more').empty().append('<a href="'+ baseUrl + '/search/' + default_site_type + query +'?f[0]=im_field_keywords%3A627">see all results</a>');
}
});
}

3
targets/solr_site/js/solr_site_results.js

@ -3,6 +3,7 @@ Drupal.behaviors.roblib_search_solr_site_results = {
url = settings.roblib_search_solr_site_results.search_url;
query = settings.roblib_search_solr_site_results.search_query;
baseUrl = settings.roblib_search_solr_site_results.base_url;
default_site_type = settings.roblib_search_solr_site_results.default_site_type + '/';
jQuery.getJSON(url, function(data) {
var items = [];
var numberOfDocs = 0;
@ -35,7 +36,7 @@ Drupal.behaviors.roblib_search_solr_site_results = {
}
if (numberOfDocs > 0)
{
jQuery('#' + 'roblib-search-solr-site-results-more').empty().append('<a href="'+ baseUrl + '/search/site/' + query +'">see all results</a>');
jQuery('#' + 'roblib-search-solr-site-results-more').empty().append('<a href="'+ baseUrl + '/search/' + default_site_type + query +'">see all results</a>');
}
});
}

4
targets/solr_site/roblib_search_solr_site.module

@ -311,6 +311,10 @@ function roblib_search_solr_site_add_url($json) {
$responses = json_decode($json);
foreach ($responses->response->docs as &$doc) {
$nid = $doc->entity_id;
// The link field is a complex field and we get the text in solr but not the actual url.
// Since best best will only every return one result it's not much overhead to load the node
// and get the value of the link field. probably less overhead then installing additional
// modules to get the url in solr.
$node = node_load($nid);
$url = $node->field_link['und'][0]['url'];
$doc->url = $url;

3
targets/solr_site/theme/theme.inc

@ -56,6 +56,7 @@ function roblib_search_solr_site_preprocessor(&$variables, $type) {
$search_url = $base_url . '/roblib_search/solr_site/' . $type . '/' . $query;
drupal_add_js(drupal_get_path('module', 'roblib_search_solr_site') . '/js/solr_site_' . $type . '.js');
$key = 'roblib_search_solr_site_' . $type;
$default_module = variable_get('search_default_module','node');
drupal_add_js(array($key => array('search_url' => $search_url, 'search_query' => $query,
'base_url' => $base_url)), array('type' => 'setting'));
'base_url' => $base_url, 'default_site_type' => $default_module)), array('type' => 'setting'));
}

Loading…
Cancel
Save