在Solr中使用数据导入处理程序索引Mysql数据库
我想使用数据导入处理程序在solr中索引mysql数据库 我做了两张桌子。第一个表保存文件的元数据在Solr中使用数据导入处理程序索引Mysql数据库,solr,lucene,solr4,Solr,Lucene,Solr4,我想使用数据导入处理程序在solr中索引mysql数据库 我做了两张桌子。第一个表保存文件的元数据 create table filemetadata ( id varchar(20) primary key , filename varchar(50), path varchar(200), size varchar(10), author varchar(50) ) ; +-------+-------------+---------+------+---------+ | id |
create table filemetadata (
id varchar(20) primary key ,
filename varchar(50),
path varchar(200),
size varchar(10),
author varchar(50)
) ;
+-------+-------------+---------+------+---------+
| id | filename | path | size | author |
+-------+-------------+---------+------+---------+
| 1 | abc.txt | c:\files| 2kb | eric |
+-------+-------------+---------+------+---------+
| 2 | xyz.docx | c:\files| 5kb | john |
+-------+-------------+---------+------+---------+
| 3 | pqr.txt |c:\files | 10kb | mike |
+-------+-------------+---------+------+---------+
第二个表包含关于上表中特定文件的“收藏夹”信息
create table filefav (
fid varchar(20) primary key ,
id varchar(20),
favouritedby varchar(300),
favouritedtime varchar(10),
FOREIGN KEY (id) REFERENCES filemetadata(id)
) ;
+--------+------+-----------------+----------------+
| fid | id | favouritedby | favouritedtime |
+--------+------+-----------------+----------------+
| 1 | 1 | ross | 22:30 |
+--------+------+-----------------+----------------+
| 2 | 1 | josh | 12:56 |
+--------+------+-----------------+----------------+
| 3 | 2 | johny | 03:03 |
+--------+------+-----------------+----------------+
| 4 | 2 | sean | 03:45 |
+--------+------+-----------------+----------------+
这里“id”是一个外键。第二个表显示了哪个人将哪个文档标记为他/她的最爱。例如,由id=1表示的abc.txt文件被ross和josh标记为最爱(见FavoritedBy列)
我想按如下方式索引这些文件:
每个文档应具有以下字段
id - to be taken from the first table filemetadata
filename - to be taken from the first table filemetadata
path - to be taken from the first table filemetadata
size - to be taken from the first table filemetadata
author - to be taken from the first table filemetadata
Favouritedby - this field should contain the names of all the people from table 2 filefav (from the favouritedby column) who like that particular file.
例如,索引文档1后应具有
id = 1
filename = abc.txt
path = c:\files
size = 2kb
author = eric
favourited by - ross , josh
我如何做到这一点
我编写了一个data-config.xml(它没有给出期望的结果),如下所示
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" user="root" password="root" />
<document name="filemetadata">
<entity name="restaurant" query="select * from filemetadata">
<field column="id" name="id" />
<entity name="filefav" query="select favouritedby from filefav where id=${filemetadata.id}">
<field column="favouritedby" name="favouritedby1" />
</entity>
<field column="filename" name="name1" />
<field column="path" name="path1" />
<field column="size" name="size1" />
<field column="author" name="author1" />
</entity>
</document>
</dataConfig>
有人能解释一下我是如何做到这一点的吗?当前结果的问题到底是什么?不必写下两个单独的查询,您可以进行连接并获得所有结果。在获得所有结果后,请在schema.xml中提及这些字段以建立索引并保留“id”“在唯一键中。我使用了连接,现在一切都很正常。谢谢