文本主要介绍通过solr界面dataimport工具导入文件,包括pdf、doc、txt 、json、csv、xml等文件,看索引结果有什么不同。其实关键是managed-schema、solrconfig.xml和data-config.xml(需要创建)这三个配置文件。

    

  1、创建core

    启动solr,创建mycore

    solr start

    solr create -c mycore

    

  2、修改配置

   2.1、创建data-config.xml文件

    找到刚才创建的mycore文件夹,solr-6.6.0\server\solr\mycore,在下面的conf文件夹下建立data-config.xml文件,具体参见文件夹下solr-6.6.0\example\example-DIH\solr\tika\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"
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>

    修改如下:

<dataConfig>
<dataSource type="BinFileDataSource"/>
<document>
<entity name="file" processor="FileListEntityProcessor" dataSource="null"
baseDir="D:/work/Solr/Import" fileName=".(doc)|(pdf)|(docx)|(txt)|(csv)|(json)|(xml)|(pptx)|(pptx)|(ppt)|(xls)|(xlsx)"
rootEntity="false"> <field column="file" name="id"/>
<field column="fileSize" name="fileSize"/>
<field column="fileLastModified" name="fileLastModified"/>
<field column="fileLastModified" name="fileLastModified"/>
<field column="fileAbsolutePath" name="fileAbsolutePath"/>
<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="text" name="text"/> </entity>
</entity>
</document>
</dataConfig>

    

    fileName :(必选)使用正则表达式匹配文件

    baseDir : (必选) 文件目录

     recursive : 是否递归的获取文件,默认false

    rootEntity :在这里必须是false(除非你只想索引文件名)。在默认情况下,document元素下就是根实体了,如果没有根实体的话,直接在实体下面的实体将会被看做跟实体。

        对于根实体对应的数据库中返回的数据的每一行,solr都将生成一个document

     dataSource :如果你是用solr1.3,那就必须设为"null",因为它没使用任何dataSourde。不需要在solr1.4中指定它,它只是意味着我们不创建一个dataSource实例。在大多数情况下,

        只有一个DataSource(JdbcDataSource),当使用FileListEntityProcessor 的时候DataSource不是必须的

    processor:只有当datasource不是RDBMS时才是必须的

    onError :默认是"abort","skip"表示跳过当前文档,"continue"表示对错误视而不见

  2.2、修改solrconfig.xml文件

    增加如下内容:

    

 <requestHandler name="/dataimport" class="solr.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>

    

 

  2.3、修改managed-schema

    配置中文词库,具体参见:http://www.cnblogs.com/shaosks/p/7843218.html,增加如下内容:

<!-- mmseg4j fieldType-->
<fieldType name="text_mmseg4j_complex" class="solr.TextField" positionIncrementGap="100" >
<analyzer>
<tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex" />
</analyzer>
</fieldType>
<fieldType name="text_mmseg4j_maxword" class="solr.TextField" positionIncrementGap="100" >
<analyzer>
<tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word" />
</analyzer>
</fieldType>
<fieldType name="text_mmseg4j_simple" class="solr.TextField" positionIncrementGap="100" >
<analyzer>
<tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="simple" />
</analyzer>
</fieldType>

    

    增加以下三列,因为id列默认已经有了,不用创建,注意title和text两个字段的类型用了上面的text_mmseg4j_complex

 <field name="title" type="text_mmseg4j_complex" indexed="true" stored="true"/>
<field name="text" type="text_mmseg4j_complex" indexed="true" stored="true" omitNorms ="true"/>
<field name="author" type="string" indexed="true" stored="true"/>
<field name="fileSize" type="long" indexed="true" stored="true"/>
<field name="fileLastModified" type="date" indexed="true" stored="true"/>
<field name="fileAbsolutePath" type="string" indexed="true" stored="true"/>

  3、建立依赖的jar包

    在mycore下面建立lib文件夹, 然后往lib目录copy一些 DIH依赖的jar包,这些包要么在solr-6.6.0\contrib\extraction\lib下面,要么在solr-6.6.0\dist下面,

    样做的好处是每个core依赖的jar包都存放在各自core的子目录下分类存放,更方便管理,全部扔WEB-INF\lib下杂乱无章不好管理。如图:

    

    再修改solrconfig.xml文件

    增加

<lib dir="./lib" regex=".*\.jar"/>

    

  4、准备导入的pdf文件

    在solr-6.6.0\bin的同级文件夹solr-6.6.0\ImportData下面有要导入的文件:

    

  5、导入pdf

    重启solr,打开浏览器,进入 solr导入界面导入pdf数据

    

    

  6、查询数据

    

    从索引结果可以看出,每种不同的文件,所有文件的主要内容都集中到text这一个字段中。索引这种索引方式适合doc,pdf,txt,html等这种非结构化文档,而对json、csv和json这种结构化文档就不合适了。

    但是这种方式在索引docx格式的word文档发生问题,抽取不到数据,这个还不知道什么原因

    

    

  

    

    

    

solr6.6 导入 pdf/doc/txt/json/csv/xml文件的更多相关文章

  1. solr6.6 导入 文本(txt/json/xml/csv)文件

    参照:solr6.6 导入 pdf文件 重点就是三个配置文件 1.建立的data-config.xml 内容如下: <dataConfig> <dataSource name=&qu ...

  2. Java JSON、XML文件/字符串与Bean对象互转解析

    前言      在做web或者其他项目中,JSON与XML格式的数据是大家经常会碰见的2种.在与各种平台做数据对接的时候,JSON与XML格式也是基本的数据传递格式,本文主要简单的介绍JSON/XML ...

  3. 主流数据文件类型(.dat/.txt/.json/.csv)导入到python

    手写很累,复制的同学请点赞犒劳下在下哦 ^_^ 一.对于.CSV类型的数据 它们的数据导入都很简单 且看下面一顿操作: 我平时一般是读取整个文件,直接这样就可以了: import pandas as ...

  4. Python常用的数据文件存储的4种格式(txt/json/csv/excel)及操作Excel相关的第三方库(xlrd/xlwt/pandas/openpyxl)(2021最新版)

    序言:保存数据的方式各种各样,最简单的方式是直接保存为文本文件,如TXT.JSON.CSV等,除此之外Excel也是现在比较流行的存储格式,通过这篇文章你也将掌握通过一些第三方库(xlrd/xlwt/ ...

  5. 用php导入10W条+ 级别的csv大文件数据到mysql。导出10W+级别数据到csv文件

    转自:http://blog.csdn.net/think2me/article/details/12999907 1. 说说csv 和 Excel 这两者都是我们平时导出或者导入数据一般用到的载体. ...

  6. jquery Ajax获取本地json 以及xml文件

    $(function() { $("#Button1").click(function() { //按钮单击事件 //打开文件,并通过回调函数处理获取的数据 $.get(" ...

  7. 2018.10.5 hibernate导入约束,在Eclipse的xml文件实现自动提示

    打开Java Resources/Libraries/hibernate-core-5.3.1.Final.jar/org.hibernate/hibernate-mapping-3.0.dtd(hi ...

  8. 浏览器 chrome 360等 加载本地json 或者xml 文件

    添加启动参数 --allow-file-access-from-files 来自为知笔记(Wiz)

  9. 写文件的工具类,输出有格式的文件(txt、json/csv)

    import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io. ...

随机推荐

  1. C中的volatile关键字

    volatile提醒编译器它后面所定义的变量随时都有可能改变,因此编译后的程序每次需要存储或读取这个变量的时候,都会直接从变量地址中读取数据.如果没有volatile关键字,则编译器可能优化读取和存储 ...

  2. java中final修饰符的使用

    1.final修饰符的用法: final可以修饰变量,被final修饰的变量被赋初始值之后,不能对它重新赋值. final可以修饰方法,被final修饰的方法不能被重写. final可以修饰类,被fi ...

  3. IOS UITableViewUITableView小技巧--实现cell向左滑动删除,编辑等功能

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return Y ...

  4. Selenium2+python自动化26-js处理内嵌div滚动条【转载】

    前言 前面有篇专门用js解决了浏览器滚动条的问题,生活总是多姿多彩,有的滚动条就在页面上,这时候又得仰仗js大哥来解决啦. 一.内嵌滚动条 1.下面这张图就是内嵌div带有滚动条的样子,记住它的长相.

  5. k8s的deployment应用

    Kubernetes 通过各种 Controller 来管理 Pod 的生命周期.为了满足不同业务场景,Kubernetes 开发了 Deployment.ReplicaSet.DaemonSet.S ...

  6. docker从零开始 存储(四)tmpfs挂载

    使用tmpfs挂载 volume和bind mounts允许您在主机和容器之间共享文件,以便即使在容器停止后也可以保留数据. 如果你在Linux上运行Docker,你有第三个选择:tmpfs moun ...

  7. python之多并发socket(zz)

    本文转载自:http://www.cnblogs.com/bainianminguo/p/7337210.html 先看socket多并发的服务端的代码,这里是用多线程实现的多并发socketserv ...

  8. 如何理解reliability

    首先推荐看: https://wenku.baidu.com/view/f55f400c52ea551810a68746.html 复习一下均值方差 然后重点看: https://www.social ...

  9. The number of steps(概率dp)

    Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one r ...

  10. python判断一个数是否是2的几次幂

    判断一个数是不是2的几次幂,最简单粗暴的做法就是直接迭代除以2,这里有一个更好的方法,那就是采用位运算. 我们观察下面属于2的几次幂的数的变化规律,用2进制表示. 十进制 二进制 0 0 2 10 4 ...