I've added the following to my module so that I can output the various fields i have highlighted:
function apachesolr_search_finalize_query(&$query, &$params){
$params['hl.fl'] = '*';
$params['hl'] = 'on';
}
However, there does not seem to be any way of retrieving the highlighted fields.
The $results['fields'] array only contains the original non-highlighted fields. Only the body seems to be highlighted.
Can anyone shed some light on this please?
Thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | highlighted-fields-1162478-10.patch | 1.2 KB | kevin.dutra |
| #5 | highlighted-fields-1162478-5.patch | 1.47 KB | kevin.dutra |
Comments
Comment #1
alcroito commentedThe problem is on line 402 in apachesolr_search.module
The code tries to access in the response, a value array, keyed by $hl_fl, which is "*"
Such a key does not exist, instead, it's an array keyed with all the fields that have a match.
This should be re-factored somehow to take into account when are a lot of highlight snippets generated.
Comment #2
alcroito commentedComment #3
pwolanin commentedpossibly the code could be changed to just foreach over:
I'm not sure if that's set if there are no highlighting matches.
Comment #4
alcroito commentedWhen you do a foreach, and there are hits in a couple of fields (not just one) the snippet variable will contain the concatenated output of all the highlighted fields.
Comment #5
kevin.dutra commentedMy $0.02:
This part doesn't make sense to me. If you want to highlight more than one field (say you had set $params['hl.fl'] = 'body,title'), then the highlighting for the snippet gets hosed.
And even supposing the snippet highlighting didn't get hosed, (as oxford-dev points out) there doesn't seem to be any way of accessing the highlighted fields. That info is in the $response, which is neither cached (like the $query) nor passed as an arg to modules implementing hook_apachesolr_process_results().
So I've attached a patch that, I hope, satisfactorily resolves these two issues. The snippet would no longer get hosed as a result of highlighting multiple fields and the highlighting portion of the response, like the regular fields, gets added into the $results so that it can be utitlized via hook_apachesolr_process_results().
Comment #7
kevin.dutra commentedD'oh, just found it: apachesolr_static_response_cache()
Comment #8
nick_vhGreat :-) So this can be closed?
Comment #9
kevin.dutra commentedI guess so, although the problem with the snippet is still there. You want me to create a separate issue for that?
Comment #10
kevin.dutra commentedThis would be the patch just for that part.
Comment #11
pwolanin commentedThe patch doesn't seem relevant to the issue here? Why would you hard-code the body field?
Comment #12
kevin.dutra commentedI thought I made it reasonably clear above, but maybe this will better explain:
Using the "hl.fl" parameter as it currently stands doesn't make sense to me. For one thing, just because I want to highlight the title field (for instance) doesn't mean I want the snippet to be the title. More importantly, if you would like to have multiple fields highlighted, then a less desirable snippet will always be chosen (one without highlighting) due to how the current code works. Let's say I want to highlight both the body field and the title field, so I modify the query:
As far as Solr is concerned, this is fine, and it will return highlighted results for both fields. However, when the module processes the response $hl_fl gets the value 'body,title' and so it will never choose the highlighted body field for the snippet, even though it may be available.
($response->highlighting->{$doc_id}->body,title doesn't exist....that first if statement will always be false)
True, this issue isn't a perfect match to what the original author was aiming at, but it is directly related to highlighting multiple results. I offered above to open a separate issue, and I'm still happy to do that if you prefer.
I suppose it could be configurable instead (would need to make sure the configured field got added to the highlighting parameters for the query), but I think the body field is what users expect to be used for the snippet and it's the only field in that's configured in solrcofig.xml to get highlighted, so my first inclination was to just hard-code it.
Comment #13
nick_vhClosing in favor of 6.x-3.x and because nobody seems to care (time of last response) or cannot reproduce. If you think this is still an issue in 6.x-3.x, feel free to re-open!