源码:链接:http://pan.baidu.com/s/1qW5KNtM 密码:isa8
搭建完成后目录结构
solr
home
solr
bin
collection1
data
...
server
apache-tomcat-6.0.44
webapp
solr
WEB-INF
...
1、将solr-4.10.2\example\webapps\solr.war拷贝到solr\webapp后解压
2、将solr-4.10.2\example\solr拷贝到solr\home目录下
3、将apache-tomcat-6.0.44拷贝到solr\server目录下
4、新建solr/home/solr/data文件夹,修改文件solr\home\solr\collection1\conf\solrconfig.xml
<dataDir>${solr.data.dir:D:\...\solrSpace\solr\home\solr\data}</dataDir>
5、新建apache-tomcat-6.0.44\conf\Catalina\localhost\solr.xml文件5
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/solr" docBase="D:/boke/technology/lucene/solrSpace/solr/webapp/solr" reloadable="false">
<Environment name="solr/home" type="java.lang.String" value="D:/boke/technology/lucene/solrSpace/solr/home/solr" override="true" />
</Context>
6、启动报错,修改tomcat配置,利用log4j输出详细日志信息,见博文:http://my.oschina.net/sniperLi/blog/465298
7、将solr-4.10.4\example\lib\ext下的jar包,全部拷贝到solrSpace\solr\webapp\solr\WEB-INF\lib下。
加入IK分词器:
下载IKAnalyzer2012FF_u1.jar,将IKAnalyzer2012FF_u1.jar拷贝到solrSpace\solr\webapp\solr\WEB-INF\lib,
在schema.xml加入以下配置:
<!-- IKAnalyzer2012FF_u1 add by huangchm -->
<fieldType name="text_ik" class="solr.TextField">
<analyzer type="index" isMaxWordLength="false" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
<analyzer type="query" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/>
</fieldType>
加入停用词和搜狗词库:
拷贝IKAnalyzer.cfg.xml、stopword.dic、sougou.dic到solrSpace\solr\webapp\solr\WEB-INF\classes目录下,修改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">sougou.dic;</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords">stopword.dic;</entry>
</properties>
加入mmseg中文分词器 注意,solr4.8版本以上需要mmseg1.9以上才行,solr4.8之后需要1.7的jdk
添加jar包到lib中,solr\webapp\solr\WEB-INF\lib
technology\lucene\maven\mmseg4j-1.9.1\dist\mmseg4j-analysis-1.9.1.jar、mmseg4j-core-1.9.1.jar、mmseg4j-solr-1.9.1.jar
修改solr\home\solr\collection1\conf\schema.xml文件,加入fieldType
<!-- add by huangchm 添加mmseg4j分词器-->
<!-- dicPath 指定词库位置(每个MMSegTokenizerFactory可以指定不同的目录,当是相对目录时,是相对 solr.home 的目录) -->
<fieldType name="textComplex" class="solr.TextField" >
<analyzer>
<tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex" dicPath="dic"/>
</analyzer>
</fieldType>
<fieldType name="textMaxWord" class="solr.TextField" >
<analyzer>
<tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word" dicPath="dic"/>
</analyzer>
</fieldType>
<fieldType name="textSimple" class="solr.TextField" >
<analyzer>
<tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="simple" dicPath="dic"/>
</analyzer>
</fieldType>