Skip to content

Commit

Permalink
add the ability to switch displays through the url - needs bit of fin…
Browse files Browse the repository at this point in the history
…etuning by adding the ability to limit available displays
  • Loading branch information
DannyJoris committed Jan 16, 2012
1 parent 1169a52 commit d92e47b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
16 changes: 12 additions & 4 deletions IslandoraSolrQueryProcessor.inc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ class IslandoraSolrQueryProcessor {
}
$this->solrStart = max(0, $startPage) * $this->solrLimit;

// look for the current display
$display = isset($_GET['display']) ? $_GET['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 +161,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 @@ -176,8 +184,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 @@ -190,7 +198,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
42 changes: 32 additions & 10 deletions IslandoraSolrResults.inc
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ class IslandoraSolrResults {
$solrQueryProcessor->solrResult->facet_counts->facet_fields :
NULL;
//dsm($islandora_facets);

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

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

// Variables to build a drupal-ish unordered list
Expand All @@ -231,9 +239,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 @@ -271,9 +282,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 @@ -368,12 +382,20 @@ 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
$display = isset($_GET['display']) ? $_GET['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++;
}
Expand Down
8 changes: 5 additions & 3 deletions islandora_solr_search.module
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,16 @@ function islandora_solr_search($query, $fq=NULL, $dismax=NULL) {
// Build and execute Apache Solr query
$queryResult = $queryClass->buildAndExecuteQuery($query, $fq, $dismax);

// get profiles
$primary_profiles = module_invoke_all("islandora_solr_primary_display");
$secondary_profiles = module_invoke_all("islandora_solr_secondary_display");
// Get the preferred display profile
// Order: First choice is what's in the ?profile query var
// Second choice is the primary display profile
// Third choice is the default IslandoraSolrResults
$islandora_solr_primary_display = variable_get('islandora_solr_primary_display', 'default');
$islandora_solr_primary_display = ((isset($_GET['display']) AND array_key_exists($_GET['display'], $primary_profiles)) ? $_GET['display'] : variable_get('islandora_solr_primary_display', 'default'));
$islandora_solr_selected_display = isset($_GET['solr_profile']) ? $_GET['solr_profile'] : NULL;
$primary_profiles = module_invoke_all("islandora_solr_primary_display");
$secondary_profiles = module_invoke_all("islandora_solr_secondary_display");


// TODO: Also filter secondary displays against those checked in the configuration options.
if (isset($secondary_profiles[$islandora_solr_selected_display])) {
Expand Down

0 comments on commit d92e47b

Please sign in to comment.