? .svn
? SolrPhpClient/.svn
? SolrPhpClient/Apache/.svn
? SolrPhpClient/Apache/Solr/.svn
? SolrPhpClient/Apache/Solr/Service/.svn
? blocks/.svn
? contrib/.svn
? contrib/apachesolr_attachments/.svn
? contrib/apachesolr_image/.svn
? contrib/apachesolr_mlt/.svn
? contrib/apachesolr_multisitesearch/.svn
? contrib/apachesolr_nodeaccess/.svn
? contrib/apachesolr_nodeaccess/tests/.svn
? tests/.svn
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.89
diff -u -p -r1.1.2.12.2.89 apachesolr.module
--- apachesolr.module	19 Jan 2009 15:16:37 -0000	1.1.2.12.2.89
+++ apachesolr.module	22 Jan 2009 05:10:37 -0000
@@ -26,6 +26,15 @@ function apachesolr_menu() {
     'access arguments'   => array('administer site configuration'),
     'type'               => MENU_DEFAULT_LOCAL_TASK,
   );
+  $items['admin/settings/apachesolr/active_facets'] = array(
+    'title' => 'Active facets',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('apachesolr_active_facets_form'),
+    'weight' => -9,
+    'access callback' => 'user_access',
+    'access arguments' => array('administer site configuration'),
+    'type' => MENU_LOCAL_TASK,
+  );
   $items['admin/settings/apachesolr/index'] = array(
     'title'              => 'Search index',
     'page callback'      => 'apachesolr_index_page',
@@ -204,6 +213,89 @@ function apachesolr_index_page() {
 }
 
 /**
+ * Indicates what order the specified facets should be listed in.  This function is used in a usort
+ * invocation.
+ * @param $a
+ *   The first facet.
+ * @param $b
+ *   The second facet.
+ * @return
+ *   A signed integer that indicates which of the specified facets should come first.
+ */
+function _apachesolr_sort_facets($a, $b) {
+  return strcasecmp($a['info'], $b['info']);
+}
+
+/**
+ * This is the submit handler for the active facets form.  The form values are simply stored
+ * in the variable table with the name 'apachesolr_enabled_facets'.
+ *
+ * @param $form_id
+ *   The form id.
+ * @param $form_values
+ *   The form values.
+ */
+function apachesolr_active_facets_form_submit($form_id, $form_values) {
+  variable_set('apachesolr_enabled_facets', $form_values['values']['apachesolr_enabled_facets']);
+}
+
+function apachesolr_get_enabled_facets_array() {
+  $enabled_facets = variable_get('apachesolr_enabled_facets', array());
+  $result = array();
+  foreach ($enabled_facets as $module => $facets) {
+    $result[$module] = array();
+    foreach ($facets['facets'] as $delta => $value) {
+      if (isset($value)) {
+        $result[$module][] = $value;
+      }
+    }
+  }
+  return $result;
+}
+
+/**
+ * Creates the form that allows the user to select which facets will be active.  Only active facets
+ * are sent to solr.  Fewer active facets can reduce the load on the search server.
+ * @return
+ *   The form.
+ */
+function apachesolr_active_facets_form() {
+  $facets = array();
+  foreach (module_implements('apachesolr_facets') as $module) {
+    $facets[$module] = module_invoke($module, 'apachesolr_facets');
+    usort($facets[$module], '_apachesolr_sort_facets');
+  }
+
+  $enabled_facets = apachesolr_get_enabled_facets_array();
+  $form = array();
+  foreach($facets as $module_name => $module_facets) {
+    $options = array();
+    foreach($module_facets as $index => $facet) {
+      $options[$facet['delta']] = $facet['info'];
+    }
+    $form['apachesolr_enabled_facets'][$module_name] = array(
+      '#type' => 'fieldset',
+      '#title' => $module_name,
+      '#collapsible' => TRUE,
+      '#collapsed' => FALSE,
+    );
+    $form['apachesolr_enabled_facets'][$module_name]['facets'] = array(
+      '#type' => 'checkboxes',
+      '#options' => $options,
+      '#default_value' => $enabled_facets[$module_name],
+    );
+  }
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+  );
+  $form['#redirect'] = 'admin/build/block';
+  $form['#tree'] = TRUE;
+  return $form;
+}
+
+/**
  * Create a form for deleting the contents of the Solr index.
  */
 function apachesolr_delete_index_form() {
@@ -683,7 +775,33 @@ function apachesolr_nodeapi(&$node, $op,
 }
 
 function apachesolr_apachesolr_facets() {
-  return array('type');
+  $facets = array();
+  $facets['type'] = array('info' => t('ApacheSolr Core: Filter by type'),
+    'cache' => BLOCK_CACHE_PER_PAGE,
+    'delta' => 'type');
+  return $facets;
+}
+
+/**
+ * Return the enabled facets from the specified block array.
+ *
+ * @param $module
+ *   The module.
+ * @param $facets
+ *   The complete set of facets exposed by a module.
+ * @return
+ *   An array consisting only of the facet info in the specified facets array that have been enabled
+ *   for the specified module.
+ */
+function apachesolr_get_enabled_facets($module, $facets) {
+  $enabled = variable_get('apachesolr_enabled_facets', array());
+  $result = array($module => array());
+  foreach ($facets as $delta => $info) {
+    if ($enabled[$module]['facets'][$delta] === $delta) {
+      $result[$module][$delta] = $facets[$delta];
+    }
+  }
+  return $result;
 }
 
 /**
@@ -692,10 +810,13 @@ function apachesolr_apachesolr_facets() 
 function apachesolr_block($op = 'list', $delta = 0, $edit = array()) {
   switch ($op) {
     case 'list':
-      // Sorting block
-      $blocks['sort'] = array('info' => t('ApacheSolr Core: Sorting'), 'cache' => BLOCK_CACHE_PER_PAGE);
-      $blocks['type'] = array('info' => t('ApacheSolr Core: Filter by type'), 'cache' => BLOCK_CACHE_PER_PAGE);
-      return $blocks;
+      $module_name = 'apachesolr';
+      $facets = apachesolr_get_enabled_facets($module_name, apachesolr_apachesolr_facets());
+      // Add the blocks
+      $facets[$module_name]['sort'] = array('info' => t('ApacheSolr Core: Sorting'),
+        'cache' => BLOCK_CACHE_PER_PAGE,
+        'delta' => 'sort', 'module' => 'apachesolr');
+      return $facets[$module_name];
 
     case 'view':
       if (apachesolr_has_searched()) {
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.59
diff -u -p -r1.1.2.6.2.59 apachesolr_search.module
--- apachesolr_search.module	16 Jan 2009 20:03:40 -0000	1.1.2.6.2.59
+++ apachesolr_search.module	22 Jan 2009 05:10:37 -0000
@@ -110,15 +110,10 @@ function apachesolr_search_search($op = 
           $params['spellcheck'] = 'true';
         }
 
-        // TODO: This adds all of the possible facets to the query. Not all
-        // of these facets have their blocks enabled, so the list should be
-        // filtered by the actual enabled blocks, otherwise we're putting
-        // unneeded strain on the Solr server.
-        foreach (module_implements('apachesolr_facets') as $module) {
-          $function = $module .'_apachesolr_facets';
-          $result = call_user_func_array($function, array());
-          if (isset($result) && is_array($result)) {
-            foreach ($result as $facet) {
+        $enabled_facets = variable_get('apachesolr_enabled_facets', array());
+        foreach ($enabled_facets as $module => $facets) {
+          foreach($facets['facets'] as $facet => $facet_value) {
+            if (!empty($facet_value)) {
               $params['facet.field'][] = $facet;
             }
           }
@@ -248,7 +243,33 @@ function apachesolr_search_search($op = 
 }
 
 function apachesolr_search_apachesolr_facets() {
-  return array_keys(apachesolr_search_block());
+  $facets = array();
+  $facets['uid'] = array('info' => t('ApacheSolr Search: Filter by author'),
+    'delta' => 'uid', 'module' => 'apachesolr_search');
+  $facets['language'] = array('info' => t('ApacheSolr Search: Filter by language'),
+    'delta' => 'language', 'module' => 'apachesolr_search');
+  // Get taxonomy vocabulary facets.
+  if (module_exists('taxonomy')) {
+    $vocabs = taxonomy_get_vocabularies();
+    foreach ($vocabs as $vid => $vocab) {
+      $delta = 'imfield_vid_' .$vid;
+      $facets[$delta] = array('info' => t('ApacheSolr Search: Filter by @name', array('@name' => $vocab->name)), 'cache' => BLOCK_CACHE_PER_PAGE,
+        'delta' => $delta, 'module' => 'apachesolr_search');
+    }
+  }
+
+  // Get CCK field facets.
+  $fields = apachesolr_cck_fields();
+  if ($fields) {
+    foreach ($fields as $name => $field) {
+      // $delta can only be 32 chars, and the CCK field name may be this
+      // long also, so we cannot add anything to it.
+      $delta = $field['field_name'];
+      $facets[$delta] = array('info' => t('ApacheSolr Search: Filter by @field', array('@field' => $field['label'])), 'cache' => BLOCK_CACHE_PER_PAGE,
+        'delta' => $delta, 'module' => 'apachesolr_search');
+    }
+  }
+  return $facets;
 }
 
 /**
@@ -258,27 +279,14 @@ function apachesolr_search_block($op = '
 
   switch ($op) {
     case 'list':
-      $blocks['uid'] = array('info' => t('ApacheSolr Search: Filter by author'));
-      $blocks['currentsearch'] = array('info' => t('ApacheSolr Search: Current search'), 'cache' => BLOCK_CACHE_PER_PAGE);
-      $blocks['language'] = array('info' => t('ApacheSolr Search: Filter by language'));
-      // Get taxonomy vocabulary facets.
-      if (module_exists('taxonomy')) {
-        $vocabs = taxonomy_get_vocabularies();
-        foreach ($vocabs as $vid => $vocab) {
-          $blocks['imfield_vid_' . $vid] = array('info' => t('ApacheSolr Search: Filter by @name', array('@name' => $vocab->name)), 'cache' => BLOCK_CACHE_PER_PAGE);
-        }
-      }
-
-      // Get CCK field facets.
-      if ($fields = apachesolr_cck_fields()) {
-        foreach ($fields as $name => $field) {
-          // $delta can only be 32 chars, and the CCK field name may be this
-          // long also, so we cannot add anything to it.
-          $blocks[$field['field_name']] = array('info' => t('ApacheSolr Search: Filter by @field', array('@field' => $field['label'])), 'cache' => BLOCK_CACHE_PER_PAGE);
-        }
-      }
-
-      return $blocks;
+      $module_name = 'apachesolr_search';
+      $facets = array();
+      $facets = apachesolr_get_enabled_facets($module_name, apachesolr_search_apachesolr_facets());
+      // Add the blocks
+      $facets[$module_name]['currentsearch'] = array('info' => t('ApacheSolr Search: Current search'),
+        'cache' => BLOCK_CACHE_PER_PAGE,
+        'delta' => 'currentsearch');
+      return $facets[$module_name];
 
     case 'view':
       if (apachesolr_has_searched()) {
