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
Comments
Comment #1
pwolanin commentedIf 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.
Comment #2
nyleve101 commentedHi,
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.
Comment #3
nyleve101 commentedComment #4
nyleve101 commentedComment #5
nick_vhPlease 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');Comment #6
nyleve101 commentedreally sorry. Thanks for getting back to me.
Comment #7
grendzy commentedAre 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!
Comment #8
pwolanin commentedwait - 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.
Comment #9
grendzy commentedThanks, 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?
Comment #10
nick_vhThis 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
Comment #11
nick_vhAnd also the complete module is included so you can use it as a start
Comment #12
nick_vh