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

来源:互联网 发布:redis可视化工具linux 编辑:程序博客网 时间:2024/04/30 11:57

陆续完善:

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 from product 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




原创粉丝点击