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

cfuller12’s picture

I 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.

nick_vh’s picture

Thanks cfuller12 for this support answer! Appreciate it! :-)

Would you be so kind to add documentation to that hook_apachesolr_search_result hook?

nick_vh’s picture

Status: Active » Needs work
pwolanin’s picture

Status: Needs work » Fixed
32i’s picture

Hi 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.

Status: Fixed » Closed (fixed)

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