使用 Solr 数据导入处理程序将多值字段从 mySQL 导入 Solr
我们的 mySQL 中有以下两个表:
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 | |
+------------+-------------+------+-----+---------+-------+
每个评论可以有多个标签.我们可以使用数据导入处理程序将整个注释导入 Solr.但是,我不确定如何将每个评论的标签导入为每个评论文档定义 schema.xml 的多值字段.
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.
请指教.谢谢
推荐答案
试试这个:
<dataConfig>
<!-- dataSource is just an example. Included just for completeness. -->
<dataSource batchSize="500" type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/my-database" user="root" password="somethinglong1283"/>
<document>
<entity name="comment" pk="id" query="SELECT * FROM comment">
<field column="blogpost_id" name="blogpost_id"/>
<field column="comment_text" name="comment_text" />
<entity name="comment_tags" pk="comment_id" query="SELECT * FROM comment_tags WHERE comment_id='${comment.id}'">
<field column="tag" name="tag" />
</entity>
</entity>
</document>
相关文章