配置Solr后台管理界面的数据导入(从MySQL中导入)
1.未配置之前
2.配置步骤:
1.在该目录下创建lib文件夹,经MySQL驱动包拷贝至此
再将以下目录下的两个jar包拷贝到lib文件夹
2.打开以下目录中的文件
在任意位置配置以下代码:
<!--配置导入-->
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
3.创建data-config.xml保存到solrhome\collection1\conf\目录下
<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/web15"
user="root"
password="123456" />
<document>
<entity name="product" query="SELECT pid,pname,shop_price,pdesc,pimage FROM product ">
<field column="pid" name="id" />
<field column="pname" name="product_name" />
<field column="shop_price" name="product_price" />
<field column="pdesc" name="product_description" />
<field column="pimage" name="product_picture" />
</entity>
</document></dataConfig>
4.在图示文件中定义相关field
<!--product-->
<field name="product_name" type="text_ik" indexed="true" stored="true" />
<field name="product_price" type="float" indexed="true" stored="true" />
<field name="product_description" type="text_ik" indexed="true" stored="false" />
<field name="product_picture" type="string" indexed="false" stored="true" />
<field name="product_keywords" type="text_ik" indexed="true" stored="false" multiValued="true" />
<copyField source="product_name" dest="product_keywords"/>
<copyField source="product_description" dest="product_keywords"/>
5.保存重启Tomcat后进入页面导入即可