0

When a user enters a blank search, by clicking "search" right away, or entering the search result url directly, the initial version of the Apache Solr Search Integration module, 6.x-1.x series, tells the user to "Please enter some keywords".

I would like it to issue the empty search, thereby returning all available results. This question List all available items with Apache Solr if the search keyword is empty asks the same for the second generation of the module, 6.x-3.x and 7.x-1.x, but that answer doesn't apply.

I've tried hacking out the if ($keys == '' check that yields the "error" message, but that simply results in no results at all.

0

I ended up with the below patch that seems to do the trick. The patch looks much larger than it needs to because I corrected the indentation after I removed an if.

Anyone that considers using this patch should be aware that this will hack the module. You should understand what that means, and be using a make file to avoid future complications.

$ diff -u apachesolr_search.module_ apachesolr_search.module
--- apachesolr_search.module_   2013-02-11 10:12:17.814561087 +0100
+++ apachesolr_search.module    2013-02-11 13:29:10.450336901 +0100
@@ -159,24 +159,22 @@ 
   if (isset($_GET['filters'])) {
     $filters = trim($_GET['filters']);
   }  
-  // Only perform search if there is non-whitespace search term or filters:
-  if ($keys || $filters) {
-    // Log the search keys:
-    $log = $keys;
-    if ($filters) {
-      $log .= 'filters='. $filters;
-    }  
-    watchdog('search', '%keys (@type).', array('%keys' => $log, '@type' => t('Search')), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys));

-    // Collect the search results:
-    $results = search_data($keys, $type);
+  // Log the search keys:
+  $log = $keys;
+  if ($filters) {
+    $log .= 'filters='. $filters;
+  }
+  watchdog('search', '%keys (@type).', array('%keys' => $log, '@type' => t('Search')), WATCHDOG_NOTICE, l(t('results'), 'search/'. $type .'/'. $keys));

-    if ($results) {
-      $results = theme('box', t('Search results'), $results);
-    }  
-    else {
-      $results = theme('box', t('Your search yielded no results'), variable_get('apachesolr_search_noresults', apachesolr_search_noresults()));
-    }  
+  // Collect the search results:
+  $results = search_data($keys, $type);
+  
+  if ($results) {
+    $results = theme('box', t('Search results'), $results);
+  }  
+  else {
+    $results = theme('box', t('Your search yielded no results'), variable_get('apachesolr_search_noresults', apachesolr_search_noresults()));
   }  
   if (empty($form)) {
     // The form may be altered based on the query that was run.
@@ -998,9 +996,6 @@ 
     $get['retain-filters'] = '1';
   }  
   $form_state['redirect'] = array($base . $keys, $get);
-  if ($keys == '' && !$queryvalues) {
-    form_set_error('keys', t('Please enter some keywords.'));
-  }  
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.