I have two apachesolr environment setup in my drupal instance. I want to index some nodes to one environment and some to the other, say based on some node values.

I could see that it always indexes to default the environment. I could see the possibility of indexing in two environments, but it is irrespective of the nodes value.

How can i achieve it?


To give more detail, I am trying to achieve shards in apache solr in Drupal

UPDATE - 17 DEC 2012

Modules used:

Reason on why i need node values

  • I have a large nodes of a particular entity type, This makes my index so large.

    • So Decided to go with shards with multiple indexes of the same node type.
  • So based on the node size and its priority of the node or proximity of the nodes location or users location , I want to split up the index to separate cloud servers and index them.

  • Proximity of the node also gives me power of separate out search indexes at a later stage.

  • Do you mean that you have two Solr indexes for nodes on one site and want place some nodes on first index and other nodes on second one? Dec 14 '12 at 17:48
  • @Eugene Fidelin Yes two environment is two index. Dec 14 '12 at 18:04
  • Why would you do this on the Drupal side and not on the Solr side? Doesn't Solr support shards on it's own? If it doesn't, a quick and dirty way to do this would be to use a system that treats all content types the same and organizes content based only on taxonomy - but does in fact have different content types. You could use node hooks with a simple custom module to change the type of content being created on the fly. Without that degree of latitude, it's a custom module that maps nids to indexes and hooks into or overrides existing indexing behavior Dec 15 '12 at 6:44
  • @DavidFells how come a node hooks redirect nodes to indexes? Dec 17 '12 at 6:02
  • You'd use a different set of field names for each content type (just namespace them) and then in the search api, index those sets of field under a server's index listing for each type of content. I assumed you'd use search api, not the solr module itself, since search api is better all around. Dec 17 '12 at 7:12

I do not know if it is possible to shard Drupal nodes into different Solr indexes based on arbitrary field values, I do however know it is possible at a node type level.

From the API documentation:

 * This is invoked for each entity that is being inspected to be added to the
 * index. if any module returns TRUE, the entity is skipped for indexing.
 * @param integer $entity_id
 * @param string $entity_type
 * @param integer $row
 *   A complete set of data from the indexing table.
 * @param string $env_id
 * @return boolean
function hook_apachesolr_exclude($entity_id, $entity_type, $row, $env_id) {
  // Never index media entities to core_1.
  if ($entity_type == 'media' && $env_id == 'core_1') {
    return TRUE;
  // Never index news entities to core_2.
  if ($entity_type == 'news' && $env_id == 'core_2') {
    return TRUE;
  // Default to allow.
  return FALSE;

So all you would need to do is allow some node types to be indexed by one core, and allow some other node types to be indexed by another core.

  • Thank you.. I am aware of this hook.As said it can do in entity_type level Dec 17 '12 at 9:13
  • Actually no, your question is rather vague. If you want better answers you should clarify exactly what you are looking for in the $node in order to send it to the correct index. Is is a field value, or a property value, or some sort of join on another table? If splitting on $node->type is not good enough, you should say why in the question.
    – wiifm
    Dec 17 '12 at 9:43
  • I have updated my question. Pls let me know if needs further info Dec 17 '12 at 9:58
  • Thanks for that, at least now you may find someone with the specific knowledge that you seek ;)
    – wiifm
    Dec 17 '12 at 10:16
  • Thanks man I have accepted. Just a glitch in my mind that stopped from accepting yours is great. Dec 18 '12 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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