0

We have a cck field called "keywords". We need to add this field to the solr index so we can search on it from outside of drupal. How are CCK fields managed in the solr index?

UPDATE:

I created a module "apachesolr_search_additions" and the following function:

<?php
function apachesolr_search_additions_apachesolr_update_index(&$document, $node) 
{
  if (isset($node->field_keywords_raw) && !empty($node->field_keywords_raw)) 
  {
    $document->addField('sm_keywords', $node->field_keywords_raw[0]['value'], '2.0');
  }
}

I then ran cron and went to: admin/reports/apachesolr

it does NOT show the field name in the search index. How can I verify it is in the index?

  • By default, apacehsolr index all cck field. What is your requirement and how you want to index this cck field? – Jayendra Kainthola Nov 17 '13 at 3:13
0

Adding Custom Fields to Apache Solr Search Results appears to have the instructions.

To do this, we will use the two hooks used in the last example: hook_apachesolr_update_index() and hook_apachesolr_modify_query(). To start, we need to add the data to the Solr index.

Modified the code to work with a field_keywords_field (note: field_keywords_field[0]['value'] is what I'm using, you may need to debug this if your keyword field is multi-value or something)

/**
* Implementation of hook_apachesolr_update_index()
*/
function mymodule_apachesolr_update_index(&$document, $node) {
  // Index field_keywords_field as a separate field
  if (isset($node->field_keywords_field) && !empty($node->field_keywords_field)) {
    // addField($key, $value, $boost), change $boost to give this field a higher score
    $document->addField('sm_field_keywords_field', $node->field_keywords_field[0]['value'], '2.0');
  }
}

function mymodule_apachesolr_modify_query(&$query, &$params, $caller) {
  $params['fl'] .= ',sm_field_keywords_field';
}
  • I followed your example but can't tell if it is in the index. – Chris Muench Sep 19 '12 at 15:00
  • You should be able to put in a keyword like "abc123", then delete the index and re-index all the items. Then just search for abc123 and it should show up. – Johnathan Elmore Sep 19 '12 at 15:42
  • The keywords raw field is a comma separated list of keywords. Should this be indexed separately? is there a good way to index an array? – Chris Muench Sep 19 '12 at 15:46
  • I'm really thinking keywords makes sense to be taxonomy, which Apache Solr has the built in ability to index. But it should work even if it's comma separated... it will still find the keyword in the string because it doesn't need to be an exact match. – Johnathan Elmore Sep 19 '12 at 16:23
0

As an answer to your update: You can use the luke request handler most likely present in your solr configuration.

For a solr setup running on the built-in Jetty container, the default address for a single-core solution is http://localhost:8983/solr/admin/luke but that varies according to whether your solr actually is on the localhost and whether you have a multi-core setup. Adjust accordingly.

That output will show you all the fields, their statistics and more. By default, the output is xml.

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.