windows搭建solr5.4.1全文搜索引擎
一. 搭建solr服务器
1.下载solr http://archive.apache.org/dist/lucene/solr/5.4.1/ ,并解压
2.将..\solr-5.4.1\example\example-DIH目录下的solr文件夹复制到tomcat根目录下
3.将..\solr-5.4.1\server\solr-webapp目录下的webapp复制到tomcat\webapp下并命名为为solr
4.将..\solr-5.4.1\server\lib\ext目录下的所有jar包复制到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\lib下
5.将..\solr-5.4.1\dist目录下的solr-dataimporthandler-5.4.1.jar和solr-dataimporthandler-extras-5.4.1.jar复制到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\lib下
6.将..\solr-5.4.1\server\resources目录下的log4j.properties复制到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\classes下
如果没有classes文件,则创建一个
7.修改..\apache-tomcat-7.0.67\webapps\solr\WEB-INF目录下的web.xml
找到<env-entry>节点,删除注释,修改如下
- <span style="white-space:pre"> </span> <env-entry>
- <env-entry-name>solr/home</env-entry-name>
- <!--指向tomcat根目录下的solr文件夹 -->
- <env-entry-value>E:\apache-tomcat-7.0.67\solr</env-entry-value>
- <env-entry-type>java.lang.String</env-entry-type>
- </env-entry>
8.启动tomcat,访问 http://localhost:8080/solr/index.html#/, 出现如下页面说明搭建成功
二. 连接数据库
1.SQL配置
以MySQL为例,需要下载mysql-connector-Java-bin.jar到..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\lib目录下
http://dev.mysql.com/downloads/file/?id=462849
2.建立查询
进入在solr/home 目录下也就是本例的..\apache-tomcat-7.0.67\solr目录下
复制db得到collection
进入..\apache-tomcat-7.0.67\solr\collection目录下,编辑conf文件夹下的db-data-config.xml文件
- <dataConfig>
- <dataSourcedriverdataSourcedriver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost:3306/dubbotest?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"user="root" password="123456" />
- <document>
- <entity name="Student" query="select* from t_student"
- deltaQuery="select * fromt_student where last_modified > '${dataimporter.last_index_time}'"
- deltaImportQuery="SELECT* FROM t_student where last_modified >'${dataimporter.last_index_time}'">
- <field column="id"name="id" />
- <fieldcolumnfieldcolumn="name" name="name" />
- <fieldcolumnfieldcolumn="sex" name="sex" />
- <fieldcolumnfieldcolumn="userId" name="userid" />
- </entity>
- </document>
- </dataConfig>
编辑..\apache-tomcat-7.0.67\solr\collection\conf\schema.xml文件,在
<fieldname="" type="" indexed=""stored=""/>最后,添加
- <fieldnamefieldname="sex" type="string" indexed="text"stored="false"/>
- <fieldnamefieldname="userId" type="string" indexed="text"stored="false"/>
因为id和name字段已有,所以不添加。
3.重新启动tomcat,可以通过http://localhost:8080/solr/index.html
导入数据
查询数据
不同版本的solr,搭建会有不同,需要注意的是相应的jar包必须添加到
..\apache-tomcat-7.0.67\webapps\solr\WEB-INF\lib中
文章来源:http://blog.csdn.net/tgbsqliuying/article/details/51591039