1、环境搭建
前提:安装java 运行环境JDK https://blog.csdn.net/lxiansheng001/article/details/82558215
1.需要的安装包:apache-tomcat-7.0.47.tar.gz、solr-4.10.3.tgz.tgz
2.解压tomcat移动文件夹到/user/local/tomcat中
[root@localhost ~]# tar -zxf apache-tomcat-7.0.47.tar.gz [root@itcast ~]# cp -r apache-tomcat-7.0.47 /usr/local/tomcat
3.把solr的压缩包上传到服务器后并解压,
[root@localhost ~]# tar -zxf solr-4.10.3.tgz.tgz
文件夹目录:重要的是下图划线的两个子文件夹。
solr war需要放到tomcat的webapp目录下启动,SolrJ是java的客户端。
4.然后把/root/solr-4.10.3/dist/solr-4.10.3.war包部署到tomcat下。并改名为solr.war
[root@itcast dist]# cp solr-4.10.3.war /usr/local/tomcat/apache-tomcat-7.0.47/webapps/solr.war
5.解压war包。启动tomcat自动解压。然后关闭tomcat,删除war包
[root@itcast apache-tomcat-7.0.47]# bin/startup.sh
[root@itcast apache-tomcat-7.0.47]# bin/shutdown.sh
[root@itcast apache-tomcat-7.0.47]# rm -f webapps/solr.war
6.把/root/solr-4.10.3/example/lib/ext 目录下所有的jar包复制到solr工程中
[root@localhost ext]# cp * /usr/local/solr/tomcat/webapps/solr/WEB-INF/lib/
7.创建solrhome文件夹,该文件夹用来存放solr服务器所有配置文件。将/root/solr-4.10.3/example中的solr文件夹拷贝至solrhome
[root@localhost example]# cp -r solr /usr/local/solr/solrhome [root@itcast example]# cp * /usr/local/tomcat/apache-tomcat-7.0.47/webapps/solr/WEB-INF/lib/
8.在solr工程中的web.xml文件中指定solrhome的位置
9.启动tomcat
2、配置业务域
schema.xml中定义
- 商品Id
- 商品标题
- 商品卖点
- 商品价格
- 商品图片
- 分类名称
- 商品描述
创建对应的业务域。需要制定中文分析器。
创建步骤:
第一步:把中文分析器添加到工程中。
- 把IKAnalyzer2012FF_u1.jar添加到solr工程的lib目录下
-
[root@localhost IKAnalyzer2012FF_hf1]# cp IKAnalyzer2012FF_u1.jar /usr/local/tomcat/apache-tomcat-7.0.47/webapps/solr/WEB-INF/lib/
- 把扩展词典、配置文件放到solr工程的WEB-INF/classes目录下。
-
[root@localhost IKAnalyzer2012FF_hf1]# cp IKAnalyzer.cfg.xml ext_stopword.dic mydict.dic /usr/local/tomcat/apache-tomcat-7.0.47/webapps/solr/WEB-INF/classes
第二步:配置一个FieldType,制定使用IKAnalyzer
修改schema.xml文件
修改Solr的schema.xml文件,添加FieldType:
<fieldType name="text_ik" class="solr.TextField"> <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/> </fieldType> |
第三步:配置业务域,type制定使用自定义的FieldType。
设置业务系统Field
<field name="item_title" type="text_ik" indexed="true" stored="true"/> <field name="item_sell_point" type="text_ik" indexed="true" stored="true"/> <field name="item_price" type="long" indexed="true" stored="true"/> <field name="item_image" type="string" indexed="false" stored="true" /> <field name="item_category_name" type="string" indexed="true" stored="true" /> <field name="item_desc" type="text_ik" indexed="true" stored="false" />
<field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/> <copyField source="item_title" dest="item_keywords"/> <copyField source="item_sell_point" dest="item_keywords"/> <copyField source="item_category_name" dest="item_keywords"/> <copyField source="item_desc" dest="item_keywords"/> |
第四步:重启tomcat