blacklight icon indicating copy to clipboard operation
blacklight copied to clipboard

Searching by group field key and grouped_key_for_results return value

Open JTatum95 opened this issue 7 years ago • 1 comments

In search_helper.rb and search_builder_behavior.rb there is a method named grouped_key_for_results that simply returns blacklight.config.index.group.

def grouped_key_for_results
    blacklight_config.index.group
end

According to the comment above this is "The key to use to retrieve the grouped field to display", however blacklight_config.index.group only returns true or false. Actually it only returns false, and if you try to return true you run in to an error whenever you try to narrow down to a single group - facets.rb tries to access @response which is nil because returning true does not create a valid request (attachment below).

So my question is this: what is the intended return type of this method? It seems to me that it should return the key like "format", "pub_date", etc. but that isn't what is currently happening.

Error: screenshot from 2018-06-15 14-09-52

JTatum95 avatar Jun 15 '18 19:06 JTatum95

By changing the grouped_key_for_results method in search_builder_behavior.rb to return the value of group.field which I currently have hard-coded:

def grouped_key_for_results
  if blacklight_params[:f] and blacklight_params[:f].include? :format
    return "format" # return key for group.field
  end
  false
end

and altering the add_group_config_to_solr method to remove the grouping parameters:

def add_group_config_to_solr(solr_parameters)
  if blacklight_params[:f] and blacklight_params[:f][grouped_key_for_results]
    solr_parameters.delete(:group) # Remove the parameter
    solr_parameters.delete('group.ngroups') # Remove ngroups for total count
  end
end

This now properly uses groups unless you are searching within a single group in which case it displays results outside of group according to the specified number of items. This also returns to group sorting after removing the group field facet from the search. I also tested this in a clone of the default Blacklight Demo where I only made these changes and added grouping to the catalog_controller.rb file.

NOTE: I am leaving this open for now to see if I can get an answer on whether or not this is correct or simply working by chance.

JTatum95 avatar Jun 22 '18 14:06 JTatum95