1. 程式人生 > >solr7.3配置中文分析器和自定義業務域

solr7.3配置中文分析器和自定義業務域

1、拷貝jar包
[[email protected] 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/ 

[[email protected] 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

[[email protected]
~]# 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等幾個域,那我就可以如下配置。

[[email protected] ~]# 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:

[[email protected] ~]# /usr/local/solr/tomcat8/bin/shutdowm.sh

[[email protected] ~]# /usr/local/solr/tomcat8/bin/startup.sh

5、以下是新增域和中文分析結果: