美文网首页
使用Solr提供的web界面来导入索引库

使用Solr提供的web界面来导入索引库

作者: 泛空秋慕 | 来源:发表于2018-06-04 23:44 被阅读0次

    第一步:在需要导入数据库数据的solr实例目录下新建一个lib目录
    例如,/usr/local/solr/solr_home/collection1
    第二步:将solr解压目录中:'/usr/local/solr/solr-4.10.3/dist/' 目录下的
    'solr-dataimporthandler-4.10.3.jar'、'solr-dataimporthandler-extras-4.10.3.jar'文件复制到上一步创建的lib目录中,
    并将'mysql-connector-java-5.1.6.jar'数据库连接驱动包复制到lib目录下
    第三步:配置/usr/local/solr/solr_home/collection1/conf/solrconfig.mxl文件,添加一个requestHandler

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

    第四步:创建data-config.xml,保存到/usr/local/solr/solr_home/collection1/conf/目录下:

                <?xml version="1.0" encoding="UTF-8" ?>  
                <dataConfig>   
                    <dataSource type="JdbcDataSource"   
                              driver="com.mysql.jdbc.Driver"   
                              url="jdbc:mysql://localhost:3306/solr"   
                              user="root"   
                              password="root"/>   
                    <document>   
                        <entity name="product" query="SELECT pid,name,catalog_name,price,description,picture FROM products ">
                             <field column="pid" name="id"/> 
                             <field column="name" name="product_name"/> 
                             <field column="catalog_name" name="product_catalog_name"/> 
                             <field column="price" name="product_price"/> 
                             <field column="description" name="product_description"/> 
                             <field column="picture" name="product_picture"/> 
                        </entity>   
                    </document>   
    
                </dataConfig>
    
    

    注意:data-config.xml文件中的<entity>标签中用到的域,需要在/collection/conf/schema.xml 文件中预先定义.
    次例使用到的域如下:


    第五步:然后在web界面中选择定义好的RequestHandler---->"/dataimport"点击执行即可。

    相关文章

      网友评论

          本文标题:使用Solr提供的web界面来导入索引库

          本文链接:https://www.haomeiwen.com/subject/geuusftx.html