Your search yielded no results

mizerydearia - September 26, 2009 - 20:01
Project:Faceted Search
Version:6.x-1.x-dev
Component:General
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

I am not sure if this issue is for views_customfield or faceted_search so I am posting to both.
I am using views_customfield module and faceted_search module.
I have a main view that works with faceted_search to display results of a particular node type.
In that main view I am using a field from views_customfield module.
The field is Customfield: PHP Code.
In that field I am using the Drupal function "views_embed_view" to embed a view within a view for each result.
If I limit the main view to display 5 results per page, in which one of the results displayed on the first page display the embedded view, the results appear fine.
If I increase the main view to display 20 results per page, "Your search yielded no results" appears.

I have been debugging for days, and after commenting every single function in faceted_search.module and faceted_search_ui.module I determined that the difference when viewing 5 results vs 20 results is that:

5 results: in theme_faceted_search_ui_stage_result() function, $pager_total_items[0] == 5
20 results: in theme_faceted_search_ui_stage_result() function, $pager_total_items[0] == 0 <-- this should be 20?

Again, I'm not sure where the issue lies, but I will continue debugging to learn more. For now, I am posting about this issue in case I do discover a bug or a misconfiguration so that if anyone else has a similar issue, they can potentially find a resolution as well.

#1

mizerydearia - September 26, 2009 - 20:24

http://drupal.org/node/588878

I believe this may be related to faceted_search because when viewing the Views Preview, 20 or 40+ results per page appear fine, however, when viewing in combination with faceted_search results, 5 results per page appears fine, but 20 or 40+ results per page yields No results.

I discovered in sites/all/modules/views/includes/view.inc:
In class view extends views_db_object { }
In function _build($key) { }
line $pager_total_items[$this->pager['element']] = $this->total_rows;

The first/main view calculates the correct 'total' results that should be displayed on the main faceted_search results page.

The view within a view with views_customfield, for each view that is created, affects this value, depending on how many results there are.

I discovered that on my results page when only displaying 5 results per page, since the last result's view within a view does have results of its own, the results are ultimately displayed, views results and views within a view results.

If I changed to 4 results per page, I would have discovered that there were no results, because the 4th result's view within a view has 0 results.

Therefore, I must learn a workaround so that each view within a view result does not affect the main/initial/first/primary view's results, and therefore affect ultimately displaying them or not. Is anyone able to help me discover a solution for this issue?

#2

mizerydearia - September 26, 2009 - 20:57

Specific to this module, theme_facted_search_ui_stage_results() function can't rely on if ($pager_total_items[0] > 0) { } in the case that Views Custom Fields embeds a view within a view. How can I detect only the main view's pager_total_items[0] value?

#3

mizerydearia - September 28, 2009 - 22:18

A work-around that seems to work for me:

Instead of relying on $pager_total_items[0] for the number of results, since the view within a view makes this value useless,
I modified a couple functions to pass on the correct results.

function faceted_search_ui_stage_results($env_id, $text = '') {
  // If the menu system has splitted the search text because of slashes, glue it back.
  if (func_num_args() > 2) {
    $args = func_get_args();
    $text .= '/'. implode('/', array_slice($args, 2));
  }

  $env = faceted_search_env_load($env_id);

  // Initialize the current search.
  $env->prepare($text);
  $env->ui_state['stage'] = 'results';

  if ($text) {
    // Log the search text.
    $path = faceted_search_ui_build_path($env, $env->ui_state, $text);
    watchdog('faceted_search', '%text.', array('%text' => $text), WATCHDOG_NOTICE, l(t('results'), $path));
  }

  faceted_search_ui_add_robots_directive($env);
  faceted_search_ui_add_css();

  // Collect the search results.
  $env->execute();
  $results_num = $env->_results_count;

  $style = faceted_search_ui_get_style($env);
  if (method_exists($style, 'format_results')) {
    $results = $style->format_results($env);
  }

  faceted_search_ui_set_title($env);
  $content = theme('faceted_search_ui_stage_results', $results, $style, $results_num);
  return theme('faceted_search_ui_page', $env, $content);
}

function theme_faceted_search_ui_stage_results($results, $style, $results_num) {
  global $pager_total, $pager_total_items, $pager_page_array;
  //if ($pager_total_items[0] > 0) {
  if ($results_num > 0) {
    $limit = $style->get_limit();
    $from = $pager_page_array[0] * $limit + 1;
    $to = min(($pager_page_array[0] + 1) * $limit, $pager_total_items[0]);
    $total = $pager_total_items[0];

    if ($total == 1) {
      $numbering = t('1 result');
    }
    elseif ($from == $to) {
      $numbering = t('Result @to of @total', array('@to' => $to, '@total' => $total));
    }
    elseif ($total <= $limit) {
      $numbering = t('@total results', array('@total' => $total));
    }
    else {
      $numbering = t('Results @from - @to of @total', array('@from' => $from, '@to' => $to, '@total' => $total));
    }

    $numbering = '<div class="faceted-search-numbering">'. $numbering .'</div>';
    return $numbering . theme('box', t('Results'), $results);
  }
  else {
    return theme('box', t('Your search yielded no results'), search_help('search#noresults', ''));
  }
}

 
 

Drupal is a registered trademark of Dries Buytaert.