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

相关推荐
万岳软件开发小城6 小时前
教育APP/小程序开发标准版图:课程、题库、直播、学习一站式梳理
大数据·php·uniapp·在线教育系统源码·教育app开发·教育软件开发
q***9947 小时前
index.php 和 php
开发语言·php
未来之窗软件服务11 小时前
操作系统应用(三十三)php版本选择系统—东方仙盟筑基期
开发语言·php·仙盟创梦ide·东方仙盟·服务器推荐
济南壹软网络科技有限公司12 小时前
挑战全球高并发:壹软科技2025新版盲盒源码的“国际合规与弹性架构”解析
数据库·php·uniapp·盲盒源码
林戈的IT生涯13 小时前
windows 安装 composer 报SSL错误的问题 以及windows11上CMD命令下中文总乱码的问题解决
php·idea·composer·error14090086·cmd中文乱码·ja-netfilter
Evan芙16 小时前
Ubuntu 24.04 双网卡 bond0 绑定
ubuntu·postgresql·php
飞梦工作室16 小时前
PHP 中 php://input 的全面使用指南
android·开发语言·php
2401_8658548817 小时前
云服务器的IP是干嘛的?有什么作用?
服务器·tcp/ip·php
郑州光合科技余经理18 小时前
PHP技术栈:上门系统海外版开发与源码解析
java·开发语言·javascript·git·uni-app·php·uniapp
2501_9159214319 小时前
Fiddler抓包工具详解,HTTPHTTPS调试、代理配置与接口分析实战教程
服务器·ios·小程序·fiddler·uni-app·php·webview