开发者

How do you determine if apachesolr has returned null results

开发者 https://www.devze.com 2023-01-15 13:50 出处:网络
开发者_开发知识库I am looking to execute some code if apachesolr has returned null results for the search query in a separate module.I am looking to leave the apachesolr module and acquia modules unto

开发者_开发知识库I am looking to execute some code if apachesolr has returned null results for the search query in a separate module. I am looking to leave the apachesolr module and acquia modules untouched.


I was looking for the same thing and found this comment very helpful:

http://drupal.org/node/877346#comment-3310554

Basically you just overwrite the theme_box function in template.php in your theme and check if the title and content matches the default "no results" template.

What I ended up with:

function mytheme_box($title, $content, $region = 'main') {
  if ($title == t('Your search yielded no results') &&
      $content == variable_get('apachesolr_search_noresults', apachesolr_search_noresults())) {
    if ($_GET['fuzzyhelp']) {
      // No results with fuzzy, go to landing page for no results. 
      drupal_goto('search_no_results'); 
    }

    // Rewrite search keys with fuzzy characters.
    $keys = array_map('trim', explode(' ', search_get_keys()));
    drupal_goto('search/apachesolr_search/'. implode('~ ', $keys). '~', 'fuzzyhelp=1');    
  }
  else if ($_GET['fuzzyhelp']) {
    // Tell user search was rewritten with fuzzy notations.
    drupal_set_message(t('Your exact search did not match any products and was broadened to include all possible matches.'));
  }

  return $content;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号