您的位置:首页 > 数据库

Lucene之Solr导入数据库中的数据(九)

2017-04-01 11:42 381 查看


一、介绍

1. 找到我们的solrHome的位置, 并且知道其中的一个collection,如下:



2. 将下面的两个jar包放在lib目录下面:



3. 将数据库的驱动包也放在lib目录下面:



4. 配置solrconfig.xml文件,添加一个requestHandler。

在E:\temp\solrhome\collection1\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>

5. 创建一个data-config.xml,保存到collection1\conf\目录下:

<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/lucene"
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>
6. 在collection1\conf目录下,找到schema.xml,在里面添加配置:

<field name="product_name" type="string" indexed="true" stored="true"></field>
<field name="product_price" type="float" indexed="true" stored="true"></field>
<field name="product_description" type="string" indexed="true" stored="false"></field>
<field name="product_catalog_name" type="string" indexed="true" stored="true"></field>
<field name="product_picture" type="string" indexed="false" stored="true"></field>
7. 重启tomcat.



8. 点击“execute”按钮导入数据。

导入数据前会先清空索引库,然后再导入。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: