Solr DIH query 工作流
本文地址 http://www.cnblogs.com/jasonxuli/p/6491270.html
DataImportHandler (DIH) 支持全量数据导入和增量数据导入,主要有四个query:query,deltaQuery,parentDeltaQuery,deltaImportQuery。
大体概括就是:
想要以 Student 表为 document 的主体,Class表通过 Student.classId 于 Student 表关联,配置如下:
solr-data-config.xml:
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://dbhost/dbname?zeroDateTimeBehavior=convertToNull" user="dbuser"
password="dbpassword"/>
<document>
<entity name="student" transformer="RegexTransformer" pk="id"
query="select * from Student where deleted=0;"
deltaImportQuery="select * from Student where deleted=0 and id='${dih.delta.id}';"
deltaQuery="select id from Student where convert_tz(updatedAt, '+00:00', '+08:00') > '${dih.last_index_time}');"
deletedPkQuery="select id from Student where deleted=1;"> <field column="id" name="id"/>
<field column="name" name="name"/>
<field column="age" name="age"/>
<field column="classId" name="classId"/>
<field column="deleted" name="deleted"/>
<field column="createdAt" name="createdAt"/>
<field column="updatedAt" name="updatedAt"/> <entity name="class" transformer="RegexTransformer" pk="classId"
query="select * from Class where deleted=0 and id='${student.classId}'"
deltaQuery="select id from Class where convert_tz(updatedAt, '+00:00', '+08:00') > '${dih.last_index_time}'"
parentDeltaQuery="select id from Student where classId=${class.id}">
<field column="image" name="image"/>
<field column="banner" name="banner"/>
</entity>
</entity>
</document>
</dataConfig>
在上面配置中,student有四个SQL语句,class有三个SQL语句,其中只有 student.query 没有输入(参数)。
全量导入时:
1,从父实体 student 开始,执行 query 语句,获取到 student.id 等字段;
2,用这些 student.id 去组成 class.query 语句,获取 class。
增量导入时:
只要有任何父/子数据变化,就重新生成相关文档
1,从子实体 class 开始,执行 deltaQuery 语句,获取到 class.id;
2,用 class.id 组装 class parentDeltaQuery 语句,获取到 student.id;
3.1,用 student.id 组装 student deltaImportQuery 语句,获取到需要更新的 student;
3.2,用 class.id 组装 class deltaImportQuery 或者 class query,获取需要更新的 class ;
参考:https://wiki.apache.org/solr/DataImportHandler#Configuring_DataSources
----------------
备注:
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">solr-data-config.xml</str>
</lst>
<lst name="datasource">
<str name="driver">com.mysql.jdbc.Driver</str>
<str name="url">jdbc:mysql://localhost/test</str>
<str name="user">root</str>
<str name="password">root</str>
</lst>
</requestHandler>
Solr DIH query 工作流的更多相关文章
- Solr DIH JDBC 源码解析
Solr DIH 源码解析 DataImportHandler.handleRequestBody()中的importer.runCmd(requestParams, sw) if (DataImpo ...
- solr DIH 知识梳理
solr DIH 知识梳理 web.xml中listener配置 <listener> <listener-class>org.apache.solr.handler.data ...
- Solrj和Solr DIH索引效率对比分析
测试软件环境: 1.16G windows7 x64 32core cpu . 2.jdk 1.7 tomcat 6.x solr 4.8 数据库软件环境: 1.16G windows7 x64 ...
- Solr DIH dataconfig配置
1. 配置文件data-config.xml定义了数据库的基本配置,以及导出数据的映射规则,即导出数据库表中对应哪些字段的值,以及对特定字段的值做如何处理 </pre><p>& ...
- Solr 07 - Solr从MySQL数据库中导入数据 (Solr DIH的使用示例)
目录 1 加入数据导入处理器的jar包 2 加入数据库驱动包 3 配置solrconfig.xml文件 3.1 配置lib标签 - 加入驱动jar包 3.2 配置requestHandler标签 - ...
- Solr DIH导入出现 Data Config problem: 前言中不允许有内容 异常
Solr配置DIH导入时出现 “Data Config problem: 前言中不允许有内容.” 异常. <response> <lst name="responseHea ...
- Solr DIH以Mysql为数据源批量创建索引
演示使用solr管理后台,以mysql为数据源,批量建索引的方法 测试于:Solr 4.5.1, mmseg4j 1.9.1, Jdk 1.6.0_45, Tomcat 6.0.37 | CentOS ...
- solr系统query检索词特殊字符的处理
solr是基于 lucence开发的应用,如果query中带有非法字符串,结果很可能是检索出所有内容或者直接报错,所以你对用户的输入必须要先做处理.输入星号,能够检索出所有内容:输入加号,则会报错. ...
- [转]solr系统query检索词特殊字符的处理
原文地址:http://blog.csdn.net/wgw335363240/article/details/39889979 solr是基于 lucence开发的应用,如果query中带有非法字符串 ...
随机推荐
- JS基本动画
<style type="text/css"> .color_red { background: red; } div { position: absolute; to ...
- UVa 568 - Just the Facts
这道题和这几段牛代码让我见识了精简与高效.好好学习! http://blog.csdn.net/lyhvoyage/article/details/9307009
- LeetCode - Department Highest Salary
题目大概的意思是选出每个Department里工资最高的人的信息并组成相应的表信息 有几个值得注意的地方:1)使用group by语句时,前面的select语句后面的内容只能有两种情况一种是group ...
- 索引原理 B tree
数据库原理之-索引 背景介绍: 用数据库的时候经常有几个疑问: 1:为啥通过加索引就能提升数据的查询料率? 2:为啥加多了索引会导致增删改的效率变低? 3:为啥有的人能用好有的人用不好? 这些问题我们 ...
- console输出图案
探索天猫控制台下的图案是怎么制作的 通过它的源码找到以下代码(还原解压代码) 自己也照葫画瓢搞了个以前公司的logo
- 转载-解决使用httpClient 4.3.x登陆 https时的证书报错问题
今天在使用httpClient4.3.6模拟登陆https网站的时候出现了证书报错的问题,这是在开源中国社区里找到的可行的答案(原文链接:http://www.oschina.net/question ...
- C# 计算当前时间距离今晚00:00:00还有多少分多少秒
.net 计算当前时间距离今晚00:00:00还有多少分多少秒 string dateDiff = null;//获取当前时间 DateTime DateTime1 = DateTime.Now; / ...
- html to pdf小工具,支持evernote导出的html和firefox插件scrapbook
周末花了一天时间用wpf写了一个html转换为pdf的小工具. 已经在win7 32位 和win8 64两台机器上测试,目前基本可用,特拿来分享. 程序下载地址:http://pan.baidu.co ...
- Android通知栏的高度获取
public static int getStatusBarHeight(Context context){ Class<?> c = null; Object obj = null; F ...
- Optimal Milking---poj2112(多重匹配+Floyd+二分)
题目链接:http://poj.org/problem?id=2112 题意:K个挤奶器(编号1~K),每个挤奶器每天最多供M头奶牛.共有C头奶牛(编号K+1~K+C).挤奶器和奶牛间有不同长度的路. ...