I ran into issue trying to make my sarnia index work with the search_api_grouping module. I ended up not using the search_api_grouping module.
With search_api_grouping, I was trying to group by a string field in my solr index. However, I could not get the field to show up in the group by filter. I tried with copying the field to a text field, it was showing up but the grouping was acting giving me very odd results and paging wasn't working.
Instead i used _hook_search_api_solr_query_alter() to define the grouping. I noticed that there was an issue with the extractResults function of the SarniaSolrService class, it was not fetching the count and docs properly.
Here is the code I used in the hook to use field collapsing, in case anyone is looking into achieving something similar:
if(!empty($options) && ( $options['search id']=='search_api_views:recipient_search:page' || $options['search id']=='search_api_views:recipient_search:view_recipient_page')){
//$query->getOption('search_api_grouping')['fields']=array('group_id'=>'group_id');
$group_options=array(
'use_grouping'=>true,
'fields'=>array('group_id'),
'group_sort'=>array(),
'group_limit'=>1,
'truncate'=>false,
'group_facet'=>false
);
$query->setOption('search_api_grouping',$group_options);
$call_args['params']['indent']='true';
$call_args['params']['group']='true';
$call_args['params']['group.field']='group_id';
$call_args['params']['group.limit']='1';
$call_args['params']['group.ngroups']='true';
}
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2977620-sarnia-field-collapsing.patch | 820 bytes | marc.mantha@outlook.com |
Comments
Comment #2
marc.mantha@outlook.com commentedHere is the patch.
Comment #3
jmdeleon commentedLooks good. This tracks a feature long supported in Search API Solr, and the use-case seems pretty clear.
Comment #5
jmdeleon commentedComment #6
jmdeleon commented