Solr6.5
Solr6.5下载下来之后,因为其本身包含jetty服务,不需要部署到tomcat中即可直接运行
1:进入目录D:\dev\solr-6.5.1\solr-6.5.1\bin,
新建两个bat文件:solr start -p 8984 / solr stop -p 8984
用于快捷开启关闭solr服务。
2:开启服务后,进入127.0.0.1:8984/solr/
3:这是是没有对应的core,需要我们手动新建,这里要注意几点,
D:\dev\solr-6.5.1\solr-6.5.1\server\solr 到这个目录下,手动创建你要新建的core,名称一致,这里用collection,
collection下新建data文件夹,同时将D:\dev\solr-6.5.1\solr-6.5.1\server\solr\configsets\basic_configs 下的config文件夹复制到collection。这时候在管理界面新建collection 即可顺利创建。
4:配置schema:这里配置需要注意的是
普通要增加的检索直接用:
<!-- 用到的field -->
<field name="columnId" type="long" indexed="true" stored="true" multiValued="false"/>
<field name="title" type="text_general" indexed="true" stored="true" multiValued="false"/>
<field name="titlePinyin" type="text_pinyin" indexed="true" stored="true" multiValued="false"/>
<field name="remark" type="text_general" indexed="true" stored="true" multiValued="false"/>
<field name="content" type="text_general" indexed="true" stored="true" multiValued="false"/>
<field name="siteId" type="long" indexed="true" stored="true" multiValued="false"/>
<field name="typeCode" type="text_general" indexed="true" stored="true" multiValued="false"/>
<field name="createDate" type="date" indexed="true" stored="true" />
<field name="typeId" type="long" indexed="true" stored="true" multiValued="false"/>
如果希望某一字段调用另外一个或者几个字段的内容,可以用到,dest是你要复制的对象,source是来源
<copyField source="title" dest="titlePinyin"/>
5:开启中文分词,首先把D:\dev\solr-6.5.1\solr-6.5.1\contrib\analysis-extras\lucene-libs 下 的solr自带的中文分词lucene-analyzers-smartcn-6.5.1.jar放到 D:\dev\solr-6.5.1\solr-6.5.1\server\solr-webapp\webapp\WEB-INF\lib下。
并下载pinyin4j的jar包pinyin4j,放到同样的位置
在schema中增加配置:
<fieldType name="text_pinyin" class="solr.TextField" positionIncrementGap="0">
<analyzer type="index">
<tokenizer class="solr.HMMChineseTokenizerFactory"/>
<filter class="com.shentong.search.analyzers.PinyinTransformTokenFilterFactory" minTermLenght="2" />
<filter class="com.shentong.search.analyzers.PinyinNGramTokenFilterFactory" minGram="1" maxGram="20" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.HMMChineseTokenizerFactory"/>
<filter class="com.shentong.search.analyzers.PinyinTransformTokenFilterFactory" minTermLenght="2" />
<filter class="com.shentong.search.analyzers.PinyinNGramTokenFilterFactory" minGram="1" maxGram="20" />
</analyzer>
</fieldType>
全部配置完毕,重启solr即可