solr pager issue

Public
</> CopyGet raw version
php
  1. /**
  2.  * Implements hook_form_FORM_ID_alter().
  3.  */
  4. function nascsp_form_apachesolr_search_custom_page_search_form_alter(&$form, &$form_state, $form_id) {
  5. $env_id = apachesolr_default_environment();
  6. if (! apachesolr_has_searched($env_id)) {
  7. return;
  8. }
  9. $query = apachesolr_current_query($env_id);
  10. $response = apachesolr_static_response_cache($query->getSearcher());
  11.  
  12. if (empty($response)) {
  13. // Response was empty, so returning no block.
  14. return;
  15. }
  16.  
  17. $tab_data = nascsp_search_facet_block($response, $query);
  18. // If, instead we were displaying this in a block, the $return value would
  19. // be returned in the 'view' op of hook_block to create a custom block.
  20. $form['#suffix'] = $tab_data['content'];
  21. }
  22.  
  23.  
  24. function nascsp_search_facet_block($response, $query) {
  25. $output = '';
  26. $env_id = apachesolr_default_environment();
  27.  
  28. $tab_options = apachesolr_get_index_bundles($env_id, 'node');
  29.  
  30. // Just so we can display all content types as tabs
  31. $tab_types = array_combine($tab_options, $tab_options);
  32.  
  33. // Add the default "All Result" Tab
  34. $all_result = array('all' => variable_get('nascsp_all_result', 'All Results'));
  35.  
  36. // Build a list of all available types
  37. $facets = array_merge($all_result, $tab_types);
  38.  
  39. $items = array();
  40. $new_query = clone $query;
  41.  
  42. // Store the currently active filter.
  43. $current_options = $new_query->getFilters('bundle');
  44.  
  45. $current_filter = isset($current_options[0]['#value']) ? $current_options[0]['#value'] : '';
  46.  
  47. $options = array();
  48. $options['attributes'] = array();
  49. // Set html to true to pass span in the text
  50. $options = array('html' => TRUE);
  51.  
  52. // remove the current filter now itself
  53. $new_query->removeFilter('bundle', $current_filter);
  54.  
  55. $bundle_filter = $new_query->getFilters('bundle');
  56.  
  57. // Set the options based on the current query.
  58. if (isset($bundle_filter[0]['#value'])) {
  59. $options['query']['f'][] = 'bundle:' . $bundle_filter[0]['#value'];
  60. }
  61.  
  62. // Current search path with the search keyword
  63. $path = $new_query->getPath();
  64.  
  65. // Lets loop through it and create tabs and search query
  66. foreach ($facets as $facet => $data) {
  67. unset($_GET['f']);
  68. if ($facet != 'all') {
  69. $options['query']['f'][0] = 'bundle:' . $facet;
  70. }
  71. $options['attributes']['class'] = ($facet == $current_filter) ? 'active' : '';
  72.  
  73. // Fetch the tab name
  74. $facet_text = ($facet == 'all') ? $data : node_type_get_name($facet);
  75.  
  76. // Generate solr links
  77. $link = apachesolr_l($facet_text, $path, $options);
  78.  
  79. // Build the array of tabs to pass to theme item list
  80. $items[$facet] = array('data' => $link);
  81.  
  82. // Assign class as well to maintain active and inactive tabs.
  83. if ((($facet == 'all') && empty($current_filter)) || ($facet == $current_filter)) {
  84. $items[$facet]['class'][] = 'active';
  85. }
  86. }
  87. if (is_array($items)) {
  88. $tabs = theme('item_list', array('items' => $items, 'title' => NULL, 'type' => 'ul', 'attributes' => array('class' => 'tabs primary clearfix')));
  89. $output .= '<div class="nascsp-solr-tabs tabs clearfix">' . $tabs . '</div>';
  90. }
  91. return array('content' => $output);
  92. }