当前位置:Gxlcms > 数据库问题 > Solr6 +mmseg4j+IK-Analyzer + SQLserver +DIH 完全配置

Solr6 +mmseg4j+IK-Analyzer + SQLserver +DIH 完全配置

时间:2021-07-01 10:21:17 帮助过:3人阅读

lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />  <!--同时兼容mmseg4j+ik中文分词器--> <lib dir="${solr.solr.home}/../tokenizers/mmseg4j" regex=".*\.jar" /> <lib dir="${solr.solr.home}/../tokenizers/IK-Analyzer" regex=".*\.jar" /> <lib dir="${solr.solr.home}/../sqlserver-jdbc" regex=".*\.jar" />

 

启用DIH,这里要注意这个功能依赖上面的  solr-dataimporthandler-xx.jar 配置

<!--启用DIH数据导入-->
  <requestHandler name="/dataimport" class="solr.DataImportHandler">
    <lst name="defaults">
      <str name="config">db-data-config.xml</str>
    </lst>
  </requestHandler>

 

以下是solr6里面,如果要手动修改schame.xml配置时要替换的,详见注释链接

<!-- 这里需要配置这个,https://cwiki.apache.org/confluence/display/solr/Schema+Factory+Definition+in+SolrConfig -->
<schemaFactory class="ClassicIndexSchemaFactory"/>

 

schema.xml 配置

<!--以下定义中文分词器及各自的词典配置-->
  <fieldtype name="mmseg4jComplex" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex"  dicPath="${solr.solr.home:}/../dict/mmseg4j" />
    </analyzer>
  </fieldtype>
  <fieldtype name="mmseg4jMaxWord" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word"  dicPath="${solr.solr.home:}/../dict/mmseg4j"  />
    </analyzer>
  </fieldtype>
  <fieldtype name="mmseg4jSimple" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="simple"  dicPath="${solr.solr.home:}/../dict/mmseg4j" />
    </analyzer>
  </fieldtype>

  <fieldType name="text_ik" class="solr.TextField">
    <!--索引时候的分词器-->
    <analyzer type="index">
      <tokenizer class="org.wltea.analyzer.util.IKTokenizerFactory" useSmart="true"/>
    </analyzer>
    <!--查询时候的分词器-->
    <analyzer type="query">
      <tokenizer class="org.wltea.analyzer.util.IKTokenizerFactory" useSmart="false"/>
    </analyzer>
  </fieldType>

 

 

db-data-config.xml

<dataConfig>
  <dataSource type="JdbcDataSource"
          driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"
          url="jdbc:sqlserver://127.0.0.1:1433;databaseName=xxdb;"
          user="dev"
          password="111111"
          batchSize="100" />
  <document>
    <entity name="product" query="select [id],[name],[brief],[description] from [products]"
            deltaQuery="select id from [products] where [lastmodificationtime] > ‘${dataimporter.last_index_time}‘">
      <field column="name" name="name" />
      <field column="brief" name="brief" />
      <field column="description" name="description" />
    </entity>
  </document>
</dataConfig>

 

以上配置内包含的路径均没有写死, 使用的占位符, 可用的占位符可以在 solr admin ui 的 dashboard JVM 栏看到

技术分享

 

!!!!!!!!!!!!!!!!!前方高能!!!!!!附件说明!!!!!!!!!!

点我下载附件,双击运行,如有报错,你来喷我啊,就是如此简单!

(一定要先配置PATH环境变量后再双击)

 

技术分享

 

Solr6 +mmseg4j+IK-Analyzer + SQLserver +DIH 完全配置

标签:

人气教程排行