Hi there, I was trying to add my custom field to search results output.
first, i've added required field via hook_apachesolr_update_index, then checked that they were added to the index.
Next step, via hook_apachesolr_query_prepare, I've added same field names as I added then at hook_apachesolr_update_index,
so I got $query->addParam('fl','field'); for each of these fields.
however, on hook_apachesolr_search_result_alter, $doc had just the default field, without the ones, added by me.
Also, I've tried to use $query->replaceParam('fl',array('*')); and it is worked out - hook_apachesolr_search_result_alter showed me all the fields with mine as well.
The questions is, is there's something I've missed, or why I failed to add custom fields to search results?
Regards, Slava.
Comments
Comment #1
cfuller12 commentedI ran into a very similar issue recently and I'm guessing that you're looking in the wrong place. The $document in hook_apachesolr_search_result_alter doesn't automatically get the new field added, but if you just print_r($vars) in hook_preprocess_search_result you should see your new field in $vars['result']['fields']. If you want to do something other than adding the fields to your formatted results, you can also look in the (as yet undocumented) hook_apachesolr_search_result, which gets invoked from apachesolr_process_response.
Comment #2
nick_vhThanks cfuller12 for this support answer! Appreciate it! :-)
Would you be so kind to add documentation to that hook_apachesolr_search_result hook?
Comment #3
nick_vhComment #4
pwolanin commentedComment #5
32i commentedHi cfuller12, ye thanks, you're right - I've managed to find this out some time ago.
Anyway, it was confusing for me hook_apachesolr_search_result_alter didn't take newly added fields.
Thanks again for response.