当前位置: 首页 > news >正文

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,否则原数据会被清除

http://www.lryc.cn/news/107278.html

相关文章:

  • leetcode 46. Permutations(排列)
  • 5、二叉树
  • Doris比MySQL快的原因
  • Prometheus + Grafana安装
  • 二十三种设计模式第二十一篇--解释器模式
  • PHP8的数据类型转换-PHP8知识详解
  • 2023 电赛 E 题 K210 方案
  • Python的正则表达式re模块的compile()方法有什么作用?
  • SQL 语句中 left join 后用 on 还是 where,区别大了!
  • uni-app 微信小程序自定义导航栏
  • 电缆故障检测仪技术参数
  • 固定资产管理软件
  • 云安全攻防(四)之 云原生技术
  • 线上通过Nginx部署前端工程,并且配置SSL
  • 直播预告 | 开源运维工具使用现状以及可持续产品的思考
  • GPT带我学-设计模式-工厂模式
  • Docker 安装 Tomcat
  • seata注册到nacos(docker)
  • ffmpeg综合应用示例(五)——多路视频合并(Linux版本)
  • Node.js-http模块服务端请求与响应操作,请求报文与响应报文
  • 除了PS,还有那些软件可以打开PSD文件
  • uniapp h5支付宝支付后端返回Form表单,前端如何处理
  • 【华秋干货铺】PCB布线技巧升级:高速信号篇
  • c#:ObservableCollection<T>的用法
  • Linux 端口号占用如何处理(使用命令处理)
  • ubuntu git操作记录设置ssh key
  • SystemVerilog数组参数传递及引用方法总结
  • Shell脚本学习-While循环1
  • docker for Windows, WSL2 ,Hyper-v的关系
  • SAS-数据集SQL水平合并