再一次.. 我有 2 个表“博客”和“评论”。一个博客可以包含 n 条评论(博客 --1:n-- 评论)。最新我使用以下选择将数据插入到 solr 索引中:
<entity name="blog" dataSource="mssqlDatasource" pk="id"
transformer="ClobTransformer"
query="SELECT b.id, b.market, b.title AS blogTitle, b.message AS
blogMessage, c.message AS commentMessage, c.secondColumn
FROM blog b LEFT JOIN comment c ON b.id = c.source_id
AND c.source_type = 'blog'">
<field column="blogMessage" name="blogMessage" clob="true" />
<field column="commentMessage" name="commentMessage" clob="true" />
</entity>
索引结果如下所示:
<doc>
<str name="id">1</str>
<str name="market">12</str>
<str name="title">blog of title 1</str>
<str name="blogMessage">message of blog 1</str>
<str name="commentMessage">message of comment</str>
<str name="scondColumn">Im the second column from comment</str>
</doc>
<doc>
<str name="id">1</str>
<str name="market">12</str>
<str name="title">blog of title 1</str>
<str name="blogMessage">message of blog 1</str>
<str name="commentMessage">message of comment - Im the second comment</str>
<str name="scondColumn">Im the second column from comment</str>
</doc>
我会说这很愚蠢,因为我在同一个博客中获得了太多索引数据,只是评论不同。是否可以将“评论”设置为“子实体”,如下所示:
<entity name="blog" dataSource="mssqlDatasource" pk="id"
transformer="ClobTransformer"
query="SELECT b.id, b.market, b.title AS blogTitle, b.message AS
blogMessage
FROM blog b">
<field column="blogMessage" name="blogMessage" clob="true" />
<entity name="comment" dataSource="mssqlDatasource" pk="id"
transformer="ClobTransformer"
query="SELECT c.message as commentMessage, c.secondColumn
FROM comment c
WHERE c.source_id = ${blog.id}">
<field column="commentMessage" name="commentMessage" clob="true" />
</entity>
</entity>
那可能吗?结果如何(直到星期一才能测试)?