zh-hongda

搜索引擎-Solr服务器导入doc文件

solr导入文件。

Solr服务器导入pdf/doc/txt/json/csv/xml文件

使用环境:

solr4.4.0

tomcat7.0.64

  1. 准备好需要导入的文件

  2. 将下列文件夹中的jar包导入到solr-server\solrhome\collection1\lib中。

    solr-4.4.0\dist

    solr-4.4.0\contrib\extraction\lib

  3. 在solr-server\solrhome\collection1\conf\solrconfig.xml中加入如下配置。

<!--该操作的意义在于,在solr中加入dataImportHandler插件-->
<requestHandler name="/dataimport" class="solr.DataImportHandler">
    <lst name="defaults">
        <str name="config">data-config.xml</str>
    </lst>
</requestHandler>
  1. 在D:\NLZ_HD\solr-server\solrhome\collection1\conf\data-config中加入如下配置,该文件夹需自己创建。
<!--该操作的意义在于,配置实体-->
<dataConfig>
  <dataSource type="BinFileDataSource"/>
  <document>
    <entity name="file" processor="FileListEntityProcessor" dataSource="null"
            baseDir="D:\NLZ_HD\solr-server\data\CNNOJIT" fileName=".(doc)|(pdf)|(docx)|(txt)|(csv)|(json)|(xml)|(pptx)|(pptx)|(ppt)|(xls)|(xlsx)"
            rootEntity="false">

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

        <field column="Author" name="file_author" meta="true"/>
        <field column="text" name="file_text"/>

      </entity>
    </entity>
  </document>
</dataConfig>
  1. 在solr-server\solrhome\collection1\conf\schema.xml中添加如下配置。
<!--该操作的意义在于,配置`data-config`需要的域-->
<!--自定义field开始-->
    <field name="file_text" type="text_ik_Synonym" indexed="true" stored="true"  multiValued="false"/>
    <field name="file_author" type="string" indexed="true" stored="true" multiValued="false"/>
    <field name="file_keyWord" type="text_ik_Synonym" indexed="true" stored="true" multiValued="true"/>
<!--自定义field结束  -->
  1. 配置完成,刷新页面,修改的配置即自动更新,然后再页面中导入数据即可。