Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.78
diff -u -r1.1.2.6.2.78 apachesolr_search.module
--- apachesolr_search.module	23 Feb 2009 03:40:37 -0000	1.1.2.6.2.78
+++ apachesolr_search.module	27 Feb 2009 17:00:06 -0000
@@ -368,6 +368,13 @@
         $initial_limits = variable_get('apachesolr_facet_query_initial_limits', array());
         $limit_default = variable_get('apachesolr_facet_query_initial_limit_default', 10);
 
+        // Get the path to this node for appending a new query
+        $path_base = apachesolr_get_path_base($query->get_query_basic());
+        if (empty($path_base)) {
+          // Panic and hastily leave the method
+          return;
+        }
+
         // Handle taxonomy vocabulary facets
         if ((strpos($delta, 'im_vid_') === 0) && module_exists('taxonomy')) {
 
@@ -383,13 +390,13 @@
               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 = $path_base . $new_query->get_query_basic();
                 $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 = $path_base . $new_query->get_query_basic();
                 $querystring = $new_query->get_url_querystring();
               }
               $countsort = $count == 0 ? '' : 1 / $count;
@@ -419,7 +426,7 @@
           case 'currentsearch':
             $fields = $query->get_fields();
             $search_keys = $query->get_query_basic();
-            $path = 'search/' . arg(1) . '/' . $search_keys;
+            $path = $path_base . $search_keys;
             $options = array();
             if (!$fields) {
               $options['attributes']['class'] = 'active';
@@ -429,7 +436,7 @@
               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 = $path_base . $new_query->get_query_basic();
                 $querystring = $new_query->get_url_querystring();
                 $unclick_link = theme('apachesolr_unclick_link', $path, $querystring);
                 if (! $fielddisplay = theme("apachesolr_breadcrumb_". $field['#name'], $field['#value'])) {
@@ -517,12 +524,19 @@
       }
       $new_keywords = strtr($query->get_query_basic(), $replacements);
 
+      // Get the path to this node for appending a new query
+      $path_base = apachesolr_get_path_base($query->get_query_basic());
+      if (empty($path_base)) {
+        // Panic and hastily leave the method
+        return;
+      }
+
       $form['basic']['suggestion'] = array(
         '#prefix' => '<div class="spelling-suggestions">',
         '#suffix' => '</div>',
         '#type' => 'item',
         '#title' => t('Did you mean'),
-        '#value' => l($new_keywords, 'search/'. arg(1) .'/'. $new_keywords),
+        '#value' => l($new_keywords, $path_base . $new_keywords),
       );
     }
   }
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.112
diff -u -r1.1.2.12.2.112 apachesolr.module
--- apachesolr.module	20 Feb 2009 19:31:16 -0000	1.1.2.12.2.112
+++ apachesolr.module	27 Feb 2009 17:00:06 -0000
@@ -631,7 +631,15 @@
             }
 
             $sort_links = array();
-            $path = 'search/' . arg(1) . '/' . $query->get_query_basic();
+
+            // Get the path to this node for appending a new query
+            $path_base = apachesolr_get_path_base($query->get_query_basic());
+            if (empty($path_base)) {
+              // Panic and hastily leave the method
+              return;
+            }
+            
+            $path = $path_base . $query->get_query_basic();
             $new_query = clone $query;
             foreach ($sorts as $type => $sort) {
               $new_sort = isset($solrsorts[$type]) ? $solrsorts[$type] == 'asc' ? 'desc' : 'asc' : $sort['default'];
@@ -652,12 +660,35 @@
 }
 
 /**
+ * Helper function for computing the path base to which the query is appended.
+ */
+function apachesolr_get_path_base($keys) {
+  static $path_base = array();
+  if (empty($path_base[$keys])) {
+    $pos = strpos($_GET['q'], $keys);
+    if ($pos === FALSE) {
+      return FALSE;
+    }
+    $path_base[$keys] = substr($_GET['q'], 0, $pos);
+  }
+  return $path_base[$keys];
+}
+
+/**
  * Helper function for displaying a facet block.
  */
 function apachesolr_facet_block($response, $query, $module, $delta, $facet_field, $filter_by, $facet_callback = FALSE) {
   if (!empty($response->facet_counts->facet_fields->$facet_field)) {
     $contains_active = FALSE;
     $items = array();
+
+    // Get the path to this node for appending a new query
+    $path_base = apachesolr_get_path_base($query->get_query_basic());
+    if (empty($path_base)) {
+      // Panic and hastily leave the method
+      return;
+    }
+
     foreach ($response->facet_counts->facet_fields->$facet_field as $facet => $count) {
       // Solr sends this back if it's empty.
       if ($facet == '_empty_') {
@@ -675,14 +706,13 @@
       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 = $path_base . $new_query->get_query_basic();
         $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 = $path_base . $new_query->get_query_basic();
         $querystring = $new_query->get_url_querystring();
       }
       $countsort = $count == 0 ? '' : 1 / $count;
