下载 PHP Solr Client:
http://code.google.com/p/solr-php-client/downloads/list
# wget http://solr-php-client.googlecode.com/files/SolrPhpClient.r22.2009-11-09.tgz
# tar xzvf SolrPhpClient.r22.2009-11-09.tgz
将文件移到web根目录下
# mv SolrPhpClient/Apache/ /home/www/
新建测试文件:
# cd /home/www
# vim sorltest.php
<?php
include("Apache/Solr/Service.php");
//连接Solr服务器
$solr = new Apache_Solr_service('localhost' , '8983' ,'/solr');
if( !$solr->ping() ) {
}
$data = array(
array(
'id' => 'EN80922032',
'name' => '男士打磨直筒休闲牛仔裤',
'brand' => 'ENERGIE',
'cat' => '牛仔裤',
'price' => '1870.00'
),
array(
'id' => 'EN70906025',
'name' => '品牌LOGO翻领拉链外套',
'brand' => 'ENERGIE',
'cat' => '外套',
'price' => '1680.00'
),
);
//添加索引数据
$documents = array();
foreach($data as $key => $value) {
}
$solr->addDocuments( $documents );
$solr->commit();
$solr->optimize();
//查询索引 $solr->search(字段:关键字 , 开始 ,每页显示,排序)
$offset = 0;
$limit = 10;
$sort = 'price asc';
$rs = $solr->search("brand:ENERGIE" , $offset ,$limit,array('sort' => $sort));
if($rs->response->numFound> 0) {
}
?>
查看:
http://localhost/solrtest.php
显示结果:
![](https://i-blog.csdnimg.cn/blog_migrate/cc09a850d467e71a629aa92b9015758c.png)