To eliminate the redundant display of facets on search result pages, simply call array_unique on the facet items array.

So, this:

function theme_solr_facet_filters($type, $fq){

 ...
 
return theme('item_list', $items);
}

becomes this:

function theme_solr_facet_filters($type, $fq){

 ...
 
return theme('item_list', array_unique($items));
}

I will likely remove the links and add styling to selected facets within the facet display area to reinforce the search context as well. This is what I have done in the past. But array_unique will prevent redundant facets from being displayed either way.

Attaching a simple patch.

Comments

cfennell’s picture

Title: Redundant facets displaying in theme_biblio_facet_filters » Now with a non-empty patch ;)
StatusFileSize
new297 bytes

see attached.

hickory’s picture

Title: Now with a non-empty patch ;) » Redundant facets displaying in theme_biblio_facet_filters
Status: Needs review » Fixed

Fixed, thanks for the patch. If you manage to add some decent styling for the chosen filters, that would be much appreciated.

cfennell’s picture

Title: Redundant facets displaying in theme_biblio_facet_filters » facet_filter styling

One thing I'd like to do w/facet output is to alter the text to my liking. What do you think about the idea of building a theme function to handle just this task? So, before displaying the facet link, for example, you call a text-altering theme:

$text = theme('facet_filter_text', $facet, $facet_arr[0], TRUE);
$items[] = check_plain($text) . ' ' . l('x', "search/$type", array('class' => 'facet_filter'), sprintf('t=%s&fq=%s&df=%s', $_GET['t'], implode(' AND ', $filters), $_GET['df']));

facet_filter_text calls something like:

function theme_facet_filter_text($facet, $field, $labeled = FALSE){
  switch($field){
	case 'year':
	  $facet_label = 'Year';	  
      $facet = substr($facet, 0, 4); //get rid of the extra date/time formatting
	break;	
  }
  $output = ($labeled == TRUE)? $facet_label . ': ' . $facet : $facet;
  return $output;
}

I think I'll be able to style the entire facet links via attributes in the item_list, but I need to actually change the text on display, hence this function. You can also call this in theme_solr_facet It did, however, occur to me that this theme function might be better suited as a node_hook though.

I guess it's food for thought anyway....

Anonymous’s picture

Status: Fixed » Closed (fixed)