? apachesolr_custom_field_mappings.patch
? p.p
? ../apachesolr_new/.DS_Store
? ../apachesolr_new/SolrPhpClient
Index: ../apachesolr_new/apachesolr.index.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/Attic/apachesolr.index.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 apachesolr.index.inc
--- ../apachesolr_new/apachesolr.index.inc	16 Apr 2009 13:33:16 -0000	1.1.2.1
+++ ../apachesolr_new/apachesolr.index.inc	24 Apr 2009 20:26:05 -0000
@@ -108,27 +108,45 @@ function apachesolr_node_to_document($ni
       }
     }
 
-    // Get CCK fields list
-    $cck_fields = apachesolr_cck_fields();
-    foreach ($cck_fields as $key => $cck_info) {
+    //Get CCK fields list
+    $fields = apachesolr_cck_fields();
+    $fields_custom = apachesolr_custom_fields();
+    $fields = array_merge($fields, $fields_custom);
+    foreach ($fields as $key => $field_info) {
       if (isset($node->$key)) {
         // Got a CCK field. See if it is to be indexed.
-        $function = $cck_info['callback'];
-        if ($cck_info['callback'] && function_exists($function)) {
+        $function = $field_info['callback'];
+        if ($field_info['callback'] && function_exists($function)) {
           $field = call_user_func_array($function, array($node, $key));
         }
         else {
           $field = $node->$key;
         }
-        $index_key = apachesolr_index_key($cck_info);
+        $index_key = apachesolr_index_key($field_info);
+        //make non-cck fields look like cck fields
+        if (array_key_exists($key, $fields_custom)) {
+          if (!is_array($field)) {
+            $field_val = $field;
+            $field = array();
+            $field[]['safe'] = $field_val;
+          }
+          else {
+            $new_field = array();
+            foreach ($field as $custom_val) {
+              $new_field[]['safe'] = $custom_val;
+            }
+            $field = $new_field;
+          }
+        }
+        $solr_field = $index_key . $field_info['field_name'];
         foreach ($field as $value) {
           // Don't index NULLs or empty strings
           if (isset($value['safe']) && strlen($value['safe'])) {
-            if ($cck_info['multiple']) {
-              $document->setMultiValue($index_key, apachesolr_clean_text($value['safe']));
+            if ($field_info['multiple']) {
+              $document->setMultiValue($solr_field, apachesolr_clean_text($value['safe']));
             }
             else {
-              $document->$index_key = apachesolr_clean_text($value['safe']);
+              $document->$solr_field = apachesolr_clean_text($value['safe']);
             }
           }
         }
Index: ../apachesolr_new/apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.133
diff -u -p -r1.1.2.12.2.133 apachesolr.module
--- ../apachesolr_new/apachesolr.module	24 Apr 2009 18:03:24 -0000	1.1.2.12.2.133
+++ ../apachesolr_new/apachesolr.module	24 Apr 2009 20:26:05 -0000
@@ -1030,7 +1030,7 @@ function apachesolr_cck_fields() {
       $result = db_query("SELECT  i.field_name, f.multiple, f.type AS field_type, i.widget_type, i.label FROM {content_node_field_instance} i INNER JOIN {content_node_field} f ON i.field_name = f.field_name;");
       while ($row = db_fetch_object($result)) {
         // Only deal with fields that have options widgets (facets don't make sense otherwise), or fields that have specific mappings.
-        if (isset($mappings[$row->field_type]) && !empty($mappings[$row->field_type]['widget_types'][$row->widget_type])) {
+        if ((isset($mappings[$row->field_type]) && !empty($mappings[$row->field_type]['widget_types'][$row->widget_type])) || $mappings[$row->field_name]['facet'] == TRUE) {
           $row->index_type = $mappings[$row->field_type]['index_type'];
           $row->callback = $mappings[$row->field_type]['callback'];
           $row->multiple = (bool) $row->multiple;
@@ -1044,6 +1044,18 @@ function apachesolr_cck_fields() {
 }
 
 /**
+ * Invokes hook_apachesolr_field_mappings to find out how to handle custom fields.
+ */
+function apachesolr_custom_fields() {
+  static $custom_fields;
+  if (is_null($custom_fields)) {
+    $custom_fields = array();
+    $custom_fields = module_invoke_all('apachesolr_custom_field_mappings');
+  }
+  return $custom_fields;
+}
+
+/**
  * Implementation of hook_theme().
  */
 function apachesolr_theme() {
Index: ../apachesolr_new/apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.87
diff -u -p -r1.1.2.6.2.87 apachesolr_search.module
--- ../apachesolr_new/apachesolr_search.module	24 Apr 2009 18:03:24 -0000	1.1.2.6.2.87
+++ ../apachesolr_new/apachesolr_search.module	24 Apr 2009 20:26:05 -0000
@@ -390,13 +390,15 @@ function apachesolr_search_apachesolr_fa
 
   // Get CCK field facets.
   $fields = apachesolr_cck_fields();
+  //Get custom facets
+  $fields = apachesolr_custom_fields() + $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.
       $facets[$field['field_name']] = array(
         'info' => t('Apache Solr Search: Filter by @field', array('@field' => $field['label'])),
-        'facet_field' => apachesolr_index_key($field),
+        'facet_field' => apachesolr_index_key($field) . $field['field_name'],
       );
     }
   }
@@ -529,11 +531,13 @@ function apachesolr_search_block($op = '
             return apachesolr_date_facet_block($response, $query, 'apachesolr_search', $delta, $delta, t('Filter by post date'));
 
           default:
-           if ($fields = apachesolr_cck_fields()) {
+          $fields = apachesolr_cck_fields();          
+          $fields = apachesolr_custom_fields() + $fields;
+           if ($fields) {
             foreach ($fields as $name => $field) {
               if ($field['field_name'] == $delta) {
                 $index_key = apachesolr_index_key($field);
-                return apachesolr_facet_block($response, $query, 'apachesolr_search', $delta, $index_key, t('Filter by @field', array('@field' => $field['label'])));
+                return apachesolr_facet_block($response, $query, 'apachesolr_search', $delta, $index_key . $delta, t('Filter by @field', array('@field' => $field['label'])));
               }
             }
           }
Index: ../apachesolr_new/apachesolr.index.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/Attic/apachesolr.index.inc,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 apachesolr.index.inc
--- ../apachesolr_new/apachesolr.index.inc	16 Apr 2009 13:33:16 -0000	1.1.2.1
+++ ../apachesolr_new/apachesolr.index.inc	24 Apr 2009 20:26:05 -0000
@@ -108,27 +108,45 @@ function apachesolr_node_to_document($ni
       }
     }
 
-    // Get CCK fields list
-    $cck_fields = apachesolr_cck_fields();
-    foreach ($cck_fields as $key => $cck_info) {
+    //Get CCK fields list
+    $fields = apachesolr_cck_fields();
+    $fields_custom = apachesolr_custom_fields();
+    $fields = array_merge($fields, $fields_custom);
+    foreach ($fields as $key => $field_info) {
       if (isset($node->$key)) {
         // Got a CCK field. See if it is to be indexed.
-        $function = $cck_info['callback'];
-        if ($cck_info['callback'] && function_exists($function)) {
+        $function = $field_info['callback'];
+        if ($field_info['callback'] && function_exists($function)) {
           $field = call_user_func_array($function, array($node, $key));
         }
         else {
           $field = $node->$key;
         }
-        $index_key = apachesolr_index_key($cck_info);
+        $index_key = apachesolr_index_key($field_info);
+        //make non-cck fields look like cck fields
+        if (array_key_exists($key, $fields_custom)) {
+          if (!is_array($field)) {
+            $field_val = $field;
+            $field = array();
+            $field[]['safe'] = $field_val;
+          }
+          else {
+            $new_field = array();
+            foreach ($field as $custom_val) {
+              $new_field[]['safe'] = $custom_val;
+            }
+            $field = $new_field;
+          }
+        }
+        $solr_field = $index_key . $field_info['field_name'];
         foreach ($field as $value) {
           // Don't index NULLs or empty strings
           if (isset($value['safe']) && strlen($value['safe'])) {
-            if ($cck_info['multiple']) {
-              $document->setMultiValue($index_key, apachesolr_clean_text($value['safe']));
+            if ($field_info['multiple']) {
+              $document->setMultiValue($solr_field, apachesolr_clean_text($value['safe']));
             }
             else {
-              $document->$index_key = apachesolr_clean_text($value['safe']);
+              $document->$solr_field = apachesolr_clean_text($value['safe']);
             }
           }
         }
Index: ../apachesolr_new/apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.133
diff -u -p -r1.1.2.12.2.133 apachesolr.module
--- ../apachesolr_new/apachesolr.module	24 Apr 2009 18:03:24 -0000	1.1.2.12.2.133
+++ ../apachesolr_new/apachesolr.module	24 Apr 2009 20:26:05 -0000
@@ -1030,7 +1030,7 @@ function apachesolr_cck_fields() {
       $result = db_query("SELECT  i.field_name, f.multiple, f.type AS field_type, i.widget_type, i.label FROM {content_node_field_instance} i INNER JOIN {content_node_field} f ON i.field_name = f.field_name;");
       while ($row = db_fetch_object($result)) {
         // Only deal with fields that have options widgets (facets don't make sense otherwise), or fields that have specific mappings.
-        if (isset($mappings[$row->field_type]) && !empty($mappings[$row->field_type]['widget_types'][$row->widget_type])) {
+        if ((isset($mappings[$row->field_type]) && !empty($mappings[$row->field_type]['widget_types'][$row->widget_type])) || $mappings[$row->field_name]['facet'] == TRUE) {
           $row->index_type = $mappings[$row->field_type]['index_type'];
           $row->callback = $mappings[$row->field_type]['callback'];
           $row->multiple = (bool) $row->multiple;
@@ -1044,6 +1044,18 @@ function apachesolr_cck_fields() {
 }
 
 /**
+ * Invokes hook_apachesolr_field_mappings to find out how to handle custom fields.
+ */
+function apachesolr_custom_fields() {
+  static $custom_fields;
+  if (is_null($custom_fields)) {
+    $custom_fields = array();
+    $custom_fields = module_invoke_all('apachesolr_custom_field_mappings');
+  }
+  return $custom_fields;
+}
+
+/**
  * Implementation of hook_theme().
  */
 function apachesolr_theme() {
Index: ../apachesolr_new/apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.87
diff -u -p -r1.1.2.6.2.87 apachesolr_search.module
--- ../apachesolr_new/apachesolr_search.module	24 Apr 2009 18:03:24 -0000	1.1.2.6.2.87
+++ ../apachesolr_new/apachesolr_search.module	24 Apr 2009 20:26:05 -0000
@@ -390,13 +390,15 @@ function apachesolr_search_apachesolr_fa
 
   // Get CCK field facets.
   $fields = apachesolr_cck_fields();
+  //Get custom facets
+  $fields = apachesolr_custom_fields() + $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.
       $facets[$field['field_name']] = array(
         'info' => t('Apache Solr Search: Filter by @field', array('@field' => $field['label'])),
-        'facet_field' => apachesolr_index_key($field),
+        'facet_field' => apachesolr_index_key($field) . $field['field_name'],
       );
     }
   }
@@ -529,11 +531,13 @@ function apachesolr_search_block($op = '
             return apachesolr_date_facet_block($response, $query, 'apachesolr_search', $delta, $delta, t('Filter by post date'));
 
           default:
-           if ($fields = apachesolr_cck_fields()) {
+          $fields = apachesolr_cck_fields();          
+          $fields = apachesolr_custom_fields() + $fields;
+           if ($fields) {
             foreach ($fields as $name => $field) {
               if ($field['field_name'] == $delta) {
                 $index_key = apachesolr_index_key($field);
-                return apachesolr_facet_block($response, $query, 'apachesolr_search', $delta, $index_key, t('Filter by @field', array('@field' => $field['label'])));
+                return apachesolr_facet_block($response, $query, 'apachesolr_search', $delta, $index_key . $delta, t('Filter by @field', array('@field' => $field['label'])));
               }
             }
           }
