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?
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 635480-15.patch | 1.64 KB | jpmckinney |
| #7 | hook-apachesolr-update-index-635480-7.patch | 2.15 KB | pwolanin |
| #5 | hook-apachesolr-update-index-635480-5.patch | 2.18 KB | pwolanin |
| #3 | apachesolr_attachments-635480-3.patch | 1.17 KB | agileware |
Comments
Comment #1
pwolanin commentedYes, 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
Comment #2
pwolanin commentedactually maybe this is the right issue to reference http://drupal.org/node/641954
Comment #3
agileware commentedI ran into this issue too.
Here is a patch for the readme that gives a note on how to do it.
Comment #4
agileware commentedFor 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:
Comment #5
pwolanin commentedHere's a patch that would invoke this hook for all modules - will only work properly with not-yet committed version of apachesolr
Comment #6
pwolanin commentedcross-ref to that issue: #666648: Make hook_apachesolr_update_index() more generic by taking a namespace param also
Comment #7
pwolanin commentedupdated patch (plus switching branches)
Comment #8
somebodysysop commentedSo, 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!
Comment #9
agileware commentedI'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
Comment #10
pwolanin commentedComment #11
pwolanin commentedCommitted to 1.x. Patch doesn't apply to HEAD - not sure if it's relevant or not.
Comment #12
wmostrey commentedThis is no longer relevant to 6.x-2, it all works as expected.
Comment #13
wmostrey commentedComment #15
jpmckinney commentedThis is actually relevant to 2.x (closed #1032650: Not calling hook_apachesolr_update_index in all modules as duplicate).
Comment #16
jpmckinney commentedComment #17
jpmckinney commented#635480 by jpmckinney, pwolanin, Agileware: Unable to use hook_apachesolr_update_index with apache solr attachments.