問題描述:如果在solr中添加數據庫中表數據:在solrhome中配置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,保存到solrhome下的一個solrcore---->collection1\conf\目錄下加入如下配置(
solrcore相當於mysql中一個數據庫
)
<?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>
這樣重啓tomcat--->選中collection1------>dataimport添加數據庫索引即可,但是如果添加另外一張表id也是從1開始,則繼續引入索引,會覆蓋原原有相同id的索引。想要解決這個問題
需要將這個sql語句進行如下修改即可 將原有的pid的sql語句改爲concat("book_",pid)
得到的結果爲
可以看出這樣在索引前加上前綴,則課解決id重複問題,就不會在覆蓋原有的索引,並且,此時數據庫的id並沒有改變,只是將索引id更改