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

  • 相关阅读:
    javascript基础案例解析
    Javascript正则
    Javascript数组
    JS函数
    数据类型转换
    flex弹性布局
    css基础5
    css基础4
    场景化支付对现有技术、业务、产品和风险产生深刻的影响
    场景化支付的关键技术
  • 原文地址:https://www.cnblogs.com/zy900406/p/6214548.html
Copyright © 2011-2022 走看看