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

46 篇文章 7 订阅
45 篇文章 0 订阅

环境 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. 查询检查导入数据

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值