如何判断apachesolr是否返回了null结果

问题描述 投票:0回答:1

如果 apachesolr 在单独的模块中为搜索查询返回空结果,我希望执行一些代码。我希望保持 apachesolr 模块和 acquia 模块不变。

php solr drupal
1个回答
0
投票

我正在寻找同样的东西,发现这个评论非常有帮助:

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

基本上,您只需覆盖主题中 template.php 中的 theme_box 函数,并检查标题和内容是否与默认的“无结果”模板匹配。

我最终得到了什么:

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;
}
© www.soinside.com 2019 - 2024. All rights reserved.