I have been using hook_apachesolr_update_index() to fine tune access control in my searches. As I am using the private_upload.module, I need to be able to add more control over attachment searches.

The process for doing this in apachesolr is to use hook_apachesolr_update_index() to add a dynamic field to a document, then hook_apachesolr_modify_query() to filter on this field. See http://drupal.org/node/632962 for more details on this.

The problem I am having with apache solr attachments is that in it's function apachesolr_attachments_add_documents(&$documents, $nid), it by passes the hook_apachesolr_update_index() process, except for apachesolr_nodeaccess. Here is the code:

        if (module_exists('apachesolr_nodeaccess')) {
          apachesolr_nodeaccess_apachesolr_update_index($document, $node);
        }

As a result, any other module's hook_apachesolr_update_index() code is ignored.

A simple hack for this is as follows:

        if (module_exists('apachesolr_nodeaccess')) {
          apachesolr_nodeaccess_apachesolr_update_index($document, $node);
          mymodule_apachesolr_update_index($document, $node);
        }

My question is: Wouldn't it be better to call all hook_apachesolr_update_index() functions as provided for in apachesolr.index.inc?:

    // Let modules add to the document - TODO convert to drupal_alter().
    foreach (module_implements('apachesolr_update_index') as $module) {
      $function = $module .'_apachesolr_update_index';
      $function($document, $node);
    }

Or, is there a reason why this was not implemented originally?

Comments

pwolanin’s picture

Status: Active » Postponed

Yes, there is a different, _alter, hook you can be using.

however, given that we are preparing these more-or-less like nodes it might make sense to use the same hook. Marking postponed until this issue is resolved in terms of the schema change to add 'entity': http://drupal.org/node/348668

pwolanin’s picture

actually maybe this is the right issue to reference http://drupal.org/node/641954

agileware’s picture

Status: Postponed » Needs review
StatusFileSize
new1.17 KB

I ran into this issue too.

Here is a patch for the readme that gives a note on how to do it.

agileware’s picture

For those who don't want to read or apply the patch, you can get around this problem without hacking apachesolr_attachments by adding this to your custom module:

<?php
  function my_module_apachesolr_attachment_index_alter(&$document, $node, $file) {
    my_module_apachesolr_update_index($document, $node);
  }
?>
pwolanin’s picture

Here's a patch that would invoke this hook for all modules - will only work properly with not-yet committed version of apachesolr

pwolanin’s picture

pwolanin’s picture

Version: 6.x-2.0-alpha1 » 6.x-1.x-dev
StatusFileSize
new2.15 KB

updated patch (plus switching branches)

somebodysysop’s picture

So, just to be clear, with this new patch, custom module code entered into the hook:

mymodule_apachesolr_update_index($document, $node);

will now execute as expected within apachesolr_attachments? Are there any changes we need to make to our custom module for this to work?

Oh, and thanks for getting this done!

agileware’s picture

I've been successfully using the patch in #7 for a week or so.

I'm running apachesolr 6.x-1.0-rc5, apachesolr_attachments 6.x-1.0-alpha2
and I no longer need to use hook_apachesolr_attachment_index_alter, only hook_apachesolr_update_index

pwolanin’s picture

Category: support » feature
pwolanin’s picture

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

Committed to 1.x. Patch doesn't apply to HEAD - not sure if it's relevant or not.

wmostrey’s picture

This is no longer relevant to 6.x-2, it all works as expected.

wmostrey’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

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

jpmckinney’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new1.64 KB

This is actually relevant to 2.x (closed #1032650: Not calling hook_apachesolr_update_index in all modules as duplicate).

jpmckinney’s picture

Category: feature » bug
jpmckinney’s picture

Status: Needs review » Fixed

#635480 by jpmckinney, pwolanin, Agileware: Unable to use hook_apachesolr_update_index with apache solr attachments.

Status: Fixed » Closed (fixed)

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