Hi!

Im trying to index a custom field in apache solr but its not working. so far i have added this to my module but when i go to administer apache solr i cant see the field anywhere in the index..

function customsolr_apachesolr_update_index(&$document, $node, $namespace) {
if($node->type == "topic_page") {
$document->fs_nodeType = $node->type;
}
}

anyone know why? im using drupal 7.

Comments

tusharbodke’s picture

HI,
To add custom field for apache solr indexing, you should build document for such node, which we are sending to apache for indexing.

Check below url for drupal apache HOOK, to add custom field to apache solr document.
http://drupalcontrib.org/api/drupal/contributions!apachesolr!apachesolr.api.php/function/hook_apachesolr_index_document_build/7

OR

you can try

function customsolr_apachesolr_index_document_build_node(ApacheSolrDocument $document, $node, $env_id){
  if($node->type == "topic_page") {
   $document->fs_nodeType = $node->type;
  }
}

Thanks,

Tushar Shantaram Bodake

jgrubb’s picture

Hi, this might be new since 2 years ago, but there's a more formal API for adding fields to the document before sending to Solr.

See http://www.drupalcontrib.org/api/drupal/contributions%21apachesolr%21Apa...

<?php
/**
 * Implements hook_apachesolr_index_document_build().
 */
function apachesolr_site_apachesolr_index_document_build(
  ApacheSolrDocument $document,
  $entity,
  $entity_type,
  $env_id
) {
    $document->setField('group', apachesolr_site_group_hash()); // or whatever
}
?>
tjmoyer’s picture

Depending on what you're trying to do, you may not need to code this. If you're trying to get a hidden field to be searchable, try adding a custom search index display and re-indexing.

Check out the post Exposing Fields to Solr for an explanation of 2 primary use cases and their approaches.