搜索引擎2

solr文件搜索:
1、创建mycore

2、创建data-config.xml文件

在创建的mycore文件夹的conf文件夹下建立data-config.xml文件,具体参见文件夹下solr-8.x.0\example\example-DIH\solr\tika\conf\tika-data-config.xml的内容:

修改文件名myfile-config.xml,修改内容为:

<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
    <dataSource type="BinFileDataSource"/>
    <document>
        <entity name="file" processor="FileListEntityProcessor" dataSource="null"
                baseDir="/Users/sunpeizhen/Desktop/file" 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"表示对错误视而不见

3、修改solrconfig.xml文件

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

4、修改managed-schema(中文分词text_ik)

<field name="title" type="text_ik" indexed="true" stored="true"/>
<field name="text" type="text_ik" indexed="true" stored="true" omitNorms ="true"/>
<field name="author" type="string" indexed="true" stored="true"/>
<field name="fileSize" type="plong" indexed="true" stored="true"/>
<field name="fileLastModified" type="pdate" indexed="true" stored="true"/>
<field name="fileAbsolutePath" type="string" indexed="true" stored="true"/>

5、建立依赖的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下杂乱无章不好管理。

6、再修改solrconfig.xml文件
增加:

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

7、重启solr,打开浏览器,进入solr导入界面导入pdf、doc、xls、txt、html等数据

8、查询数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值