时间:2021-07-01 10:21:17 帮助过:21人阅读
solr查询返回只是xml格式或是json格式,并不像我们平时使用google或百度时的那种漂亮清爽的界面,实际上solr只负责数据的查询和返回,并不负责显示,如果要生成如google那样的界面,还的借助solr的php客户端,通过客户端进行查询后,再通过php代码显示出来。
本文的做法是一台服务器使用tomcat,运行solr,另一台服务器使用apache,负责和用户的交互与显示。
?
solr的php客户端也有好几个,本文选择了一个简单易用的,?php-solr-client ,该项目的地址为?http://code.google.com/p/solr-php-client/,下载后解压放到apache的网站根目录。
?
?下面是一个简单的查询例子:
?
?
search($query, 0, $limit);
  }
  catch (Exception $e)
  {
    // in production you'd probably log or email this error to an admin
        // and then show a special message to the user but for this example
        // we're going to show the full exception
        die("SEARCH EXCEPTION {$e->__toString()}");
  }
}
?>
  
    PHP Solr Client Example 
  
  
    
response->numFound;
  $start = min(1, $total);
  $end = min($limit, $total);
?>
    Results  -  of :
    
response->docs as $doc)
  {
?>
      - 
        
 $value)
    {
?>
          
             
 
?
进行查询,如输入car ,结果如下?

连接solr查询成功,再进行些美工上的优化,就能有像百度一样的查询界面了