Java开发环境之Solr

查看更多Java开发环境配置,请点击《Java开发环境配置大全》html

玖章:Solr安装教程

1)官网下载Solr安装包

http://lucene.apache.org/solr/downloads.htmljava

 

2)安装Solr5之前版本

2.1 安装Solrmysql

选择无中文目录,解压缩Sorl安装包即安装完成;web

 

2.2 复制Solr的war包到Tomcatsql

将D:\solr\solr-4.10.3\solr-4.10.3\example\webapps路径下的war包放入到Tomcat下的D:\apache-tomcat-8.5.4-windows-x64\apache-tomcat-8.5.4\webapps里面,启动tomcat,自动解压缩该war包,解压以后就能够删除该war包;数据库

 

2.3 复制Solr的jar包到Tomcat下的Sorlapache

复制D:\solr\solr-4.10.3\solr-4.10.3\example\lib\ext下的全部jar包,将它们放入到D:\apache-tomcat-8.5.4-windows-x64\apache-tomcat-8.5.4\webapps\solr\WEB-INF\lib里面;windows

复制D:\solr\solr-4.10.3\solr-4.10.3\example\resources下的log4j.properties,将它放入到D:\apache-tomcat-8.5.4-windows-x64\apache-tomcat-8.5.4\webapps\solr\WEB-INF\classes目录下,没有classes目录则建立;浏览器

复制D:\solr\solr-4.10.3\solr-4.10.3\dist下的solr-dataimporthandler-4.10.3.jar和solr-dataimporthandler-extras-4.10.3.jar,将它们放入到D:\apache-tomcat-8.5.4-windows-x64\apache-tomcat-8.5.4\webapps\solr\WEB-INF\lib下;tomcat

 

2.4 配置solrhome

将D:\solr\solr-4.10.3\solr-4.10.3\example\solr文件夹复制到无中文目录下,更名为solrhome;

找到D:\apache-tomcat-8.5.4-windows-x64\apache-tomcat-8.5.4\webapps\solr\WEB-INF下的web.xml,配置solrhome的路径:

<env-entry>

  <env-entry-name>solr/home</env-entry-name>

  <env-entry-value>D:\solr\solrhome</env-entry-value>

  <env-entry-type>java.lang.String</env-entry-type>

</env-entry>

 

3)下载IK分词器

GoogleCode开源项目:http://code.google.com/p/ik-analyzer/ GoogleCode SVN下载:http://ik-analyzer.googlecode.com/svn/trunk/

将下载好的IKAnalyzer2012FF_u1.jar放入到D:\apache-tomcat-8.5.4-windows-x64\apache-tomcat-8.5.4\webapps\solr\WEB-INF\lib下;

 

4)IK分词器设置

4.1 在D:\solr\sorlhome\collection1\conf中的schema.xml配置文件中添加:

<!-- IKAnalyzer(IK分词器配置) -->

<fieldType name="text_ik" class="solr.TextField">

  <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>

</fieldType>

 

4.2 添加词汇与禁用分词

在D:\apache-tomcat-8.5.4-windows-x64\apache-tomcat-8.5.4\webapps\solr\WEB-INF\classes目录下添加几个文件:

ext.dic:该文件存放新增词汇,好比我是高富帅,就能够把高富帅写进去分词

stopword.dic:该文件存放中止词汇,好比禁止我,你等分词

IKAnalyzer.cfg.xml,分词配置以下:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
  <comment>IK Analyzer 扩展配置</comment>
  <!--用户能够在这里配置本身的扩展字典 -->
  <entry key="ext_dict">ext.dic;</entry>
  <!--用户能够在这里配置本身的扩展中止词字典-->
  <entry key="ext_stopwords">stopword.dic;</entry>
</properties>

 

5)配置域

方式一:

找到D:\solr\solrhome\collection1\conf下的solrconfig.xml,在最后面加上:

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">

  <lst name="defaults">

    <str name="config">data-config.xml</str>

  </lst>

</requestHandler>

在solrconfig.xml同级目录下建立data-config.xml,内容配置以下:

<?xml version="1.0" encoding="UTF-8"?>

<dataConfig>

<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/lucene" user="root" password="admins"/>

<document>

  <entity name="product" query="SELECT pid,name,catalog_name,price,description,picture FROM products">

    <field column="pid" name="id"/>

    <field column="name" name="product_name"/>

    <field column="catalog_name" name="product_catalog_name"/>

    <field column="price" name="product_price"/>

    <field column="description" name="product_description"/>

    <field column="picture" name="product_picture"/>

  </entity>

</document>

</dataConfig>

 

方式二:

修改同目录下的schema.xml文件,在里面添加数据库对应的域,知识点比较多,能够百度配置教程。

 

6)启动

启动Tomcat,浏览器输入http:/localhost:8080/solr便可访问。

 

7)安装Solr5之后版本

在solr5之前solr的启动都有tomcat做为容器,可是从solr5之后solr内部集成jetty服务器,能够经过bin目录中脚本直接启动,就是从solr5之后跟solr4最大的区别是被发布成一个独立的应用。

选择无中文目录,解压缩Sorl安装包即安装完成;

cmd进入到安装包的bin目录下,执行命令solr start,即启动完成,默认端口8983,浏览器输入http:/localhost:8983便可访问。