Importing multi-valued field into Solr from mySQL using Solr Data Import Handler
http://stackoverflow.com/questions/20233837/importing-multi-valued-field-into-solr-from-mysql-using-solr-data-import-handler
Q:
We have the following two tables in our mySQL:
mysql> describe comment;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| blogpost_id | int(11) | YES | | NULL | |
| comment_text | varchar(256) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
mysql> describe comment_tags;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| comment_id | int(11) | YES | | NULL | |
| tag | varchar(80) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
Where each comment can have multiple tags. We can import the entire comment into Solr using the Data Import Handler. However I am not sure how to import the tags for each comment into a multivalued field defined the schema.xml for each comment document.
A:
You can also use GROUP_CONCAT with a Seperator(e.g " , ") and then try something like this :
<dataConfig>
<!-- dataSource is just an example. Included just for completeness. -->
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/db" user="root" password="root"/>
<document>
<entity name="comment" pk="id" query="SELECT *, group_concat(tags) as comment_tags FROM comment" transformer="RegexTransformer">
<field column="blogpost_id" name="blogpost_id"/>
<field column="comment_text" name="comment_text" />
<field column="tag" name="comment_tags" splitBy = "," />
</entity>
</document>
</dataConfig>
It'll increase the Performance and also will remove the Dependency of another query.
------------------
solr在DIH中常见的场景:
表A一条记录对应表B多条记录(明细)。
Importing multi-valued field into Solr from mySQL using Solr Data Import Handler的更多相关文章
- Solr 4.3.0 配置Data import handler时出错
启动solr的时候,居然出现了如下的错误: org.apache.solr.common.SolrException: RequestHandler init failure at or ...
- Importing/Indexing database (MySQL or SQL Server) in Solr using Data Import Handler--转载
原文地址:https://gist.github.com/maxivak/3e3ee1fca32f3949f052 Install Solr download and install Solr fro ...
- sorl6.0+jetty+mysql搭建solr服务
1.下载solr 官网:http://lucene.apache.org/solr/ 2.目录结构如下 3.启动solr(默认使用jetty部署) 在path路径下将 bin文件夹对应的目录加入,然后 ...
- Solr系列四:Solr(solrj 、索引API 、 结构化数据导入)
一.SolrJ介绍 1. SolrJ是什么? Solr提供的用于JAVA应用中访问solr服务API的客户端jar.在我们的应用中引入solrj: <dependency> <gro ...
- Solr与MySQL查询性能对比
本文简单对比下Solr与MySQL的查询性能速度. 测试数据量:10407608 Num Docs: 10407608 这里对MySQL的查询时间都包含了从MySQL Server获取数据的时 ...
- 使用Solr索引MySQL数据
环境搭建 1.到apache下载solr,地址:http://mirrors.hust.edu.cn/apache/lucene/solr/ 2.解压到某个目录 3.cd into D:\Solr\s ...
- Solr导入MySql中的数据
1.参照 http://www.cnblogs.com/luxh/p/5016894.html 部署好solr的环境 2.在solr_home下建立一个core_item目录 [root@iZ23ex ...
- solr导入mysql数据库
感谢ITeye的博主viskyzz分享的经验,笔者基本参考ta的方法.然而,解决中间出现的问题时也融入了自己的经验. 查看ta的原文请戳: http://tbwuming.iteye.com/blog ...
- Solr与Mysql简单集成
Solr与Mysql数据库的集成,实现全量索引.增量索引的创建. 基本原理很简单:在Solr项目中注册solr的DataImportHandler并配置Mysql数据源以及数据查询sql语句.当我们通 ...
随机推荐
- active在iphone上不起作用
在js中加一个空的touchstart函数 $(function(){ document.body.addEventListener('touchstart',function(){ }); 或在&l ...
- Java中的关键字
1)48个关键字:abstract.assert.boolean.break.byte.case.catch.char.class.continue.default.do.double.else.en ...
- C++学习(二十九)(C语言部分)之 顺序表
一.数据结构组织 存放数据的方式 精心选择的数据结构可以提升效率 数据结构 1.逻辑结构 一对多关系 父与子 一对一关系 排队中 多对多关系 两地的路线 2.存储结构 数据存放的位置关系 顺序存储数据 ...
- Map 知识整理
首先是HashMap的学习,理解散列的概念以及相关的实现,并且会学习HashMap的源码,理解为什么HashMap的速度如此之快. 声明:参考到的资料在下方列出. 1.<Java编程思想> ...
- C#获取IIS所有站点及虚拟目录和应用程序(包含名称及详细信息)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Go程序语言设计 (艾伦 A. A. 多诺万 著)
第1章 入门 (已看) 1.1 hello,world package main import "fmt" func main(){ fmt.Println("Hell ...
- Unity3D中常用的数据结构 学习
Array 1.数组存储在连续的内存上. 2.数组的元素都是相同类型或者类型的衍生类型 3.数组可以直接通过下标访问 ArrayList 1.不必在声明ArrayList时指定它的长度,这是由于Arr ...
- Pycharm主题设置以及导入方式
主题下载链接: http://www.themesmap.com/ pycharm -- 导入主题(theme) and 修改背景颜色(护眼色) 前情提要 众所周知,随着python语言的不断流行 ...
- IA64与x64的区别
说到IA-64与x86-64可能很多人会比较陌生.不知道你在下载系统的时候有没有注意过,有的地方标注了x86/64/ia-64全版本等字样.那x86/x64/ia-64都是什么东西的版本呢?答案就是C ...
- CSS如何实现”右部宽度固定,左部自适应“的布局
吃过晚饭后,开始刷前端笔试题,却遇到了一道CSS难题——使用CSS实现左部自适应.右部固定宽度为200px的布局.当时第一眼看到题目时,以为只是一道很简单的题目.不就是定义两个左浮动的div,右部的宽 ...