You are here

function apachesolr_search_nested_facet_items in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 6 apachesolr_search.module \apachesolr_search_nested_facet_items()
  2. 6.2 apachesolr_search.module \apachesolr_search_nested_facet_items()

Recursive function that returns a nested array of facet values for use with theme_item_list().

Parameters

$query: The current Solr query.

$facets: Array of facet items to prepare for rendering, possibly as nested lists.

$num_found: The number of documents in the current response.

$sort: If true, the returned list will be sorted based on the count of each facets, it's text representation and wither it's active. If false, the facets will be returned in the order they were received.

2 calls to apachesolr_search_nested_facet_items()
apachesolr_search_currentsearch_block in ./apachesolr_search.module
Return the contents of the "Current search" block.
apachesolr_search_taxonomy_facet_block in ./apachesolr_search.module
Generate the facet block for a taxonomy vid delta.

File

./apachesolr_search.module, line 730
Provides a content search implementation for node content for use with the Apache Solr search application.

Code

function apachesolr_search_nested_facet_items($query, $facets, $num_found, $sort = TRUE) {
  $items = array();
  foreach ($facets as $field) {
    $breadcrumb_name = 'apachesolr_breadcrumb_' . $field['#name'];
    drupal_alter('apachesolr_theme_breadcrumb', $breadcrumb_name);
    $facet_text = theme($breadcrumb_name, $field, $field['#exclude']);
    if (!$facet_text) {
      $facet_text = $field['#value'];
    }
    $link = array();
    $new_query = clone $query;
    if (!empty($field['#active'])) {

      // '*' sorts before all numbers.
      $sortpre = '*';
      foreach (apachesolr_search_collect_children($field) as $child) {
        $new_query
          ->remove_filter($child['#name'], $child['#value']);
      }
      $options['query'] = $new_query
        ->get_url_queryvalues();
      $link['data'] = theme('apachesolr_unclick_link', $facet_text, $new_query
        ->get_path(), $options);
    }
    else {
      $sortpre = 1000000 - $field['#count'];
      $new_query
        ->add_filter($field['#name'], $field['#value']);
      $options = array(
        'query' => $new_query
          ->get_url_queryvalues(),
      );
      $link['data'] = theme('apachesolr_facet_link', $facet_text, $new_query
        ->get_path(), $options, $field['#count'], FALSE, $num_found);
    }

    // We don't display children unless the parent is clicked.
    if (!empty($field['#children']) && $field['#active'] == TRUE) {
      $link['children'] = apachesolr_search_nested_facet_items($query, $field['#children'], $num_found, $sort);
      $link['class'] = "expanded-facet";
    }
    elseif (!empty($field['#has_children'])) {
      $link['class'] = "collapsed";
    }
    $items[$sortpre . '*' . $facet_text . $field['#name'] . $field['#value']] = $link;
  }
  if ($sort) {
    ksort($items);
  }
  return array_values($items);
}