I get this error when cron runs and nodes are to be indexed.

I think it is a wrong implementation of the hook in apachesolr.index.inc because drupal_alter only allows 2 additional parameters to be handed off to the function.

In this case there 3 additional parameters are included and this is the reason for this error.

Comments

mkalkbrenner’s picture

Project: Apache Solr Multilingual » Apache Solr Search

I get the same warning. The function in Apache Solr Multilingual has been coded according to the documentation in apachesolr.api.php:

/**
 * Alter the prepared documents from one entity before sending them to Solr.
 *
 * @param $documents
 *   Array of ApacheSolrDocument objects.
 * @param $entity
 * @param $entity_type
 * @param string $env_id
 */
function hook_apachesolr_index_documents_alter(array &$documents, $entity, $entity_type, $env_id) {
  // Do whatever altering you need here
}

Therefor this issue gets moved to Apache Solr Search Integration.

nick_vh’s picture

In any case, I'd suggest you to use hook_apachesolr_index_document_build,

will look into this issue

mkalkbrenner’s picture

hook_apachesolr_index_document_build is called to early. For the modifications done by multilingual we need the teaser and the tags to be part of the document already:

  //do this for all possible documents that were returned by the callbacks
  foreach ($documents as $document) {
    // Call an all-entity hook to add stuff to the document.
    module_invoke_all('apachesolr_index_document_build', $document, $entity, $entity_type, $env_id);

    // Call a type-specific hook to add stuff to the document.
    module_invoke_all('apachesolr_index_document_build_' . $entity_type, $document, $entity, $env_id);

    // Final processing to ensure that the document is properly structured.
    // All records must have a label field, which is used for user-friendly labeling.
    if (empty($document->label)) {
      $document->label = '';
    }

    // All records must have a "content" field, which is used for fulltext indexing.
    // If we don't have one, enter an empty value.  This does mean that the entity
    // will not be fulltext searchable.
    if (empty($document->content)) {
      $document->content = '';
    }

    // All records must have a "teaser" field, which is used for abbreviated
    // displays when no highlighted text is available.
    if (empty($document->teaser)) {
      $document->teaser = truncate_utf8($document->content, 300, TRUE);
    }

    // Add additional indexing based on the body of each record.
    apachesolr_index_add_tags_to_document($document, $document->content);
  }

  // Now allow modules to alter each other's additions for maximum flexibility.
  drupal_alter('apachesolr_index_documents', $documents, $entity, $entity_type, $env_id);
nick_vh’s picture

"A maximum of 2 alterable arguments is supported. In case more arguments need to be passed and alterable, modules provide additional variables assigned by reference in the last $context argument"

Seems nobody has ever tested that alter hook. Most of the times the build hook is sufficient.

What are our options here?
We can give it one context argument with documents and the second one with entity, entity_type and $env_id as a key => value storage?

nick_vh’s picture

StatusFileSize
new593 bytes
nick_vh’s picture

Status: Active » Needs review

Since we only need to alter the documents array (all the other values won't have any effect) the rest is considered as context and can be given to the alter as one array

Status: Needs review » Needs work

The last submitted patch, 1722012-5.patch, failed testing.

mkalkbrenner’s picture

Status: Needs work » Active

Why not implementing a normal hook using module_invoke_all() instead of drupal_alter()?

  module_invoke_all('apachesolr_index_documents_alter', $documents, $entity, $entity_type, $env_id);

This way we have an absolute compatible change which is fine even for the current release candidate status.

nick_vh’s picture

Status: Active » Needs review
StatusFileSize
new1.4 KB

API changes documented

nick_vh’s picture

Hmm, the new hook would be a solution, that allows us not to change the API. Looking into it

Status: Needs review » Needs work

The last submitted patch, 1722012-6.patch, failed testing.

nick_vh’s picture

StatusFileSize
new556 bytes

Just tested this, works as expected when you loop over the documents and change it.

Only problem that stands is that the array itself can't be altered. Somehow the pointer to that array does not seem to function. eg.: This means that if you add another document to the array, it won't reach the indexing process.

Still investigating

nick_vh’s picture

Status: Needs work » Needs review
nick_vh’s picture

StatusFileSize
new757 bytes

This won't work

// Now allow modules to alter each other's additions for maximum flexibility.
  // Afer the test, the documents should have 1 value more
  $documents = array('test1' => 'test1');
  
  // Not possible because you can't give the documents array as a reference
  module_invoke_all('apachesolr_index_documents_alter', $documents, $entity, $entity_type, $env_id);
  
  // Impossible because drupal alter only allows three arguments. This would give warnings for env_id
  drupal_alter('apachesolr_index_documents', &$documents, $entity, $entity_type, $env_id);
  
  // Only possible option is the following
  foreach (module_implements('apachesolr_index_documents_alter') as $module) {
    $function = $module . '_apachesolr_index_documents_alter';
    $function($documents, $entity, $entity_type, $env_id);
  }
pwolanin’s picture

Version: 7.x-1.x-dev » 6.x-3.x-dev
Status: Needs review » Patch (to be ported)
StatusFileSize
new1.32 KB

commited this which fixes whitespace. needs to be ported

nick_vh’s picture

Status: Patch (to be ported) » Fixed

committed without modifications, worked as expected

Status: Fixed » Closed (fixed)

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

ronniekoopmans’s picture

// Not possible because you can't give the documents array as a reference
module_invoke_all('apachesolr_index_documents_alter', $documents, $entity, $entity_type, $env_id);

Objects always pass by reference, even if the array itself is a copy.

xx_apachesolr_index_documents_alter($documents, ..) works
xx_apachesolr_index_documents_alter(&$documents, ..) works, generates php notice