Notice: Undefined index: field_page_attachments in /var/www/glowbox/company/sites/all/modules/contrib/apachesolr/apachesolr.module on line 1551

If a module is implementing hook_apachesolr_cck_fields_alter line 1551 throws errors because any added fields in the alter don't exist in $fields[$row->field_name]. Patch attached fixes this issue.

Note, this might be related also (I think) with #664866: Multiple indexes for one CCK field.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

robertDouglass’s picture

Can you paste some example implementation that causes the error for my testing? Thanks.

swentel’s picture

Taken from nd_search.module (from nd_contrib branch 6--2)

/**
 * Implementation of hook_apachesolr_cck_fields_alter.
 * Add the required CCK fields to apache solr.
 */
function nd_search_apachesolr_cck_fields_alter(&$mappings) {
  $fields = content_fields();

  foreach ($fields as $field) {
    $mappings['per-field'][$field['field_name']] = array(
      'display callback' => '',
      // The callback function gets called at indexing time to get the values.
      'indexing callback' => 'nd_search_indexing_callback',
      // Common types are 'text', 'string', 'integer',
      // 'double', 'float', 'date', 'boolean'
      'index_type' => _get_solr_type($field['type']),
    );
  }
}

/**
 * Get the corresponding apache solr type from a cck type.
 *
 * @param string $type CCK field type.
 * @return array with type and prefix in apache solr.
 */
function _get_solr_type($type) {
  $types = array(
    'text' => 'string',
    'number_integer' => 'integer',
    'number_float' => 'float',
    'filefield' => 'string',
    'imagefield' => 'string',
    'date' => 'date',
  );

  // Default type is text
  if (!isset($types[$type])) {
    return 'string';
  }

  return $types[$type];
}
swentel’s picture

Title: PHP notices on line 1551 » Several php notices
FileSize
550 bytes
572 bytes

I've attached two other patches fixing other notices. I did them seperately so you can review them easier, changed title to reflect that we're trying to fix several notices at once :)

  • apachesolr_operator_settings.patch : fixes a notice where $operator_settings[$module][$delta] might not be set. This check is also done in apachesolr_form_block_admin_configure_alter() for $form['block_settings']['apachesolr_operator']
  • apachesolr_filters_notices.patch : fixes a notice in Solr_Base_query where filters might be empty.

I found two others which I couldn't fix immediately or didn't really understand what exactly was going on in there:

  • Warning: Illegal offset type in isset or empty in /var/www/glowbox/company/sites/all/modules/contrib/apachesolr/apachesolr_search.module on line 927
  • Notice: Array to string conversion in /var/www/glowbox/company/includes/bootstrap.inc on line 77 :

For the second notice, a backtrace leads to ../Solr_Base_Query.php:388 where the $themed variable has become an array instead of text. Probably the theme($breadcrum_name, $field) function errors here. The backtrace for the first one seems related too

1	0.0001	57840	{main}( )	../index.php:0
2	0.0884	1497084	menu_execute_active_handler( )	../index.php:18
3	0.0885	1497468	call_user_func_array ( )	../menu.inc:348
4	0.0885	1497760	apachesolr_search_view( )	../menu.inc:0
5	0.0902	1502832	apachesolr_search_search( )	../apachesolr_search.module:168
6	0.0902	1503244	apachesolr_search_execute( )	../apachesolr_search.module:129
7	0.1251	1893332	Solr_Base_Query->get_breadcrumb( )	../apachesolr_search.module:382
8	0.1257	1894800	theme( )	../Solr_Base_Query.php:387
9	0.1316	2359388	call_user_func_array ( )	../theme.inc:617
10	0.1316	2359696	theme_apachesolr_breadcrumb_language( )	../theme.inc:0
11	0.1316	2359820	apachesolr_search_language_name( )	../apachesolr_search.module:1313
robertDouglass’s picture

FileSize
2.56 KB

Unified patch.

robertDouglass’s picture

Version: 6.x-2.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

#664884 by swentel: Fixed Several php notices.
Committing to 6.2. Thanks!

robertDouglass’s picture

Status: Patch (to be ported) » Fixed

Don't think these need porting.

pwolanin’s picture

Looks like the code is rather different in 6.x-1.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.