Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi!
I tried as many solutions I could found here and on google, but nothing works for me. For example I want to add an image field to the search index. I tried this from here:
function customsearch_apachesolr_update_index($document, $node, $namespace) {
// When indexing nodes, add field from my custom content type
if ($node->type == 'content_page') {
// grab the image URL
$image_uri = $node->field_content_image['und'][0]['uri'];
// add the image and description to the document in the solr index
$document->addField('ss_my_content_page_image', $image_uri);
}
}
function customsearch_apachesolr_query_prepare($query) {
// Add the image
$query->addParam('fl', 'ss_content_page_image');
}
field_conent_image is the name of my field, content_page my conent_type
The image is a visible field in my content type.
I delete the whole index and re-index all, but never my custom field is shown in the apache solr report. Can somebody help me? I don't know what I am doing wrong.
Comments
Comment #1
Nick_vhHave you tried reading apachesolr.api.php?
Use one of those two hooks, one of them is a generic one, the other is entity_type specific.
Comment #2
stayontherun CreditAttribution: stayontherun commentedThx for your help, now it works with the function you posted. I haven't tried reading the api file before, now I know that hook_apachesolr_update_index is deprecated since 7.x-1.0-beta15 of this module.
Comment #4
moonshdw8 CreditAttribution: moonshdw8 commentedSorry to revisit this, but it sounds like you were in the same place I am right now.
Could you please show the code that ended up working for you?
And just to be sure, what file are you adding the "function hook_apachesolr_index_document_build..." to?
Thanks so much for any help you can give.
Comment #5
sankuratri CreditAttribution: sankuratri commentedI used following code and that worked to index my custom field(field_your_filed_name)
function your_module_apachesolr_index_document_build(ApacheSolrDocument $document, $entity, $entity_type, $env_id) {
if (!empty($entity->field_your_filed_name['und'][0]['value'])) {
$document->ss_field_your_filed_name= $entity->field_your_filed_name['und'][0]['value'];
}
}
Comment #6
moonshdw8 CreditAttribution: moonshdw8 commentedThanks for this code. Did you add this to your template.php file, did you create a new module to do this, or did you add this directly to a template file?