Hi,

The extrafields are not taken into index when they are defined using mapping options as the only fields allowed are the ones defined in the field_config tableb here is the current mapping indexing function

/**
 * Returns array containing information about node fields that should be indexed
 */
function apachesolr_entity_fields($entity_type = 'node') {
  $fields = &drupal_static(__FUNCTION__, array());

  if (!isset($fields[$entity_type])) {
    $fields[$entity_type] = array();

    $mappings = module_invoke_all('apachesolr_field_mappings');
    foreach (array_keys($mappings) as $key) {
      // Set all values with defaults.
      $defaults = array(
          'dependency plugins' => array('bundle', 'role'),
          'map callback' => FALSE,
          'name callback' => '',
          'hierarchy callback' => FALSE,
          'indexing_callback' => '',
          'index_type' => 'string',
          'facets' => FALSE,
          'facet missing allowed' => FALSE,
          'facet mincount allowed' => FALSE,
          // Field API allows any field to be multi-valued.
          'multiple' => TRUE,
        );
      if ($key !== 'per-field') {
        $mappings[$key] += $defaults;
      }
      else {
        foreach (array_keys($mappings[$key]) as $field_key) {
          $mappings[$key][$field_key] += $defaults;
        }
      }
    }

    // Allow other modules to add or alter mappings.
    drupal_alter('apachesolr_field_mappings', $mappings, $entity_type);

    $modules = system_get_info('module');
    $instances = field_info_instances($entity_type);
    foreach (field_info_fields() as $field_name => $field) {
      $row = array();
      if (isset($field['bundles'][$entity_type]) && (isset($mappings['per-field'][$field_name]) || isset($mappings[$field['type']]))) {
        // Find the mapping.
        if (isset($mappings['per-field'][$field_name])) {
          $row = $mappings['per-field'][$field_name];
        }
        else {
          $row = $mappings[$field['type']];
        }
        // The field info array.
        $row['field'] = $field;

        // @todo: for fields like taxonomy we are indexing multiple Solr fields
        // per entity field, but are keying on a single Solr field name here.
        $function = !empty($row['name callback']) ? $row['name callback'] : NULL;
        if ($function && is_callable($function)) {
          $row['name'] = $function($field);
        }
        else {
          $row['name'] = $field['field_name'];
        }
        $row['module_name'] = $modules[$field['module']]['name'];
        // Set display name
        $display_name = array();
        foreach ($field['bundles'][$entity_type] as $bundle) {
          if (empty($instances[$bundle][$field_name]['display']['search_index']) || $instances[$bundle][$field_name]['display']['search_index'] != 'hidden') {
            $row['display_name'] = $instances[$bundle][$field_name]['label'];
            $row['bundles'][] = $bundle;
          }
        }
        // Only add to the $fields array if some instances are displayed for the search index.
        if (!empty($row['bundles'])) {
          // Use the Solr index key as the array key.
          $fields[$entity_type][apachesolr_index_key($row)] = $row;
        }
      }
    }
    
  }
  return $fields[$entity_type];
}

As you can see above the only fields that are taken into index are the ones that come from field_info_fields() function.

Attached the patch to include the fields that are defined in the extrafields hook that allows external modules to define mapping option that can be indexed.

Regards,

Julian Mancera

Comments

julianmancera’s picture

StatusFileSize
new2.06 KB

Bug in the patch, here is the new one

Julian Mancera

nick_vh’s picture

Status: Active » Needs work

Could you please use double spaces instead of tabs? Marking as needs work till code review passes :-)

julianmancera’s picture

Hi Nick,

I double checked the patch and the module with coder but no tabs were found, I´m submitting the coder reviewed patch.

Regards

Julian Mancera

julianmancera’s picture

Status: Needs work » Active

Changing to active

pwolanin’s picture

Status: Active » Needs work

_field_info_collate_fields()

Is named as a non-API function - should probably use field_info_fields() instead.

Also - feels like a lot of code duplication?

julianmancera’s picture

Hi Nick,

The field_info_fields function filters out the extrafields defined by the extrafield hook, additionally the _field_info_collate_fields is called by the field_info_fields one. What is your suggestion to do a module_invoke_all to the modules that implement the hook_extrafields(not sure the name now) and get them from there?

Julian Mancera

nick_vh’s picture

Category: bug » feature

Marking as feature request. Let's clean the bug list first

pwolanin’s picture

Version: 7.x-1.0-beta19 » 7.x-1.x-dev
Category: feature » bug

Any function named with a leading _ should not be used - it's not a public API function.

This is probably bug if we are not supporting the full field API.

nick_vh’s picture

So what is the next step to take here? Julian, can you show us a usecase or improve the code?

Chaz Cheadle’s picture

Perhaps an admin option in the apachesolr search settings could allow 'indexing of ALL custom fields' or a checkbox list of all fields, indexed (checked and unindexed (unchecked).

Chaz

nyleve101’s picture

Hi,

the patch above doesn't seem to work with the current version of Apache Solr Integration and is preventing the inclusion of Ubercart fields from the Apache Solr Ubercart module. Is anyone else experiencing this issue?

Evey

PatchRanger’s picture

Status: Needs work » Closed (works as designed)

Please take a look at this useful article: Exposing fields to Solr. It puts clear that in most cases you don't have to manually implement some hooks in order to achieve custom field indexing, a couple of easy actions with Drupal UI is enough. That article explains how to determine whether you really need such hook implementation - and suggests how to do it. So closing as works as designed if nobody would mind.
@nyleve101 I have double checked: "Use Case #1" from the article above works for indexing Ubercart fields: just install Apachesolr Ubercart Integration module, follow the instructions from the article and flush all caches.