? 358166_39.patch
? 358166_39_1.patch
? 358166_41.patch
? SolrPhpClient
? tmp.patch
? wildcard_search.patch
Index: Solr_Base_Query.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/Solr_Base_Query.php,v
retrieving revision 1.1.4.24
diff -u -p -r1.1.4.24 Solr_Base_Query.php
--- Solr_Base_Query.php	3 Apr 2009 14:37:32 -0000	1.1.4.24
+++ Solr_Base_Query.php	3 Apr 2009 21:52:22 -0000
@@ -225,7 +225,13 @@ class Solr_Base_Query {
    * omitting any field:value portions.
    */
   public function get_query_basic() {
-    return $this->rebuild_query();
+    $basic = $this->rebuild_query();
+    if (!isset($basic)) {
+      return variable_get('apachesolr_wildcard', '*');
+    }
+    else {
+      return $basic;
+    }
   }
 
   /**
Index: apachesolr.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.admin.inc,v
retrieving revision 1.1.2.13
diff -u -p -r1.1.2.13 apachesolr.admin.inc
--- apachesolr.admin.inc	30 Mar 2009 22:50:49 -0000	1.1.2.13
+++ apachesolr.admin.inc	3 Apr 2009 21:52:23 -0000
@@ -66,6 +66,12 @@ function apachesolr_settings() {
     '#default_value' => variable_get('apachesolr_set_nodeapi_messages', 1),
     '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
   );
+  $form['apachesolr_wildcard'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Solr wildcard'),
+    '#default_value' => variable_get('apachesolr_wildcard', '*'),
+    '#description' => t('Wildcard to show all results from the solr index.'),
+  );
   return system_settings_form($form);
 }
 
@@ -188,6 +194,24 @@ function apachesolr_enabled_facets_form_
   $enabled = array();
   foreach ($form_state['values']['apachesolr_enabled_facets'] as $module => $facets) {
     $enabled[$module] = array_filter($facets);
+    
+    /**
+     * Set taxonomy module to be apachesolr_search for vocabularies from enabled facets
+     * This will get term paths from apachesolr_search_term_path() instead of taxonomy.
+     */
+    if ($module == "apachesolr_search") {
+      foreach ($facets as $delta => $selected) {
+        if (substr($delta, 0, 7) == "im_vid_") {
+          $vid = substr($delta, 7);
+          if ($selected) {
+            $handler = $module;
+          } else {
+            $handler = "taxonomy";
+          }
+          db_query("UPDATE {vocabulary} SET module = '%s' WHERE vid = %d", $handler, $vid);
+        }
+      }
+    }
   }
   variable_set('apachesolr_enabled_facets', $enabled);
   drupal_set_message($form_state['values']['submit_message'], 'warning');
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.123
diff -u -p -r1.1.2.12.2.123 apachesolr.module
--- apachesolr.module	3 Apr 2009 14:37:32 -0000	1.1.2.12.2.123
+++ apachesolr.module	3 Apr 2009 21:52:23 -0000
@@ -695,7 +695,7 @@ function apachesolr_block($op = 'list', 
             }
 
             $sort_links = array();
