[root@localhost conf]# cp /usr/local/solr/solr-7.3.0/dist/solr-dataimporthandler-7.3.0.jar /usr/local/solr/tomcat8/webapps/solr/WEB-INF/lib/
[root@localhost conf]# cp /usr/local/solr/solr-7.3.0/contrib/analysis-extras/lucene-libs/* /usr/local/solr/tomcat8/webapps/solr/WEB-INF/lib/
2、添加TypeField
[root@localhost ~]# vim /usr/local/solr/solrhome/new_core/conf/managed-schema
在文件最后添加如下内容:
<!-- ChineseAnalyzer --> <fieldType name="text_ik" class="solr.TextField" positionIncrementGap="100"> <analyzer type="index"> <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/> </analyzer> <analyzer type="query"> <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/> </analyzer> </fieldType>
3、自定义业务域
业务域就是想让solr做某些工作的表的某些属性。比如我的tb_item表如下:
我想让solr在做搜索的时候只需用到tittle、sell_point、price等几个域,那我就可以如下配置。
[root@localhost ~]# vim /usr/local/solr/solrhome/new_core/conf/managed-schema在最后加下面内容:
<field name="item_title" type="text_ik" indexed="true" stored="true"/> <field name="item_sell_point" type="text_ik" indexed="true" stored="true"/> <field name="item_price" type="plong" indexed="true" stored="true"/> <field name="item_image" type="string" indexed="false" stored="true" /> <field name="item_category_name" type="string" indexed="true" stored="true" /> <field name="item_desc" type="text_ik" indexed="true" stored="false" /> <field name="item_keywords" type="text_ik" indexed="true" stored="false" multiValued="true"/> <copyField source="item_title" dest="item_keywords"/> <copyField source="item_sell_point" dest="item_keywords"/> <copyField source="item_category_name" dest="item_keywords"/> <copyField source="item_desc" dest="item_keywords"/>
4、重启Tomcat:
[root@localhost ~]# /usr/local/solr/tomcat8/bin/shutdowm.sh
[root@localhost ~]# /usr/local/solr/tomcat8/bin/startup.sh
5、以下是添加域和中文分析结果: