zoukankan      html  css  js  c++  java
  • (八) 通过jdbc对对solr进行数据的增量导入

    接着上一节的内容,假如我们从mysql中导入进solr中的数据量比较大,所耗时比较长,如果每次都是进行完全导入,肯定是不好的做法,因此可以采取增量导入的方式,solr的相关配置如下所示:

    在 schema.xml的域信息定义如下:

    <field name="id"     type="string"   indexed="true"  stored="true"  required="true"/>
     <field name="title" type="text" indexed="true" stored="true"/>
     <field name="catname" type="string" stored="true"/>

    solrconfig.xml

    <requestHandler name="/import" class="org.apache.solr.handler.dataimport.DataImportHandler">
     <lst name="defaults">
        <str name="config">db-data-config.xml</str>
     </lst>
     </requestHandler>

    db-data-config.xml 的配置如下:

    <dataConfig>
        <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/blog" user="root" password="admin"/>
        <document>
            <entity name="article" query="select id,title,catid from article" deltaImportQuery="select id,title,catid from article where id='${dataimporter.delta.id}'" deltaQuery="select id from article where cdate&gt; '${dataimporter.last_index_time}'">
                <field column="id" name="id" />
                <field column="title" name="title" />
                <field column="title" name="suggest"/>
                <entity name="category" query="select catname from category where id=${article.catid}">
                    <field column="catname" name="catname"/>
                </entity>
            </entity>
        </document>
    </dataConfig>

    与上一节相比,db-data-config.xml 文件的配置有所变化:

    在最外层的entity节点里面新增了两个属性节点,deltaImportQuery 与deltaQuery, deltaImportQuery使用deltaQuery返回的文章id作为查询条件,然后进行增量导入。

    dataimporter.last_index_time  :存储在文件import.properties 中

    #Sat Jun 16 19:30:20 CST 2012
    last_index_time=2012-06-16 19\:30\:19
    article.last_index_time=2012-06-16 19\:30\:19
    dataimporter.delta.id:deltaImportQuery 返回的id

     

  • 相关阅读:
    Python 正则表达式匹配两个指定字符串中间的内容
    Switch Case 和 If Else
    MYSQL LETT/RIGHT/INNER/FUll JOIN 注意事项
    MYSQL 批处理 Packet for query is too large
    Junit单元测试不支持多线程
    postman中 form-data、x-www-form-urlencoded、raw、binary的区别
    一个项目中:只能存在一个 WebMvcConfigurationSupport (添加swagger坑)
    Nginx 转发特点URL到指定服务
    基于UDP协议的程序设计
    TcpClient类与TcpListener类
  • 原文地址:https://www.cnblogs.com/xiazh/p/2551790.html
Copyright © 2011-2022 走看看