zoukankan      html  css  js  c++  java
  • solr5.2 mysql 增量索引

    前提:数据库里数据进行增删改操作时,相应的solr需要修改或者新建索引,之前从数据库中导入数据并创建索引的操作是全量创建,如果本身数据库数据量非常大,就需要增量创建索引

    1./usr/local/src/solr-5.2.1/server/solr/doc/conf 中solrconfig.xml,添加下面的内容

    这个是全量创建索引

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

     下面这个是增量

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

    2./usr/local/src/solr-5.2.1/server/solr/doc/conf中data-config.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <dataConfig>
        <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/documents" user="root" password="12345"/>
        <document>
            <entity name="doc_import" pk="id" query="select id,file_name,file_type,file_path,file_content from document">
                <field column="id" name="id" />
                <field column="file_name" name="file_name" />
                <field column="file_type" name="file_type" />
                <field column="file_path" name="file_path" />  
                <field column="file_content" name="file_content" />
            </entity>
            <deltaImportQuery>
            </deltaImportQuery>
        </document>
    </dataConfig>

    3./usr/local/src/solr-5.2.1/server/solr/doc/conf中delta-data-config.xml

    数据库中有一个create_time,默认是CURRENT_TIMESTAMP

    <dataConfig>  
        <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/documents" user="root" password="12345"/>
        <document name="doc">  
            <entity dataSource="jdbcDataSource" name="doc_import_add" 
              query="select id,file_name,file_type,file_path,file_content from document"  
              deltaImportQuery="select id,file_name,file_type,file_path,file_content from document where id= ${dih.delta.id}"  
              deltaQuery="select id,file_name,file_type,file_path,file_content from document where creat_time &gt; '${dih.last_index_time}'">  
                <field column="id" name="id" />
                <field column="file_name" name="file_name" />
                <field column="file_type" name="file_type" />
                <field column="file_path" name="file_path" />  
                <field column="file_content" name="file_content" />
            </entity>  
        </document>  
    </dataConfig>  

     4.重启solr

  • 相关阅读:
    猴子得到一堆桃,当天吃了一半之后,又多吃了1个。以后每天,猴子都吃了剩余的一半桃子之>后,又多吃一个。在第10天,只剩下1个桃子。输出这堆桃最初有多少个。
    打印9 9乘法表
    尝试实现一个管理系统, 名字和电话号分别用两个列表存储 =======通讯录管理系统======= 1.增加姓名和手机 2.删除姓名 3.修改手机 4.查询所有用户 5.根据姓名查找手机号 6.退出
    求结果
    背景流动
    1
    zuoye
    假期 作业1220
    python1217作业
    pythonzuoye20181212
  • 原文地址:https://www.cnblogs.com/zy900406/p/6214548.html
Copyright © 2011-2022 走看看