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

相关推荐
运维行者_8 小时前
网络监控工具怎么选?从设备监控到智能运维的能力清单
运维·服务器·开发语言·网络·人工智能·支持向量机·php
星光开发者11 小时前
基于springboot智慧草场牛羊管理系统-计算机毕设【课程设计】50360
vue.js·spring boot·后端·mysql·php·课程设计·express
weixin_BYSJ198711 小时前
电竞先锋网站---附源码02032
java·vue.js·spring boot·python·django·tomcat·php
郑州光合科技余经理12 小时前
同城小程序开发:同一笔单在用户端和商家端各显示到哪
android·java·开发语言·前端·后端·uni-app·php
2401_8724187814 小时前
互联网公开信息检索完全指南:Google、Yandex、Wayback Machine、DNS、WHOIS、Shodan 等 OSINT 工具大全
开发语言·php
aixingpan14 小时前
aixingpan.cnAPI开发文档:api_docs_trichart_natal_solar_return_transit2接口指南
前端·php
狗凯之家源码网16 小时前
H5 棋牌对战系统源码深度评测与实战分析
php·游戏开发
李纲明1 天前
WordPress 后台登录马上被踢回登录页:Cookie 域、HTTPS、盐值和页面缓存怎么查
运维·缓存·https·php·wordpress·cookie
4SAPI1 天前
AI 数据分析工具大模型 API 选型指南
大数据·人工智能·架构·php·1024程序员节
f8979070701 天前
php升级之后切换到php8.2.35报pdo错误
php