学习淘淘商城第五十一课(搜索功能切换到集群)
来源:互联网 发布:javascript实战 pdf 编辑:程序博客网 时间:2024/06/07 01:51
Solr单机版使用的是HttpSolrServer,集群版用的是CloudSolrServer,这两个类都是SolrServer的子类,我们在Dao层使用的SolrServer进行操作,从而我们可以不用改Dao层代码,只需要在Spring容器中切换单机版或集群版Solr即可。
现在我们到applicationContext-solr.xml文件当中配置一下Solr集群,如下图所示。
applicationContext-solr.xml文件当前的全部内容如下:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"> <!-- 配置单机版Solr --> <!-- <bean id="httpSolrServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer"> <constructor-arg name="baseURL" value="http://192.168.156.22:8080/solr/collection1"/> </bean> --> <!-- 集群版Solr连接 --> <bean id="cloudSolrServer" class="org.apache.solr.client.solrj.impl.CloudSolrServer"> <constructor-arg name="zkHost" value="192.168.156.23:2181,192.168.156.24:2181,192.168.156.25:2181"/> <property name="defaultCollection" value="collection2"/> </bean></beans>
由于还没有将数据库中的数据导入到集群版的索引库,因此我们需要到淘淘商城后台重新导入到索引库,不过在此之前,我们最好把上节课测试添加的那条数据给删除掉。如下图所示,我们点击"Documents",在Document Type类型中选择XML,在Document(s)中输入删除语句,然后点击提交按钮即可完成删除操作。
删除操作代码如下:
<delete><query>id:"11111"</query></delete><commit/>
下面我们把数据库中的数据导入到集群版索引库(整个过程耗费的时间比较长,一两分钟左右),如下图所示。
导入成功后,我们访问淘淘商城首页,并在搜索框中输入"金立M2017"并按回车进行搜索,发现可以正常搜索到结果,如下图所示。说明我们切换到集群版后,代码完全没问题。
0 0
- 学习淘淘商城第五十一课(搜索功能切换到集群)
- 淘淘商城系列——搜索功能切换到集群
- 学习淘淘商城第三十一课(Redis集群搭建)
- 学习淘淘商城第四十九课(搜索功能测试)
- 学习淘淘商城第四十四课(首页跳转到搜索页面及搜索实现分析)
- 学习淘淘商城第八十一课(SSO 系统分析)
- 学习淘淘商城第四十七课(搜索功能Service实现)
- 学习淘淘商城第四十八课(商品搜索功能Controller实现)
- 学习淘淘商城第五课(安装SVN服务器)
- 学习淘淘商城第五十二课(全局异常处理)
- 学习淘淘商城第五十四课(为何引入ActiveMQ)
- 学习淘淘商城第五十五课(ActiveMQ的安装)
- 学习淘淘商城第五十七课(接收Queue消息)
- 学习淘淘商城第三十二课(Redis集群测试)
- 学习淘淘商城第三十六课(Solr集群搭建)
- 学习淘淘商城第三十八课(搜索服务搭建)
- 学习淘淘商城第三十九课(搜索系统搭建)
- 学习淘淘商城第二十课(实现图片上传功能)
- 封装MemDC
- Spring各jar包详解
- java 多线程加锁-锁住了什么?
- Bootstrap常用的导航栏
- 高斯滤波器
- 学习淘淘商城第五十一课(搜索功能切换到集群)
- STC单片机测8路NTC测温度
- hdu2571-递推的思考-递推的逻辑
- pthread-消费者/生产者模型实现
- 为什么继承
- 单例模式的八种写法
- 01-端口映射作用
- js获取url及url参数的方法
- Spring Anotation