Hi,

I was wondering if anyone has any idea on how to include a cck text field in the search index? I don't want to use it as a facet, I just want to be able to view the field in the search results. I found the code below here http://drupal.org/node/1366156 but that seems to add facets.

/*
 * Implements hook_apachesolr_field_mappings_alter().
 */
function my_module_apachesolr_field_mappings_alter(&$mappings) {
  $mappings['text'] = array(
    'indexing_callback' => 'apachesolr_fields_default_indexing_callback',
    'map callback' => '',
    'index_type' => 'string',
    'facets' => TRUE,
    'facet missing allowed' => TRUE,
    'dependency plugins' => array('bundle', 'role'),
    'hierarchy callback' => FALSE,
    'name_callback' => '',
    'facet mincount allowed' => FALSE,
    // Field API allows any field to be multi-valued.
    // If we set this to false we are able to sort
    'multiple' => FALSE,
  );
  // Add our per field mapping here so we can sort on the
  //price by making it single. Solr cannot sort on multivalued fields
  $mappings['per-field']['field_price'] = $mappings['number_float'];
  $mappings['per-field']['field_price']['multiple'] = FALSE;
}

Any help is greatly appreciated.

Eve

CommentFileSizeAuthor
#11 apachesolr_text.zip2.49 KBnick_vh

Comments

pwolanin’s picture

Status: Active » Fixed

If you are asking about CCK, that doesn't seem relevant to 7.x.
In show, for either case, make sure the text is rendered as part of the full node when being sent to the search index.

Check the 'search index' display mode.

nyleve101’s picture

Hi,

thanks for getting back to me.

Apologies, I didn't mean CCK. Thanks for the 'manage display' tip but is there a way to have the text field as an individual field rather than as part of the whole content display? I want to be able to display the field_old_price field specifically in an apache solr view display. My other non text fields are being indexed individually.

Thanks again for your help- much appreciated.

nyleve101’s picture

Status: Fixed » Active
nyleve101’s picture

Title: cck text field inclusion » content type text field inclusion
nick_vh’s picture

Status: Active » Fixed

Please search the issue queue, this has been answered multple times before. A keyword that probably helps is apachesolr_query_alter and the qf parameter.

http://drupal.org/node/1490186
http://drupal.org/node/1475324

If you have added your field you can use function hook_apachesolr_query_alter($query) { to add this new field to the query fields using $query->addParam('qf', 'ss_newfield');

nyleve101’s picture

really sorry. Thanks for getting back to me.

grendzy’s picture

Category: support » feature
Status: Fixed » Active

Are there are any plans to implement a UI for indexing existing text fields?

If not, I'm considering writing one. Are there any technical hurdles I need to be aware of? Thanks!

pwolanin’s picture

wait - there is a catch to the above in that STRING (e.g. ss_ ) fields are not suitable for keyword searches at all. You need a text field that's tokenized, etc.

This would not be hard to hack together - in the UI you can already pick TEXT fields to be part of the query, so the missing piece is really to implement a module that puts a UI on top of hook_apachesolr_field_mappings_alter() and provides 'per-field' mappings or overrides.

grendzy’s picture

Thanks, I think I even understood half of that. :-) Would an existing dynamic field like ts_ work? Or would the schema.xml need to be modified?

nick_vh’s picture

This is an example you can copy/paste in a custom module called apachesolr_text. It will ma the drupal text fields with solr dynamic fields and expose them to facet API

/**
 *
 * @param type $mappings
 * @param type $entity_type
 *
 */

function apachesolr_text_apachesolr_field_mappings_alter(&$mappings, $entity_type) {
  // Enable indexing for text fields
  $mappings['text'] = array(
    'indexing_callback' => 'apachesolr_fields_default_indexing_callback',
    'map callback' => '',
    'index_type' => 'string',
    'facets' => TRUE,
    'facet missing allowed' => TRUE,
    'dependency plugins' => array('bundle', 'role'),
    'hierarchy callback' => FALSE,
    'name_callback' => '',
    'facet mincount allowed' => FALSE,
    // Field API allows any field to be multi-valued.
    // If we set this to false we are able to sort
    'multiple' => FALSE,
  );
}
nick_vh’s picture

StatusFileSize
new2.49 KB

And also the complete module is included so you can use it as a start

nick_vh’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.