solr data-config.xml配置文件的见解mysql数据源

本文介绍如何使用Solr进行数据导入,并解决导入过程中遇到的问题,包括配置数据源、定义实体和查询条件等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

陆续完善:

http://localhost:8080/solr 进行DataImport时 找不到数据库中的entity

检查一下dataSource中的url

<dataSource type="JdbcDataSource" name="chishang" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://xxx.mysql.rds.aliyuncs.com/wjs?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8" user="xxxx" password="xxxx" />

一般都能用。如果不能用 将后面的编码格式去掉 试试看

<dataSource type="JdbcDataSource" name="chishang" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://xxxxx.mysql.rds.aliyuncs.com/wjs" user="xxxx" password="xxxx" />


data-config.xml配置文件

<entity name="product" dataSource="chishang"query="select id,'艺术品' cat,artists,content 'introduction',DATE_FORMAT(last_modified,'%Y-%m-%d')last_modified,focus,price,size,title,weight,proClassId,cast(concat('p',id) as char) as dockey fromproduct where deleted=false"


deltaImportQuery="select id,'艺术品' cat,artists,content 'introduction',DATE_FORMAT(last_modified,'%Y-%m-%d') last_modified,focus,price,size,title,weight,proClassId,cast(concat('p',id) as char) as dockey from product where cast(concat('p',id) as char)='${dih.delta.dockey}'"


deltaQuery="select cast(concat('p',id) as char) as dockey from product where cast(concat('p',id) as char) in (select cast(concat('p',id) as char) from product_class where
last_modified>'${dih.last_index_time}') or last_modified &gt; '${dih.last_index_time}'"> //注意这里才是entity的结束括号

<entity name="product_picture" query="select path 'icon' from product_picture_tbl where productId='${product.id}'"> </entity>


</entity>

解释说明
(1):query中select哪些字段 a.为产品product表中哪些字段需要作为搜索的内容
b.内嵌的entity中需要用到的字段如:<entity name="product_picture"query="select path 'icon' from product_picture_tbl where
productId='${product. id }'"></entity> 中的'${product.id}'中的 id ,必须在query 进行select的时候筛选 出来。


(2):deltaQuery解释:从product表(或者product中内嵌的entity)中查找last_modifed时间大于solr配置文件dataimport.properties中的最 后一次修改时间。把需要修改的id都查找出来。例如:
deltaQuery="select cast(concat('p',id) as char) as dockey from product where cast(concat('p',id) as char) in (select cast(concat('p',id) as char) from product_class where
last_modified>'${dih.last_index_time}') or last_modified &gt; '${dih.last_index_time}'"> product表中的last_modified>'${dih.last_index_time} 同时product_class表中的

last_modified>'${dih.last_index_time} 可能有点难理解,可以看solr官网。


(3):deltaImportQuery的理解

deltaImportQuery="select id,'艺术品' cat,artists,content 'introduction',DATE_FORMAT(last_modified,'%Y-%m-%d') last_modified,focus,price,size,title,weight,proClassId,cast(concat('p',id) as char) as dockey from product wherecast(concat('p',id) as char)='${dih.delta.dockey}'"


cast(concat('p',id) as char) 为最外层entity的主键
${dih.delta.dockey} 中的dockey为deltaquery查询时的主键


deltaQuery是用来确认有没有记录要导入的,一般只返回记录ID.
deltaImportQuery是已经确认有记录要导入的情况下,用来获取要导入的记录所有属性的,是依据deltaQuery的ID来确定的。

意味着:deltaQuery返回了多少个ID,就会执行多少次deltaImportQuery




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值