facet_filter styling

libsys - October 8, 2007 - 23:40
Project:Solr
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:minor
Assigned:Unassigned
Status:closed
Description

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.

AttachmentSize
solr.theme_facet_limit.patch0 bytes

#1

libsys - October 8, 2007 - 23:42
Title:Redundant facets displaying in theme_biblio_facet_filters» Now with a non-empty patch ;)

see attached.

AttachmentSize
solr.theme_facet_limit_0.patch297 bytes

#2

hickory - October 9, 2007 - 12:47
Title:Now with a non-empty patch ;)» Redundant facets displaying in theme_biblio_facet_filters
Status:patch (code 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.

#3

libsys - October 9, 2007 - 20:10
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....

#4

Anonymous - October 23, 2007 - 20:31
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.