PHP操作solr

1,php下载solr(索尔)扩展,phpinfo需要支持solr扩展.

2,安装 Solr。Solr 要求您的系统上有 Java。java --version,Java 的版本大于 1.6

3,下载solr,并安装 D:\solr。

开启solr命令:solr start

关闭solr命令:solr stop -all

4,代码

$option = array(

'hostname' => '127.0.0.1', // solr 服务器ip地址

'login' => '', // 用户名 (solr配置了才需要传)

'password' => '', // 密码 (solr配置了才需要传)

'port' => 8983, // 端口

'path' => 'solr/new_core' // 核心

);
s o l r C l i e n t = n e w S o l r C l i e n t ( solrClient = new SolrClient( solrClient=newSolrClient(option);

// 通过ping来判断是否连接成功

try {

//增加

res = solrClient->ping();

$sql = "select * from users";
c l i e n t = n e w S o l r C l i e n t ( client = new SolrClient( client=newSolrClient(option);

$doc = new SolrInputDocument();

$doc->addField('id', 111);

$doc->addField('name', 100);

$doc->addField('email', 'Hello Wolrd');

$response = c l i e n t − > a d d D o c u m e n t ( client->addDocument( client−>addDocument(doc);
c l i e n t − > c o m m i t ( ) ; / / p r i n t r ( client->commit(); // print_r( client−>commit();//printr(response);

//查询
c l i e n t = n e w S o l r C l i e n t ( client = new SolrClient( client=newSolrClient(option);

$query = new SolrQuery();

$query->setQuery('name:fangyan');

$query->setStart(0);

$query->setRows(50);

$query_response = c l i e n t − > q u e r y ( client->query( client−>query(query);

$response1 = q u e r y r e s p o n s e − > g e t R e s p o n s e ( ) ; / / e c h o " < p r e / > " ; / / p r i n t r ( query_response->getResponse(); // echo "<pre/>"; // print_r( queryresponse−>getResponse();//echo"<pre/>";//printr(response1);

//删除
c l i e n t = n e w S o l r C l i e n t ( client = new SolrClient( client=newSolrClient(option);

$client->deleteByQuery('id:111');

$result = c l i e n t − > c o m m i t ( ) ; e c h o " < p r e / > " ; p r i n t r ( client->commit(); echo "<pre/>"; print_r( client−>commit();echo"<pre/>";printr(result);

exit;

} catch (Exception KaTeX parse error: Expected '}', got 'EOF' at end of input: ... die(e->getMessage());

}

5,同步数据

http://localhost:8983/solr/new_core/dataimport?command=full-import\&commit=true\&clean=false

未将clean设置为false,实际使用时不能设置为true,否则原数据会被清除

相关推荐
Q_Q19632884751 小时前
python的电影院座位管理可视化数据分析系统
开发语言·spring boot·python·django·flask·node.js·php
Ashlee_code3 小时前
香港券商智能櫃台系統技術解決方案——融合跨境清算與AI風控,助力券商把握滬港雙市爆發機遇**
java·科技·金融·重构·架构·系统架构·php
nightunderblackcat4 小时前
进阶向:人物关系三元组,解锁人物关系网络的钥匙
开发语言·python·开源·php
向日葵.21 小时前
fastdds.ignore_local_endpoints 属性
服务器·网络·php
dog2501 天前
难以超越的 TCP AIMD
网络协议·tcp/ip·php
檀越剑指大厂1 天前
【Linux系列】如何在 Linux 服务器上快速获取公网
linux·服务器·php
Q_Q5110082851 天前
python的软件工程与项目管理课程组学习系统
spring boot·python·django·flask·node.js·php·软件工程
BingoGo1 天前
重新学习 PHP 目前短运算符 简化你得代码
后端·php
Fine姐1 天前
The Network Link Layer: 无线传感器中Delay Tolerant Networks – DTNs 延迟容忍网络
开发语言·网络·php·硬件架构
hotlinhao2 天前
php版的FormCreate使用注意事项
php·crmeb