学习笔记:从0开始学习大数据-29. solr增加ik中文分词器并导入doc,pdf文档全文检索

环境 centos7,solr7.5.0

1. 新建core

从  solr-7.5.0/example/files/conf 作为配置文件模板,创建core,名为mycore

2.下载分词器

https://search.maven.org/search?q=g:com.github.magese 下载    ik-analyzer-7.5.0.jar

复制到 solr-7.5.0/server/solr-webapp/webapp/WEB-INF/lib 目录下

3. 修改 mycore/conf/managed-schema 文件,增加:

  <!-- ik分词器 --> 
<fieldType name="text_ik" class="solr.TextField"> 
<analyzer type="index"> 
<tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false" conf="ik.conf"/> <filter class="solr.LowerCaseFilterFactory"/> 
</analyzer> 
<analyzer type="query"> 
<tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true" conf="ik.conf"/> <filter class="solr.LowerCaseFilterFactory"/> 
</analyzer> 
</fieldType> 

并修改 ,原来的 text_simple 修改为新增的text_ik  即指定用新的分词器去对这几个字段内容分词。文本内容根据设置可存储在索引库,也可以不存储。

4.修改  mycore/conf/tika-data-config.xml 文件 全文:

<dataConfig>
  <dataSource type="BinFileDataSource"/>
  <document>
    <entity name="file" processor="FileListEntityProcessor" dataSource="null"
            baseDir="${solr.install.dir}/example/exampledocs" fileName=".(pdf)|(doc)|(docx)"
            rootEntity="false">

      <field column="file" name="id"/>

      <entity name="pdf" processor="TikaEntityProcessor"
              url="${file.fileAbsolutePath}" format="text">

        <field column="Author" name="author" meta="true"/>
        <!-- in the original PDF, the Author meta-field name is upper-cased,
          but in Solr schema it is lower-cased
         -->

        <field column="title" name="title" meta="true"/>
        <field column="dc:format" name="format" meta="true"/>

        <field column="text" name="text"/>

      </entity>
    </entity>
  </document>
</dataConfig>

注意 filename匹配或通配符指定扫描的文件类型,baseDir="${solr.install.dir}/example/exampledocs"  这个指定要导入的文件存放位置。

5. 测试

6.导入doc文档

把要导入的文档存放在指定目录,然后执行导入

7. 查询检查导入数据

猜你喜欢

转载自blog.csdn.net/oLinBSoft/article/details/85008308
今日推荐