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';
    }

Comments

Menthos created an issue. See original summary.

marc.mantha@outlook.com’s picture

StatusFileSize
new820 bytes

Here is the patch.

jmdeleon’s picture

Looks good. This tracks a feature long supported in Search API Solr, and the use-case seems pretty clear.

  • jmdeleon committed 427f758 on 7.x-1.x authored by Menthos
    Issue #2977620 by Menthos: Issue with field collapsing
    
jmdeleon’s picture

Status: Active » Fixed
jmdeleon’s picture

Status: Fixed » Closed (fixed)