solr6.3从文档建立索引

开始此篇之前,我已经假定你已经学会了如何在Tomcat下部署Solr6.3啦。即启动Tomcat后你能看到Solr6.3的Web UI界面。不会的话可点击这里,此博客以此为基础展开,OK,下面直接进入正题

一、配置文件索引库

1、  新建core

我们新建一个solr的core,用于存储文件型索引,新建core的步骤请参考:

2、  准备jar

拷贝solr6.3发布包solr-6.3.0\contrib\extraction\lib下所有jar包到apache-tomcat-8.5.8\webapps\solr\WEB-INF\lib文件夹下。

3、新建tika-data-config.xml

<dataConfig> 
   <script><![CDATA[
        id = 1;
        function GenerateId(row) {
            row.put('id', (id ++).toFixed());
            return row;
        } 
        function WipOffHtml(row) {
            var file = row.get('file');
            row.put('file',file.substr(0,file.indexOf('.')));
            return row;
        }          
       ]]>
    </script> 
       <dataSource type="BinFileDataSource" />
           <document>
            <entity    name="files" dataSource="binary"    rootEntity="false"
               processor="FileListEntityProcessor"
            baseDir="文件所在路径" fileName=".*.(doc)|(pdf)|(xls)|(ppt)|(docx)"
            recursive="true">
                <field  column="fileAbsolutePath" name="filePath" />
                <field  column="fileSize" name="size" />
                <field  column="fileLastModified" name="lastModified" />
                <entity  name="documentImport"  processor="TikaEntityProcessor"  url="${files.fileAbsolutePath}" format="text" transformer="HTMLStripTransformer,RegexTransformer,script:GenerateId">
                    <field  column="file" name="fileName"/>
                    <field column="id" name="id" />
                    <field  column="Author" name="author" meta="true"/>
                    <field  column="title" name="title" meta="true"/>
                    <field  column="text" name="text" stripHTML="true" regex="\t|\r|\n|\s"
                    replaceWith="" />
                </entity>
              </entity>
           </document>
</dataConfig>
4、配置solrconfig.xml

    <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">  
      <lst name="defaults">  
         <str name="config">tika-data-config.xml</str>  
      </lst>  
 </requestHandler>  
5、配置managed-schema

   <field name="fileName" type="string" indexed="true" stored="true"/>
    <field name="filePath" type="string" indexed="true" stored="true"/>
    <field name="author" type="string" indexed="true" stored="true"/>
    <field name="title" type="string" indexed="true" stored="true"/>
    <field name="text" type="text_ik" indexed="true" stored="true"/>
注意:没有配置分词器的可参考 这里
6、启动tomcat,输入localhost:8080/solr/index.html,配置索引库



7、进行索引操作


8、测试查询



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值