? SolrPhpClient
Index: CHANGELOG.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/CHANGELOG.txt,v
retrieving revision 1.1.2.99.2.22
diff -u -p -r1.1.2.99.2.22 CHANGELOG.txt
--- CHANGELOG.txt	17 Aug 2009 17:33:53 -0000	1.1.2.99.2.22
+++ CHANGELOG.txt	17 Aug 2009 18:45:00 -0000
@@ -5,6 +5,7 @@ Apache Solr integration x.x-x.x, xxxx-xx
 
 Apache Solr integration 6.x-2.x, xxxx-xx-xx
 ------------------------------
+#551620 by robertDouglass Type dependent facet blocks.
 #549664 by Scott Reynolds Ignore node_access for Solr Views queries.
 #551582 by robertDouglass make CCK breadcrumbs, facets, and current search show the value, not the key.
 #551278 by robertDouglass CCK mappings don't respect shared fields
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.155.2.12
diff -u -p -r1.1.2.12.2.155.2.12 apachesolr.module
--- apachesolr.module	17 Aug 2009 17:28:14 -0000	1.1.2.12.2.155.2.12
+++ apachesolr.module	17 Aug 2009 18:45:00 -0000
@@ -653,6 +653,64 @@ function apachesolr_block($op = 'list', 
 }
 
 /**
+ * Implementation of hook_form_[form_id]_alter().
+ *
+ * Hide the core 'title' field in favor of our 'name' field.
+ *
+ * Add a checkbox to enable type-specific visibility.
+ */
+function apachesolr_form_block_admin_configure_alter(&$form, $form_state) {
+  // Hide the core title field.
+  if ($form['module']['#value'] == 'apachesolr' && $form['delta']['#value'] != 'sort') {
+    $form['block_settings']['title']['#access'] = FALSE;
+  }
+
+  // Add a type-specific visibility checkbox.
+  $module = $form['module']['#value'];
+  $delta = $form['delta']['#value'];
+  $enabled_facets = apachesolr_get_enabled_facets();
+
+  // If this block isn't enabled as a facet, get out of here.
+  if (!isset($enabled_facets[$module][$delta])) {
+    return;
+  }
+
+  $facet_info = module_invoke($module, 'apachesolr_facets');
+
+  // If this facet doesn't define any content type array, get out of here.
+  if (!isset($facet_info[$delta]['content types'])) {
+    return;
+  }
+
+  $settings = variable_get('apachesolr_type_filter', array());
+  // Set up some variables for the verbiage of the form element.
+  $count = count($facet_info[$delta]['content types']);
+  $types = format_plural($count, t('type'), t('types'));
+  $are = format_plural($count, t('is'), t('are'));
+  $content_types = implode(', ', $facet_info[$delta]['content types']) . '.';
+  $form['block_settings']['apachesolr_type_filter'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Show this block only when the type filter is selected for: %content_types',  array('%content_types' => $content_types)),
+    '#default_value' => isset($settings[$module][$delta]) ? $settings[$module][$delta] : FALSE,
+    '#description' => t('This filter is relevant only for specific content types. Check this to display the block only when the type filter has been selected for one of the relevant content types.'),
+    '#weight' => 11,
+  );
+  // Add a submit handler to save the value.
+  $form['#validate'][] = 'apachesolr_block_admin_configure_submit';
+}
+
+function apachesolr_block_admin_configure_submit($form, &$form_state) {
+  if (isset($form_state['values']['apachesolr_type_filter'])) {
+    $settings = variable_get('apachesolr_type_filter', array());
+    $module = $form_state['values']['module'];
+    $delta = $form_state['values']['delta'];
+    unset($settings[$module][$delta]);
+    $settings[$module][$delta] = $form_state['values']['apachesolr_type_filter'];
+    variable_set('apachesolr_type_filter', $settings);
+  }
+}
+
+/**
  * Helper function for displaying a facet block.
  */
 function apachesolr_facet_block($response, $query, $module, $delta, $facet_field, $filter_by, $facet_callback = FALSE) {
@@ -1388,17 +1446,6 @@ function apachesolr_form_block_admin_dis
 }
 
 /**
- * Implementation of hook_form_[form_id]_alter().
- *
- * Hide the core 'title' field in favor of our 'name' field..
- */
-function apachesolr_form_block_admin_configure_alter(&$form, $form_state) {
-  if ($form['module']['#value'] == 'apachesolr' && $form['delta']['#value'] != 'sort') {
-    $form['block_settings']['title']['#access'] = FALSE;
-  }
-}
-
-/**
  * Returns a list of blocks. Used by hook_block
  */
 function apachesolr_mlt_list_blocks() {
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.111.2.5
diff -u -p -r1.1.2.6.2.111.2.5 apachesolr_search.module
--- apachesolr_search.module	17 Aug 2009 17:28:15 -0000	1.1.2.6.2.111.2.5
+++ apachesolr_search.module	17 Aug 2009 18:45:00 -0000
@@ -575,6 +575,7 @@ function apachesolr_search_apachesolr_fa
     $facets['is_book_bid'] = array(
       'info' => t('Book: Filter by Book'),
       'facet_field' => 'is_book_bid',
+      'content types' => variable_get('book_allowed_types', array('book')),
     );
   }
 
@@ -587,6 +588,7 @@ function apachesolr_search_apachesolr_fa
       $facets[$delta] = array(
         'info' => t('Taxonomy vocabulary: Filter by taxonomy @name', array('@name' => $vocab->name)),
         'facet_field' => $delta,
+        'content types' => $vocab->nodes,
       );
     }
   }
@@ -600,6 +602,7 @@ function apachesolr_search_apachesolr_fa
       $facets[$field['field_name']] = array(
         'info' => t('CCK field: Filter by @field', array('@field' => $field['label'])),
         'facet_field' => apachesolr_index_key($field),
+        'content types' => $field['content types'],
       );
     }
   }
@@ -642,6 +645,27 @@ function apachesolr_search_block($op = '
           return;
         }
 
+        // This code makes a decision whether to show this block or not.
+        // If the block is configured to heed type hierarcy then it looks
+        // to see if a suitable type filter has been chosen. If not,
+        // the function returns.
+        $type_filters = variable_get('apachesolr_type_filter', array());
+        if (isset($type_filters['apachesolr_search'][$delta]) && $type_filters['apachesolr_search'][$delta] == TRUE) {
+          $facet_info = module_invoke('apachesolr_search', 'apachesolr_facets');
+          if (isset($facet_info[$delta]['content types'])) {
+            $has_filter = $query->get_filters($facet_info[$delta]['facet_field']);
+            $show = count($has_filter);
+            foreach ($facet_info[$delta]['content types'] as $content_type) {
+              if ($query->has_filter('type', $content_type)) {
+                $show = TRUE;
+              }
+            }
+            if (!$show) {
+              return;
+            }
+          }
+        }
+
         // Get information needed by the taxonomy blocks about limits.
         $initial_limits = variable_get('apachesolr_facet_query_initial_limits', array());
         $limit_default = variable_get('apachesolr_facet_query_initial_limit_default', 10);
