第七步:连接数据库MySQL
拷jar包
docker cp /soft/mysql-connector-java-5.1.48.jar solr100:/opt/solr/server/solr-webapp/webapp/WEB-INF/lib docker cp /soft/solr-dataimporthandler-7.4.0.jar solr100:/opt/solr/server/solr-webapp/webapp/WEB-INF/lib docker cp /soft/solr-dataimporthandler-extras-7.4.0.jar solr100:/opt/solr/server/solr-webapp/webapp/WEB-INF/lib |
创建连接数据库的文件
cd /opt/solr/server/solr/solrhome/conf/
vim data-config.xml
<?xml version="1.0" encoding="UTF-8" ?> <dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://10.10.51.201:3306/s4" user="root" password="csit115"/> <document> <entity name="product" query="SELECT pid,name,catalog,catalog_name,price,description,picture FROM products "> <field column="pid" name="id"/> <field column="name" name="product_name"/> <field column="catalog" name="product_catalog"/> <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> |
修改配置文件
vim solrconfig.xml
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler> |
修改配置文件
vim managed-schema
<!-- 商品名称 --> <field name="product_name" type="text_ik" indexed="true" stored="true"/> <!-- 商品分类ID --> <field name="product_catalog" type="string" indexed="true" stored="true"/> <!-- 商品分类名称 --> <field name="product_catalog_name" type="string" indexed="true" stored="true"/> <!-- 商品价格 --> <field name="product_price" type="pdouble" default="0.0" indexed="true" stored="true"/> <!-- 商品描述 --> <field name="product_description" type="text_ik" indexed="true" stored="true"/> <!-- 商品图片地址 --> <field name="product_picture" type="string" indexed="false" stored="true"/> <!-- 复制到指定的keywords 组合域--> <field name="product_keywords" type="text_ik" indexed="true" stored="true" multiValued="true"/> <copyField source="product_description" dest="product_keywords"/> <copyField source="product_name" dest="product_keywords"/> |
退出重启
exit
Docker restart solr
解决方案
mysql5.x grant all privileges on *.* to 'root'@'%' identified by 'csit115'; mysql8 create user root@'%' identified by 'csit115'; grant all privileges on *.* to root@'%' with grant option; flush privileges; |
查所有
条件查q
如下:
删除索引库
<delete>
<query>*:*</query>
</delete>
</delete>