From d92e47b4ffcdbea6a9df30317f62dcd114449625 Mon Sep 17 00:00:00 2001 From: Danny Joris Date: Mon, 16 Jan 2012 12:03:40 -0400 Subject: [PATCH] add the ability to switch displays through the url - needs bit of finetuning by adding the ability to limit available displays --- IslandoraSolrQueryProcessor.inc | 16 +++++++++---- IslandoraSolrResults.inc | 42 +++++++++++++++++++++++++-------- islandora_solr_search.module | 8 ++++--- 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/IslandoraSolrQueryProcessor.inc b/IslandoraSolrQueryProcessor.inc index 7e65f164..06e5613b 100644 --- a/IslandoraSolrQueryProcessor.inc +++ b/IslandoraSolrQueryProcessor.inc @@ -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; @@ -154,6 +161,7 @@ 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); @@ -161,7 +169,7 @@ class IslandoraSolrQueryProcessor { $options['attributes']['class'] = "strikethrough"; } $breadcrumb[] = l($value, $crumblink, $options) . - " (" . l("x", $cutlink, array('attributes' => array('title' => "Remove " . $facet))) . ")"; + " (" . l("x", $cutlink, array('attributes' => array('title' => "Remove " . $facet), 'query' => $query)) . ")"; $breadcrumb_fq = $this->delete_filter($breadcrumb_fq, $facet); } } @@ -176,8 +184,8 @@ class IslandoraSolrQueryProcessor { } } if ($queryval != '%252F') { - $breadcrumb[] = l($queryval, $queryurl . "/-", array('attributes' => array('title' => $this->solrQuery))) . - " (" . l("x", $cutlink, array('attributes' => array('title' => "Remove " . $facet))) . ")"; + $breadcrumb[] = l($queryval, $queryurl . "/-", array('attributes' => array('title' => $this->solrQuery), 'query' => $query)) . + " (" . l("x", $cutlink, array('attributes' => array('title' => "Remove " . $facet), 'query' => $query)) . ")"; } } $breadcrumb[] = l(t('Home'), NULL); @@ -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; } diff --git a/IslandoraSolrResults.inc b/IslandoraSolrResults.inc index 20d06314..140ee637 100644 --- a/IslandoraSolrResults.inc +++ b/IslandoraSolrResults.inc @@ -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 @@ -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( - 'Remove search term', 'islandora/solr/search/' . " " . '/' . replaceSlashes($islandora_fq) . '/dismax', array('html' => TRUE) - ) . ' ' . stripslashes($solrQueryProcessor->solrQuery); + + // set link properties + $image = '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 .= '
'; @@ -271,9 +282,12 @@ class IslandoraSolrResults { $exclude = TRUE; $filter_name = substr($filter_name, 1); } - $filter_list_items[] = l( - '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 = '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; } } @@ -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 . ')' . '' . - 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 )) . ''; $facet_count++; } diff --git a/islandora_solr_search.module b/islandora_solr_search.module index 156932cd..6695003b 100644 --- a/islandora_solr_search.module +++ b/islandora_solr_search.module @@ -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])) {