赞
踩
将连接数据库的jar包和solr\dist下的dataimporthandler架包复制到solr\server\solr-webapp\webapp\WEB-INF\lib下
在goods(core名)/conf文件夹下创建mysql-db文件夹,然后在mysql-db文件夹中创建data-config.xml文件,文件中添加如下内容
<?xml version="1.0" encoding="utf-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/sc"
user="root"
password="root"
/>
<document>
<!--sql配置-->
<entity name="goods" query="select goods_id,goods_name,sales_price,goods_img,cid from goods">
<!--column为数据库中列名,name为属性名-->
<field column="goods_id" name="id" />
<field column="goods_name" name="goodsName" />
<field column="sales_price" name="salesPrice" />
<field column="goods_img" name="goodsImg" />
<field column="cid" name="cid" />
</entity>
</document>
</dataConfig>
在managed-schema.xml文件中添加
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<!-- docValues are enabled by default for long type so we don't need to index the version field -->
<field name="_version_" type="plong" indexed="false" stored="false"/>
<field name="_root_" type="string" indexed="true" stored="false" docValues="false" />
<!--字段名与第二步相对应,text_ik为查找的字段-->
<field name="goodsName" type="text_ik" indexed="true" stored="true" multiValued="false" />
<field name="salesPrice" type="plong" indexed="true" stored="true" multiValued="false" />
<field name="goodsImg" type="string" indexed="true" stored="true" multiValued="false" />
<field name="cid" type="string" indexed="true" stored="true" multiValued="false" />
注意: id,version,root 不能删除,text 不需要 可以删除
在solrconfig.xml文件中添加
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">mysql-db/data-config.xml</str>
</lst>
</requestHandler>
重启命令:solr restart -p 8983
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。