最近用到Solr 这个全文检索工具,之前了解过 全文检索 lucene3 ,Solr在lucene的基础上有做了很多事情,方便了开发对lucene的使用
具体说明:
Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口。用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引;也可以通过Http Get操作提出查找请求,并得到XML格式的返回结果。
特点:
Solr是一个高性能,采用Java5开发,
基于Lucene的全文搜索服务器。同时对其进行了扩展,提供了比Lucene更为丰富的查询语言,同时实现了可配置、可扩展并对查询性能进行了优化,并且提供了一个完善的功能管理界面,是一款非常优秀的全文搜索引擎。
准备开始配置
1. 下载Solr5.2.1
解压后找到webapps 目录 把solr.war 放入tomcat webapps中解压
2.solr 用到的jar 导入到tomcat/weapps/solr/WEB-INF/lib/中
3.配置solr 下的web.xml 指定solr 的索引目录
在web.xml中增加行
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>D:/Program Files/solr_home</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
4.创建 solr 的索引与配置目录 solr_home
其中 new_core 为自定义目录,创建new_core 之后,在此目录中创建三个文件
data-config.xml 是数据库配置文件
schema.xml 字段与索引的配置
solrconfig.xml solr 相关配置
id
name
5.2.1
${solr.data.dir:}
${solr.lock.type:native}
true
${solr.ulog.dir:}
${solr.ulog.numVersionBuckets:65536}
${solr.autoCommit.maxTime:15000}
false
${solr.autoSoftCommit.maxTime:-1}
1024
true
20
200
false
2
explicit
10
explicit
json
true
name
{!xport}
xsort
false
query
data-config.xml
name
explicit
true
true
false
terms
*:*
其中 solrconfig.xml 需要配置数据源
5. 重新启动tomcat 打开 http://localhost:8080/solr
打开之后会让添加索引目录及配置
6.导入数据创建索引
7.测试查询