本文的做法是一台服务器使用tomcat,运行solr,另一台服务器使用apache,负责和用户的交互与显示。

solr的php客户端也有好几个,本文选择了一个简单易用的, php-solr-client ,该项目的地址为 http://code.google.com/p/solr-php-client/,下载后解压放到apache的网站根目录。

下面是一个简单的查询例子:

// make sure browsers see this page as utf-8 encoded HTML

header('Content-Type: text/html; charset=utf-8');

$limit = 10;

$query = isset($_REQUEST['q']) ? $_REQUEST['q'] : false;

$results = false;

if ($query)

{

// The Apache Solr Client library should be on the include path

// which is usually most easily accomplished by placing in the

// same directory as this script ( . or current directory is a default

// php include path entry in the php.ini)

require_once('Apache/Solr/Service.php');

// create a new solr service instance - host, port, and webapp

// path (all defaults in this example)

$solr = new Apache_Solr_Service('localhost', 8983, '/solr/');

// if magic quotes is enabled then stripslashes will be needed

if (get_magic_quotes_gpc() == 1)

{

$query = stripslashes($query);

}

// in production code you'll always want to use a try /catch for any

// possible exceptions emitted by searching (i.e. connection

// problems or a query parsing error)

try

{

$results = $solr->search($query, 0, $limit);

}

catch (Exception $e)

{

// in production you'd probably log or email this error to an admin

// and then show a special message to the user but for this example

// we're going to show the full exception

die("

SEARCH EXCEPTION

{$e->__toString()}

");

}

}

?>

PHP Solr Client Example

Search:

// display results

if ($results)

{

$total = (int) $results->response->numFound;

$start = min(1, $total);

$end = min($limit, $total);

?>

Results <?php echo $start; ?> - <?php echo $end;?> of <?php echo $total; ?>:

// iterate result documents

foreach ($results->response->docs as $doc)

{

?>

// iterate document fields / values

foreach ($doc as $field => $value)

{

?>

<?php echo htmlspecialchars($field, ENT_NOQUOTES, 'utf-8'); ?><?php echo htmlspecialchars($value, ENT_NOQUOTES, 'utf-8'); ?>

}

?>

}

?>

}

?>

进行查询,如输入car ,结果如下

连接solr查询成功,再进行些美工上的优化,就能有像百度一样的查询界面了

solr php大小写,Solr 学习(6) —- Solr的PHP客户端相关推荐

  1. 基于Solr的空间搜索学习笔记

    基于Solr的空间搜索学习笔记 在Solr中基于空间地址查询主要围绕2个概念实现: (1) Cartesian Tiers 笛卡尔层 Cartesian Tiers是通过将一个平面地图的根据设定的层次 ...

  2. Solr及Spring-Data-Solr入门学习

    2019独角兽企业重金招聘Python工程师标准>>> Solr的安装与配置 多数搜索引擎应用都必须具有某种搜索功能,而搜索功能往往大量的消耗资源导致应用程序运行缓慢.为此,出现了各 ...

  3. Solr 企业级搜索应用服务器学习

    转自:https://blog.csdn.net/cs_hnu_scw/article/details/79388080 备注:学习Solr最好先了解一下Lucene的基本内容,不需要很熟,但是知道个 ...

  4. solr安装-tomcat+solrCloud构建稳健solr集群

    solrCloud的搭建可以有两种方式:使用solr内嵌的jetty来搭建:使用外部web容器tomcat来搭建.对于使用jett来搭建参考solr官方的手册照着做肯定ok,下面我主要讲的是如何使用t ...

  5. java solr 查询条件_05 java调用solr的api完成数据的查询

    本文将演示通过java代码完成solr数据的新增.修改与删除. 1.版本约束 CentOS7 工作站 solr-4.10.3 putty apache-tomcat-8.5.38 2.前提约束 3.新 ...

  6. solr 的maven_使用Maven运行Solr

    solr 的maven 使用Maven运行Solr Solr是一个开源搜索服务器,它是使用Lucene Core的索引和搜索功能构建的,它可以用于使用几乎任何编程语言来实现可扩展的搜索引擎. 尽管So ...

  7. solr mysql 自动同步_MongoDB和Solr的整合以及实现数据同步功能

    使用mongo-connector实现mongodb与solr数据同步: 1.solr搭建.这个我有记录,可以去找,这里不说了.(此次采用solr版本为4.7) 2.mongo搭建,要搭建集群,就是副 ...

  8. solr mysql 导入命令_Solr 07 - Solr从MySQL数据库中导入数据 (Solr DIH的使用示例)

    1 加入数据导入处理器的jar包 复制Solr解压后dist目录中的:solr-dataimporthandler-4.10.4.jar; 粘贴到contrib/dataimporthandler/l ...

  9. solr mysql 增量索引_基于Solr DIH实现MySQL表数据全量索引和增量索引

    实现MySQL表数据全量索引和增量索引,基于Solr DIH组件实现起来比较简单,只需要重复使用Solr的DIH(Data Import Handler)组件,对data-config.xml进行简单 ...

最新文章

  1. 360安全卫士 导致MySQL 5.0.24 自动关闭
  2. 1700 Crossing River
  3. pycharm 无法import PIL
  4. html垂直边距,html – Styling Bootstrap的btn-group-justified,添加边距和垂直尺寸
  5. VC中连接mdb数据库及其数据读取方法
  6. 计算机系统中字word的描述性定义是,计算机基础练习题1
  7. C#安装本地nupkg包
  8. 三角波傅立叶级数展开式matlab,常见波形的傅里叶级数展开式
  9. splay 模板 洛谷3369
  10. Abode Photoshop CC 2019之更换图片颜色
  11. servlet3 文件上传
  12. 认知突围_移动应用:突围
  13. 使用 ifconfig 查看本机 ip
  14. 自定义九宫格控件NineGridLayout ,实现微信朋友圈图片九宫格显示
  15. payjs 源码_GitHub - wlijie/payjs_test: PAYJS 小程序支付框架与示例
  16. [系统安全] 三十五.Procmon工具基本用法及文件进程、注册表查看
  17. 模拟火车站售票窗口,开启三个窗口售票,总票数为100张
  18. java 如何获取设备号_java – 如何获取android设备ID?
  19. 树莓派驱动OLED显示屏
  20. http状态码大全,从100-505状态码详情

热门文章

  1. 主干开发前要知道的,4错误认识+3优势
  2. 跑道防侵入,华为云ModelArts平台助力航空器识别AI模型开发
  3. Code Review 与 结对编程
  4. Mybatis的resultMap自定义映射
  5. Android笔记 pacth图形
  6. 艾蔻智能机器人怎么连接网络_艾蔻扫地机器人z3怎么用?
  7. LeetCode-1052:爱生气的书店老板
  8. WORD如何定义新项目符号?
  9. julia语言 调用 java_以编程方式/动态导入Julia中的模块
  10. python判断_轻松python文本专题-判断对象里面是否是类字符串(推荐使用isinstance(obj,str))...