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

  • 相关阅读:
    10月15日模拟赛题解
    NOIp初赛题目整理
    【meet in the mid】【qbxt2019csp刷题班day1C】birthday
    【字符串】 manacher算法
    【border树】【P2375】动物园
    【border相关】【P3426】 [POI2005]SZA-Template
    【字符串】 Z-algorithm
    【字符串】KMP
    【神奇性质】【P5523】D [yLOI2019] 珍珠
    【线段树】【P5522】[yLOI2019] 棠梨煎雪
  • 原文地址:https://www.cnblogs.com/zy900406/p/6214548.html
Copyright © 2011-2022 走看看