Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I want a sharded Solr environment so that I can distribute data and query accordingly. Started two solr instances as described here.

Since Solr doesn't support (fully yet) writing automatically into different Solr instances, I have to do it manually.

I'm trying to do it in the following hook:

/* "node" is the module name. */
function node_apachesolr_index_document_build($document, $entity, $entity_type, &$env_id)
{
}

Note that I'm trying to change the $env_id by making it a reference parameter, since that's what I want to change based on certain logic. When the cron is run, I get the error:

Warning: Parameter 4 to node_apachesolr_index_document_build() expected to be a reference, value given in module_invoke_all() (line 857 of /var/www/drupal-7.17/includes/module.inc)

since it messes up with existing calls.

Any idea how to workaround this? Thanks.

share|improve this question

2 Answers

According to the documentation, the function hook_apachesolr_index_document_build(), on line 373 of file apachesolr.api.php, is not a reference value, instead directly a variable. So, the code should be:

function hook_apachesolr_index_document_build(ApacheSolrDocument $document, $entity, $entity_type, $env_id) {

}

Also, from the code you use, I suspect the following possibilities:

  1. You are adding the code to the core node module, which is never recommended, as one should never hack core.
  2. If you are adding this code to a custom module, and name that module node (as you mentioned in the comment of the code), that will conflict with the core node module, and might cause conflicts and break down your code.
  3. If you add this code to a custom module (with a different name), then it is a wrong way to implement a hook in custom module. Follow this guide to get started with module development.
    Lets say, if you name your module "custom_search", then you should place this code in the file custom_search.module, and implement it in the following way:

    function custom_search_apachesolr_index_document_build(ApacheSolrDocument $document, $entity, $entity_type, $env_id) {
    
    }
    

    Note that, I've replace the hook in the function name with the module name "custom_search"

share|improve this answer
1  
Thanks for the pointers. My question was more specifically on distributing to a different solr server (for which I tried changing $env_id by making it reference - I understand it's not right and that's why mentioned that "since it messes up with existing calls."). But thanks for the pointers though. – Mouli Dec 7 '12 at 7:15

I am not sure that I can give a complete answer , However have a look on the search results and modules available, this may give you an idea/hint,

1) An advanced option to allow configuration of "shards". This allows Solr to do a distributed search across several cores. A Filter by site Facet. Addition of the site host onto the extra result information (the small text under each result).

Multisite search is made possible by having many sites share an index. Because each "document" is stored in the index with a site and a hash field, it is possible to filter by site or hash, and thus return results from just one site, or from all of the sites sharing an index.

I will try to update you on this after digging more into the module.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.