Issue #1642140 by Nick_vh: Fixed Make the search query also escape the slash and... 7.x-1.0-rc1
authorNick_vh
Thu, 21 Jun 2012 09:28:25 +0000 (11:28 +0200)
committerNick_vh
Thu, 21 Jun 2012 09:28:25 +0000 (11:28 +0200)
CHANGELOG.txt
Solr_Base_Query.php
apachesolr.module
apachesolr_search.module
apachesolr_search.pages.inc

index fa4c4c9..1ddc952 100644 (file)
@@ -1,5 +1,6 @@
 Apache Solr integration 7.x-1.x-xxxx, xxxx-xx-xx
 ------------------------------
+#1642140 by Nick_vh: Fixed Make the search query also escape the slash and move away from menu_tail() to just 1 argument.
 #1518108 by grendzy: Added Devel interface for inspecting solr documents.
 #1402748 by Nick_vh: Fixed Check in apachesolr_do_query() if the static of the query with that name already exists, and if so return it.
 #1631702 by Nick_vh | khaled.zaidan: Fixed Report at admin/reports/apachesolr doesn't always display data from the current default solr server.
index 0eecc08..95373d6 100644 (file)
@@ -278,7 +278,7 @@ class SolrBaseQuery extends SolrFilterSubQuery implements DrupalSolrQueryInterfa
   protected $solrsort = array('#name' => 'score', '#direction' => 'desc');
   // A flag to allow the search to be aborted.
   public $abort_search = FALSE;
-  
+
   // A flag to check if need to retrieve another page of the result set
   public $page = 0;
 
@@ -576,7 +576,11 @@ class SolrBaseQuery extends SolrFilterSubQuery implements DrupalSolrQueryInterfa
       return $this->base_path . '/' . $this->getParam('q');
     }
     else {
-      return $this->base_path;
+      // Return with empty query (the slash). The path for a facet
+      // becomes $this->base_path . '//facetinfo';
+      // We do this so we can have a consistent way of retrieving the query +
+      // additional parameters
+      return $this->base_path . '/';
     }
   }
 
index a5728fc..e201fe9 100644 (file)
@@ -491,7 +491,7 @@ function apachesolr_failure($search_name, $querystring) {
         if (isset($search_info[$fail_rule])) {
           $search_info = $search_info[$fail_rule];
           drupal_set_message(t("%search_name is not available. Your search is being redirected.", array('%search_name' => $search_name)));
-          drupal_goto('search/' . $search_info['path'] . '/' . drupal_encode_path($querystring));
+          drupal_goto('search/' . $search_info['path'] . '/' . rawurlencode($querystring));
         }
       }
       // if search is not enabled, break and do nothing
index 694ecb0..1a01ffa 100644 (file)
@@ -161,7 +161,8 @@ function apachesolr_search_menu_alter(&$items) {
       'file path' => drupal_get_path('module', 'apachesolr_search'),
     );
 
-    $items[$search_page['search_path'] . '/%menu_tail'] = array(
+    // Not using menu tail because of inflexibility with clean urls
+    $items[$search_page['search_path'] . '/%'] = array(
       'title' => $page_title,
       'load arguments' => array('%map', '%index'),
       'page callback' => 'apachesolr_search_custom_page',
@@ -180,13 +181,13 @@ function apachesolr_search_menu_alter(&$items) {
       $title_callback = $search_type['title callback'];
       $items[$search_page['search_path']]['title callback'] = $title_callback;
       $items[$search_page['search_path']]['title arguments'] = array($search_page['page_id'], $position);
-      $items[$search_page['search_path'] . '/%menu_tail']['title callback'] = $title_callback;
-      $items[$search_page['search_path'] . '/%menu_tail']['title arguments'] = array($search_page['page_id'], $position);
+      $items[$search_page['search_path'] . '/%']['title callback'] = $title_callback;
+      $items[$search_page['search_path'] . '/%']['title arguments'] = array($search_page['page_id'], $position);
     }
     // If we have additional searches in the search/* path
     if ($core_search) {
-      $items[$search_page['search_path'] . '/%menu_tail']['tab_root'] = 'search/' . $default_info['path'] . '/%';
-      $items[$search_page['search_path'] . '/%menu_tail']['tab_parent'] = 'search/' . $default_info['path'];
+      $items[$search_page['search_path'] . '/%']['tab_root'] = 'search/' . $default_info['path'] . '/%';
+      $items[$search_page['search_path'] . '/%']['tab_parent'] = 'search/' . $default_info['path'];
     }
 
     if ($taxonomy_search) {
@@ -1425,7 +1426,11 @@ function apachesolr_search_apachesolr_environment_delete($server) {
   menu_rebuild();
 }
 
-
+function apachesolr_search_form_search_block_form_alter(&$form, $form_state) {
+  if (variable_get('search_default_module') == 'apachesolr_search') {
+    $form['#submit'][] = 'apachesolr_search_form_search_submit';
+  }
+}
 /**
  * Implements hook_form_[form_id]_alter().
  *
@@ -1486,11 +1491,20 @@ function theme_apachesolr_search_suggestions($variables) {
  */
 function apachesolr_search_form_search_submit($form, &$form_state) {
   $fv = $form_state['values'];
-  $get = json_decode($fv['apachesolr_search']['get'], TRUE);
-  if (!empty($fv['apachesolr_search']['retain-filters'])) {
-    $get['retain-filters'] = '1';
-    // Add the query values into the redirect.
-    $form_state['redirect'] = array($form_state['redirect'], array('query' => $get));
+
+  if (isset($fv['apachesolr_search'])) {
+    $get = json_decode($fv['apachesolr_search']['get'], TRUE);
+    if (!empty($fv['apachesolr_search']['retain-filters'])) {
+      $get['retain-filters'] = '1';
+      // Add the query values into the redirect.
+      $form_state['redirect'] = array($form_state['redirect'], array('query' => $get));
+    }
+  }
+
+  // Replace keys with their rawurldecoded value
+  if (isset($fv['search_block_form'])) {
+    $raw_keys = rawurlencode($fv['search_block_form']);
+    $form_state['redirect'] = str_replace($fv['search_block_form'], $raw_keys, $form_state['redirect']);
   }
 }
 
index 9e49667..909ab35 100644 (file)
@@ -22,6 +22,8 @@ function apachesolr_search_custom_page($page_id, $keys = '', $path_replacer = NU
   $search_page->search_path = str_replace('%', $path_replacer, $search_page->search_path);
   // Retrieve the conditions that apply to this page
   $conditions = apachesolr_search_conditions_default($search_page);
+  // Process our keys so they are clean
+  $keys = rawurldecode($keys);
   // Retrieve the results of the search
   $results = apachesolr_search_search_results($keys, $conditions, $search_page);
   // Initiate our build array
@@ -93,8 +95,14 @@ function apachesolr_search_custom_page_search_form($form, &$form_state, $search_
 function apachesolr_search_custom_page_search_form_submit(&$form, &$form_state) {
   $search_page = $form['#search_page'];
   $redirect = $search_page->search_path;
+
+  // Also encode slashes so we don't get akward situations when obtaining the
+  // search key. We can't use drupal_encode_path because for "aestetic" reasons
+  // they don't encode slashes...
+  $redirect_value = rawurlencode($form_state['values']['keys']);
+
   if (strlen($form_state['values']['keys'])) {
-    $redirect .= '/' . $form_state['values']['keys'];
+    $redirect .= '/' . $redirect_value;
   }
   if (isset($form_state['values']['get'])) {
     $get = json_decode($form_state['values']['get'], TRUE);