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
Comment #1
julianmancera commentedBug in the patch, here is the new one
Julian Mancera
Comment #2
nick_vhCould you please use double spaces instead of tabs? Marking as needs work till code review passes :-)
Comment #3
julianmancera commentedHi 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
Comment #4
julianmancera commentedChanging to active
Comment #5
pwolanin commented_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?
Comment #6
julianmancera commentedHi 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
Comment #7
nick_vhMarking as feature request. Let's clean the bug list first
Comment #8
pwolanin commentedAny 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.
Comment #9
nick_vhSo what is the next step to take here? Julian, can you show us a usecase or improve the code?
Comment #10
Chaz Cheadle commentedPerhaps 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
Comment #11
nyleve101 commentedHi,
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
Comment #12
PatchRanger commentedPlease 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.