-            $path = 'search/' . arg(1) . '/' . $query->get_query_basic();
+            $path = apachesolr_get_path();
             $new_query = clone $query;
             foreach ($sorts as $type => $sort) {
               $new_sort = isset($solrsorts[$type]) ? $solrsorts[$type] == 'asc' ? 'desc' : 'asc' : $sort['default'];
@@ -750,14 +750,13 @@ function apachesolr_facet_block($respons
       if ($active = $query->has_field($facet_field, $facet)) {
         $contains_active = TRUE;
         $new_query->remove_field($facet_field, $facet);
-        // TODO: don't assume 'search' - find the real path.
-        $path = 'search/'. arg(1) .'/'. $new_query->get_query_basic();
+        $path = apachesolr_get_path();
         $querystring = $new_query->get_url_querystring();
         $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
       }
       else {
         $new_query->add_field($facet_field, $facet);
-        $path = 'search/'. arg(1) .'/'. $new_query->get_query_basic();
+        $path = apachesolr_get_path();
         $querystring = $new_query->get_url_querystring();
       }
       $countsort = $count == 0 ? '' : 1 / $count;
@@ -824,7 +823,7 @@ function apachesolr_date_facet_block($re
       }
       $new_query = clone $query;
       $new_query->add_field($facet_field, "[$facet TO {$range_end[$facet]}]");
-      $path = 'search/'. arg(1) .'/'. $new_query->get_query_basic();
+      $path = apachesolr_get_path();
       $querystring = $new_query->get_url_querystring();
 
       $countsort = $count == 0 ? '' : 1 / $count;
@@ -1174,6 +1173,21 @@ function apachesolr_current_query($keys 
   if (empty($keys)) {
     $keys = search_get_keys();
   }
+  /**
+   * This allows the user to issue filters within keyword searches by placing them in brackets
+   * Examples: 
+   *  "bike [filters=tid:1]" would return items matching "bike" filtered by term ID 1
+   *  "* [filters=tid:1]" would return all items that have term ID 1
+   */
+  if (preg_match('/.*\[filters=([^\]]+)/', $keys, $matches)) {
+    $filters = $matches[1];
+    // Remove [filter=...] from $keys so Solr doesn't try to search for it as keywords
+    $keys = preg_replace('/ *\[filters=.*?\] */', '', $keys);
+  }
+  // when wildcard is used, use empty $keys
+  if ($keys == variable_get('apachesolr_wildcard', '*')) {
+    $keys = '';
+  }
   if (empty($filters) && !empty($_GET['filters'])) {
     $filters = $_GET['filters'];
   }
@@ -1258,6 +1272,21 @@ function apachesolr_cck_fields() {
 }
 
 /**
+ * Return path
+ */
+function apachesolr_get_path() {
+  $query = apachesolr_current_query();
+  if ($query->get_query_basic() == '') {
+    // TODO: don't assume 'search' - find the real path.
+    $path = 'search/' . arg(1) . '/' . variable_get('apachesolr_wildcard', '*') . $query->get_query_basic();
+  }
+  else {
+    $path = 'search/' . arg(1) . '/' . $query->get_query_basic();
+  }
+  return $path;
+}
+
+/**
  * Implementation of hook_theme().
  */
 function apachesolr_theme() {
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.80
diff -u -p -r1.1.2.6.2.80 apachesolr_search.module
--- apachesolr_search.module	3 Apr 2009 14:37:32 -0000	1.1.2.6.2.80
+++ apachesolr_search.module	3 Apr 2009 21:52:23 -0000
@@ -472,13 +472,13 @@ function apachesolr_search_block($op = '
               if ($active = $query->has_field('tid', $tid)) {
                 $contains_active = TRUE;
                 $new_query->remove_field('tid', $term->tid);
-                $path = 'search/' . arg(1) . '/' . $new_query->get_query_basic();
+                $path = apachesolr_get_path();
                 $querystring = $new_query->get_url_querystring();
                 $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
               }
               else {
                 $new_query->add_field('tid', $term->tid);
-                $path = 'search/' . arg(1) . '/' . $new_query->get_query_basic();
+                $path = apachesolr_get_path();
                 $querystring = $new_query->get_url_querystring();
               }
               $countsort = $count == 0 ? '' : 1 / $count;
@@ -508,7 +508,7 @@ function apachesolr_search_block($op = '
           case 'currentsearch':
             $fields = $query->get_fields();
             $search_keys = $query->get_query_basic();
-            $path = 'search/' . arg(1) . '/' . $search_keys;
+            $path = apachesolr_get_path();
             $options = array();
             if (!$fields) {
               $options['attributes']['class'] = 'active';
@@ -518,7 +518,7 @@ function apachesolr_search_block($op = '
               if ($field['#name']) {
                 $new_query = clone $query;
                 $new_query->remove_field($field['#name'], $field['#value']);
-                $path = 'search/'. arg(1) .'/'. $new_query->get_query_basic();
+                $path = apachesolr_get_path();
                 $querystring = $new_query->get_url_querystring();
                 $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
                 if (! $fielddisplay = theme("apachesolr_breadcrumb_". $field['#name'], $field['#value'])) {
@@ -597,6 +597,13 @@ function apachesolr_search_get_type($fac
  */
 function apachesolr_search_form_search_form_alter(&$form, $form_state) {
 
+  // Remove filter commands from keywords, like "[filter=tid:12345]"
+  if ($form['module']['#value'] == 'apachesolr_search') {
+    $keys = preg_replace('/ *\[filters=.*?\] */', '', $form['basic']['inline']['keys']['#default_value']);
+    $form['basic']['inline']['keys']['#default_value'] = $keys;
+  }
+  
+  // Suggestions
   if (($form['module']['#value'] == 'apachesolr_search') && variable_get('apachesolr_search_spellcheck', FALSE) && apachesolr_has_searched() && ($response = apachesolr_static_response_cache())) {
     //Get spellchecker suggestions into an array.
     $suggestions = get_object_vars($response->spellcheck->suggestions);
@@ -748,3 +755,24 @@ function theme_apachesolr_currentsearch(
 function theme_apachesolr_search_snippets($doc, $snippets) {
   return implode(' ... ', $snippets);
 }
+
+
+/**
+ * Implementation of taxonomy_term_path.
+ *
+ * This rewrites taxonom term links for filters enabled in admin/settings/apachesolr/enabled-filters
+ */
+function apachesolr_search_term_path($term) {
+  static $vids_to_override;
+  
+  if (!isset($vids_to_override)) {
+    $vids_to_override = apachesolr_get_enabled_facets('apachesolr_search');
+  }
+  $vocabulary_facet_name = 'im_vid_' . $term->vid;
+  if (in_array($vocabulary_facet_name, $vids_to_override)) {
+    // apachesolr_current_query() accepts filters on keyword searches using syntax [filters=tid:XX]
+    return 'search/apachesolr_search/*+[filters=tid:' . $term->tid . ']';
+  } else {
+    return 'taxonomy/term/' . $term->tid;
+  }
+}
