Skip to content

Commit

Permalink
Merge branch '6.x' of git://github.com/Islandora/islandora_solr_searc…
Browse files Browse the repository at this point in the history
…h into 6.x
  • Loading branch information
adam-vessey committed Jan 17, 2012
2 parents 66b1125 + 12707fe commit 95d645a
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 52 deletions.
39 changes: 31 additions & 8 deletions IslandoraSolrQueryProcessor.inc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class IslandoraSolrQueryProcessor {
* @param type $dismax
* @return type
*/
function buildAndExecuteQuery($query, $fq=NULL, $dismax=NULL) {
function buildAndExecuteQuery($query, $fq=NULL, $dismax=NULL, $params = NULL) {

if (variable_get('islandora_solr_search_block_request_handler', NULL) == 'standard') {
$namespace = trim(variable_get('solr_namespace_restriction', NULL));
Expand All @@ -61,19 +61,21 @@ class IslandoraSolrQueryProcessor {
}
}
}
$this->buildQuery($query, $fq, $dismax);
$this->buildQuery($query, $fq, $dismax, $params);

return $this->executeQuery();
}

/**
* Default implementation for solr search. You can configure others in the block config settings
* @todo Get rid of the global $facetArray? It is the only global yet relied upon.
*/
function buildQuery($query, $fq=NULL, $dismax=NULL) {
function buildQuery($query, $fq=NULL, $dismax=NULL, $params = array()) {
// Get pager variable
$startPage = isset($_GET['page']) ? $_GET['page'] : 0;
$this->solrLimit = variable_get('islandora_solr_search_num_of_results', 20);
global $base_url, $facetArray; //used by facet block as well

// -- cut here --
// Get display profile
$islandora_solr_primary_display = variable_get('islandora_solr_primary_display', 'default');
Expand All @@ -83,7 +85,11 @@ class IslandoraSolrQueryProcessor {
return "";
}
$profile = $profiles[$islandora_solr_primary_display];

if ($profile['params']) {
foreach ($profile['params'] as $param) {
$params[] = $param;
}
}
// Include the file for the display profile
require_once(drupal_get_path('module', $profile['module']) . '/' . $profile['file']);

Expand Down Expand Up @@ -126,6 +132,9 @@ class IslandoraSolrQueryProcessor {
);


if (is_array($params)) {
$this->solrParams = array_merge($this->solrParams, $params);
}
$debugQuery = (variable_get('islandora_solr_search_debug_mode', 0) ? "TRUE" : NULL ); //any val incl. 'FALSE' is treated as TRUE by Solr

if ($fq != NULL && $fq != '-') {
Expand All @@ -144,6 +153,19 @@ class IslandoraSolrQueryProcessor {
}
$this->solrStart = max(0, $startPage) * $this->solrLimit;

// look for the current display
// it seems like this function is happening before we even look which display
// to use, so we'll have to check again using hook_invoke_all and checking
// the variable.
$primary_profiles = module_invoke_all("islandora_solr_primary_display");
$islandora_solr_primary_display = ((isset($_GET['display']) AND array_key_exists($_GET['display'], $primary_profiles)) ? $_GET['display'] : variable_get('islandora_solr_primary_display', 'default'));
//global $current_display;
$display = isset($_GET['display']) ? $islandora_solr_primary_display : '';
$query = '';
if ($display) {
$query = array('display' => $display);
}

// The breadcrumb should go in the display class
$queryurl = "islandora/solr/search/" . replaceSlashes($this->solrQuery);
$breadcrumb_fq = $islandora_fq;
Expand All @@ -154,14 +176,15 @@ class IslandoraSolrQueryProcessor {
$value = restoreSlashes(trim(substr($facet, strpos($facet, ":") + 1), '"'));
$options = array('html' => TRUE);
$options['attributes']['title'] = $facet;
$options['query'] = $query; // query for display
$crumblink = $queryurl . "/" . $breadcrumb_fq . (empty($this->solrDefType) ? '' : '/' . $this->solrDefType);
$cut_fq = $this->delete_filter($islandora_fq, $facet);
$cutlink = $queryurl . "/" . $cut_fq . (empty($this->solrDefType) ? '' : '/' . $this->solrDefType);
if (!strncmp("-", $facet, 1)) {
$options['attributes']['class'] = "strikethrough";
}
$breadcrumb[] = l($value, $crumblink, $options) .
" <span class='islandora_solr_search_breadcrumb_super'>(" . l("x", $cutlink, array('attributes' => array('title' => "Remove " . $facet))) . ")</span>";
" <span class='islandora_solr_search_breadcrumb_super'>(" . l("x", $cutlink, array('attributes' => array('title' => "Remove " . $facet), 'query' => $query)) . ")</span>";
$breadcrumb_fq = $this->delete_filter($breadcrumb_fq, $facet);
}
}
Expand All @@ -177,8 +200,8 @@ class IslandoraSolrQueryProcessor {
}
}
if ($queryval != '%252F') {
$breadcrumb[] = l($queryval, $queryurl . "/-", array('attributes' => array('title' => $this->solrQuery))) .
" <span class='islandora_solr_search_breadcrumb_super'>(" . l("x", $cutlink, array('attributes' => array('title' => "Remove " . $facet))) . ")</span>";
$breadcrumb[] = l($queryval, $queryurl . "/-", array('attributes' => array('title' => $this->solrQuery), 'query' => $query)) .
" <span class='islandora_solr_search_breadcrumb_super'>(" . l("x", $cutlink, array('attributes' => array('title' => "Remove " . $facet), 'query' => $query)) . ")</span>";
}
}
$breadcrumb[] = l(t('Home'), NULL);
Expand All @@ -191,7 +214,7 @@ class IslandoraSolrQueryProcessor {
// At this point let's invoke a hook for third-party modules to mess about
// with the query parameters if they need to. Third party modules may alter
// this object's query parameters if they wish.
// module_invoke_all("islandora_solr_search_query_processor", &$this);
module_invoke_all("islandora_solr_search_query_processor", &$this);
return;
}

Expand Down
112 changes: 95 additions & 17 deletions IslandoraSolrResults.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class IslandoraSolrResults {
* @param type $solrQueryProcessor
* @param type $title
* @param type $output
* @return string
* @return string
*/
function displayResults($solrQueryProcessor, $title = "Search Results", $output = '') {
$apacheSolrResult = $solrQueryProcessor->solrResult;
Expand Down Expand Up @@ -80,7 +80,7 @@ class IslandoraSolrResults {
}

// if number of elements is the same as the number of disabled displays,
// this means that there are no displays enabled.
// this means that there are no displays enabled.
if ($array_count != $i) {

$output .= "<div id='islandora_solr_secondary_display_profiles'>";
Expand Down Expand Up @@ -143,7 +143,13 @@ class IslandoraSolrResults {
$title = NULL;
$recordStart = $results->response->start;
$limitResults = variable_get('islandora_solr_search_limit_result_fields', 0);
$rawResponse = $results->getRawResponse();
$responseArray = json_decode($rawResponse, true);
$docs = $responseArray['response']['docs'];
//retrieve 'highlighing' from resultset.
$highlightResults = $responseArray['highlighting'];
$highlights = $results->highlighting;

foreach ($highlights as $highlight) {
$fields = get_object_vars($highlight);
$keys = array_keys($fields);
Expand All @@ -163,7 +169,7 @@ class IslandoraSolrResults {
foreach ($results->response->docs as $doc) {
$rows = array();
$row = 0;

$snippet = null;
foreach ($doc as $field => $value) {

if ($limitResults && empty($this->resultFieldArray[$field])) {
Expand All @@ -180,14 +186,25 @@ class IslandoraSolrResults {
}

if ($field == 'PID') {
$pid = $value;
$l = l($value, 'fedora/repository/' . htmlspecialchars($value, ENT_QUOTES, 'utf-8'));
$rows[$row][] = $l;
if (is_array($keys)) {
$snippet = $highlightResults[$value][$keys[0]];
}
}
else {
$rows[$row][] = $value;
}
$row++;
}
if ($snippet) {
$rows[$row][] = array(
'data' => 'Full Text',
'header' => TRUE,
);
$rows[$row][] = $snippet[0];
}
$items[] = theme_table(NULL, $rows, array('class' => 'islandora_solr_search_results_object'));
}
$output .= theme_item_list($items, $title, $type, array('class' => 'stuff', 'start' => ($recordStart + 1)));
Expand Down Expand Up @@ -226,6 +243,15 @@ class IslandoraSolrResults {
$solrQueryProcessor->solrResult->facet_counts->facet_fields :
NULL;
//dsm($islandora_facets);

// look for the current display
global $current_display;
$display = isset($_GET['display']) ? $current_display : '';
$query = '';
if ($display) {
$query = array('display' => $display);
}

if (strlen(trim($solrQueryProcessor->solrQuery))) {

// Variables to build a drupal-ish unordered list
Expand All @@ -237,9 +263,12 @@ class IslandoraSolrResults {
// OK, so it's a list of one.
// In the future, we could reasonably break the query on boolean operators
// and allow one part to be removed at a time.
$query_list_items[] .= l(
'<img class="islandora_solr_add_remove_link" src="' . $base_url . '/' . drupal_get_path('module', 'islandora_solr_search') . '/images/delete.png" alt="Remove search term">', 'islandora/solr/search/' . " " . '/' . replaceSlashes($islandora_fq) . '/dismax', array('html' => TRUE)
) . ' ' . stripslashes($solrQueryProcessor->solrQuery);

// set link properties
$image = '<img class="islandora_solr_add_remove_link" src="' . $base_url . '/' . drupal_get_path('module', 'islandora_solr_search') . '/images/delete.png" alt="Remove search term">';
$link = 'islandora/solr/search/' . " " . '/' . replaceSlashes($islandora_fq) . '/dismax';

$query_list_items[] .= l($image, $link, array('html' => TRUE, 'query' => $query )) . ' ' . stripslashes($solrQueryProcessor->solrQuery);

$output .= '<div class="islandora_solr_search_query_wrap">';

Expand Down Expand Up @@ -277,9 +306,12 @@ class IslandoraSolrResults {
$exclude = TRUE;
$filter_name = substr($filter_name, 1);
}
$filter_list_items[] = l(
'<img class="islandora_solr_add_remove_link" src="' . $base_url . '/' . drupal_get_path('module', 'islandora_solr_search') . '/images/delete.png" alt="Remove this filter">', 'islandora/solr/search/' . replaceSlashes($solrQueryProcessor->solrQuery) . '/' . replaceSlashes($filter_disable) . '/' . $solrQueryProcessor->solrDefType, array('html' => TRUE)
) . ' ' . $this->facetFieldArray[$filter_name] . ($exclude ? ' != ' : ' = ') . $filter_value;

// set link properties
$image = '<img class="islandora_solr_add_remove_link" src="' . $base_url . '/' . drupal_get_path('module', 'islandora_solr_search') . '/images/delete.png" alt="Remove this filter">';
$link = 'islandora/solr/search/' . replaceSlashes($solrQueryProcessor->solrQuery) . '/' . replaceSlashes($filter_disable) . '/' . $solrQueryProcessor->solrDefType;

$filter_list_items[] = l($image, $link, array('html' => TRUE, 'query' => $query )) . ' ' . $this->facetFieldArray[$filter_name] . ($exclude ? ' != ' : ' = ') . $filter_value;
}
}

Expand Down Expand Up @@ -331,6 +363,10 @@ class IslandoraSolrResults {
if (empty($islandora_facets)) {
return $output; //no facets to show
}

// set counter to include javascript later
$i = 0;

foreach ($islandora_facets as $key => $field) {
$list_items = array();
$list_type = "ul";
Expand All @@ -343,6 +379,7 @@ class IslandoraSolrResults {
$filter_include = NULL;
$filter_exclude = NULL;
$disable_link = FALSE;
// dsm($field);
foreach ($field as $name => $number) {
if ($islandora_fq && $islandora_fq != '-') {//there are existing facets in the query
$disable_link = strstr($islandora_fq, $key . ':"' . replaceSlashes($name) . '"'); //we don't want a link for this facet as we already used it
Expand All @@ -369,27 +406,68 @@ class IslandoraSolrResults {
$evenodd = ( $facet_count % 2 ? 'odd' : 'even' );
$lplus = 'islandora/solr/search/' . $solrQueryProcessor->solrQuery . '/' . $filter_include . '/' . $solrQueryProcessor->solrDefType;
$lminus = 'islandora/solr/search/' . $solrQueryProcessor->solrQuery . '/' . $filter_exclude . '/' . $solrQueryProcessor->solrDefType;


// look for the current display
global $current_display;
$display = isset($_GET['display']) ? $current_display : '';
$query = '';
if ($display) {
$query = array('display' => $display);
}

$text = $name;
$attrs = array();
$list_items[] = l($text, $lplus, $attrs) . ' (' . $number . ')' .
$list_items[] = l($text, $lplus, array('query' => $query)) . ' (' . $number . ')' .
'<span class="plusminus">' .
l('+', $lplus, array('attributes' => array('class' => 'plus'))) . ' ' .
l('-', $lminus, array('attributes' => array('class' => 'minus'))) .
l('+', $lplus, array('attributes' => array('class' => 'plus'), 'query' => $query )) . ' ' .
l('-', $lminus, array('attributes' => array('class' => 'minus'), 'query' => $query )) .
'</span>';
$facet_count++;
}
}
if ($facet_count >= 2) {
if ($facet_count >= 1) {
$facet_output .='<div class="islandora_solr_search_facet">';

// shown limit
$shown_limit = variable_get('islandora_solr_search_block_facet_shown_limit', 0);
$facetlimit = variable_get('islandora_solr_search_block_facet_limit', '12');
$facetMinCount = variable_get('islandora_solr_search_block_facet_min_count', '2');

$list_title = $this->facetFieldArray[$key];
$list_type = "ul";
$list_attributes = array('class' => 'islandora_solr_search_facet_list facet_list');

// set show more variable
$show_more = FALSE;

// split the array if shown_limit is between the min and max limits and if the total is larger than the shown_limit.
if ($facet_count > $shown_limit AND $shown_limit < $facetlimit AND $shown_limit > $facetMinCount) {
$list_items_hidden = array_slice($list_items, $shown_limit);
$list_items = array_slice($list_items, 0, $shown_limit);
$show_more = TRUE;
}

$facet_output .= theme_item_list($list_items, $list_title, $list_type, $list_attributes);

// set counter
if ($show_more == TRUE) {
$i++;
$facet_output .= '<a href="#" class="shown-toggle">' . t('Show more') . '</a>';
$facet_output .= '<a href="#" class="shown-toggle hidden">' . t('Show less') . '</a>';
$facet_output .= '<div class="toggle-wrapper hidden">';
$facet_output .= theme_item_list($list_items_hidden, NULL, $list_type, $list_attributes);
$facet_output .= '</div>';
}

$facet_output .='</div>';
}
}
}

if ($i >= 1) {
// if there is at least one occurence of a split array, we add js to the page.
drupal_add_js(drupal_get_path('module', 'islandora_solr_search') . '/js/islandora_solr_search_shown_limit.js');
}

//////////////////////////////////////////////////////////////////////////////////////
// as we add additional facets, we're repeatedly URL-encoding old facet //
Expand All @@ -411,7 +489,7 @@ class IslandoraSolrResults {
* @param type $repeat
* @param type $pathToSearchTerms
* @param type $query
* @return string
* @return string
*/
function build_solr_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) {

Expand Down Expand Up @@ -497,7 +575,7 @@ class IslandoraSolrResults {
/**
* Build simple solr form
* @global type $islandora_query
* @return type
* @return type
*/
function build_simple_solr_form() {
$required = FALSE;
Expand Down Expand Up @@ -526,7 +604,7 @@ class IslandoraSolrResults {
/**
* Theme solr search form
* @param type $form
* @return type
* @return type
*/
function theme_solr_search_form($form) {
if (!isset($repeat)) {
Expand Down
7 changes: 7 additions & 0 deletions islandora_solr_search.css → css/islandora_solr_search.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,11 @@ html.js .refresh-button {

.strikethrough {
text-decoration: line-through !important;
}

/* hide the 2nd list if a facet list is split in two */

.islandora_solr_search_facet .hidden
{
display: none;
}
19 changes: 13 additions & 6 deletions islandora_solr_config/IslandoraSolrResultsTable.inc
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,26 @@ class IslandoraSolrResultsTable extends IslandoraSolrResults {
foreach ($values as $num => $val_array) {
unset($rowclass);
$result_num = $recordStart + $num + 1;
$rows[$row][] = array(
$rows[$row]['data'][] = array(
'data' => (isset($val_array['PID']) ? l($result_num,'fedora/repository/'.$val_array['PID']) : $result_num),
'header' => TRUE,
'class' => 'col-first'

);
foreach ($fields as $field) {
if (isset ($val_array[$field])) {
$rows[$row][] = $val_array[$field];
} else {
$rows[$row][] = '';
$field_count = count($fields);
foreach ($fields as $fieldnum => $field) {
if (!isset ($val_array[$field])) {
$val_array['field'] = " ";
}
$cell_data = array('data' => $val_array[$field]);
$rows[$row]['data'][] = $cell_data;

}
$rows[$row]['data'][$field_count]['class'] = 'col-last';
$row++;
}
$rows[0]['class'] = 'row-first';
$rows[$row -1]['class'] = 'row-last';

$output .= theme_table($header,$rows,array('class'=>'islandora_solr_search_results_table'));

Expand Down
Loading

0 comments on commit 95d645a

Please sign in to comment.