In apachesolr.module, theme_apachesolr_facet_list(), there is a small code issue that sometimes causes the wrong number of visible items in a facet block to appear.

This code:

foreach ($hidden_items as $hidden_item) {
      if (!is_array($hidden_item)) {
        $hidden_item = array('data' => $hidden_item);
      }
      $items[] = $hidden_item + array('class' => 'apachesolr-hidden-facet');
    }

Should be this:

foreach ($hidden_items as $hidden_item) {
      if (!is_array($hidden_item)) {
        $hidden_item = array('data' => $hidden_item);
      }
      $hidden_item['class'] = 'apachesolr-hidden-facet';
      $items[] = $hidden_item;
    }

The issue is that sometimes $hidden_item already has a class (in my case it was 'collapsible'). Using the '+' operator does not overwrite that value with the appropriate class name, so some of the items that should be hidden initially are not.

CommentFileSizeAuthor
#3 686390-preserve-class-3.patch819 bytespwolanin

Comments

pwolanin’s picture

The suggested change would overwrite the class you had set - that doesn't sound right either.

justindodge’s picture

In my case it seemed to make no difference, but I suppose you're right. For good measure:

foreach ($hidden_items as $hidden_item) {
      if (!is_array($hidden_item)) {
        $hidden_item = array('data' => $hidden_item);
      }
      $hidden_item['class'] = $hidden_item['class'] ? $hidden_item['class'] . ' apachesolr-hidden-facet' : 'apachesolr-hidden-facet';
      $items[] = $hidden_item;
    }
pwolanin’s picture

Version: 6.x-1.0-rc4 » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new819 bytes

need to use isset() to avoid notices

rjbrown99’s picture

There is a second problem with taxonomy facets and number if displayed items. I'm posting it here because the topic is identical but it is a different kind of issue.

In apachesolr_search.module, within the function apachesolr_search_taxonomy_facet_block, towards the bottom, we see this code:

    // Process all terms into an item list
    if ($items && ($response->response->numFound > 1 || $contains_active)) {
      $limit = isset($initial_limits['apachesolr_search'][$delta]) ? $initial_limits['apachesolr_search'][$delta] : $limit_default
      return array(
        'subject' => t('Filter by @name', array('@name' => $vocab->name)),
        'content' => theme('apachesolr_facet_list', $items, $limit),
      );
    }

The problem is the $initial_limits variable is never populated. So you end up with the taxonomy blocks ignoring the configured initial filter links value. In my case with a large taxonomy, my block had hundreds of terms displayed when I wanted it to display 10.

The fix is to add this line above the line that starts with $limit:

$initial_limits = variable_get('apachesolr_facet_query_initial_limits', array());
pwolanin’s picture

@rjbrown - I think this was fixed already in #672882: Broken "Show more" link on taxonomy facets

rjbrown99’s picture

Yup, didn't see that one. Thanks!

pwolanin’s picture

Is this patch working for you?

pwolanin’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Needs review » Patch (to be ported)

committed to 6.x-1.x

robertdouglass’s picture

Status: Patch (to be ported) » Fixed

#686390 by pwolanin | rjbrown99: Fixed Wrong number of initial items in taxonomy facet under certain conditions.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.