Solr - DIH定义&导入多对多字段

时间:2015-08-28 05:28:13

标签: mysql solr lucene dih

我有两个MySQL表bookauthor,他们有many-to-many关系,通过book_author_mapper完成,其行包含book_id / {列{1}}。

在Solr中,我有一个查询来获取图书清单,我需要为每本书获得一本author_id的图书。

目前,我正在考虑使用多值字段来存储图书ID。

我的问题是:

  • 如何定义字段,以及如何在DIH中编写SQL,似乎需要多个SQL,对吧? THX。
  • 如果我不仅要获得author_id列表,而且每个author_id都要author_name,那可能吗?

1 个答案:

答案 0 :(得分:1)

查看doc&谷歌搜索,我有点解决了这个问题。

  • 作者
  • book_author_map(这是多对多关系的中间表)

DIH配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/test?characterEncoding=utf8&amp;zeroDateTimeBehavior=convertToNull" user="root"
        password="123456" />
    <document>
        <entity name="book" pk="id"
            query="SELECT * FROM book where status = 0 limit 200000;"
            deltaImportQuery="SELECT * FROM book where status = 0 and id='${dih.delta.id}' limit 200000;"
            deltaQuery="select id from book where status = 0 and CONVERT_TZ(`update_date`, @@session.time_zone, '+00:00')  &gt; '${dih.last_index_time}'"
        >
            <entity name="author"
                query="SELECT au.cn_name as author_cn_name FROM author AS au JOIN book_author_map AS bam ON au.id = bam.author_id WHERE bam.book_id = ${book.id} limit 10;"
            >
                <field name="authors" column="author_cn_name" />
            </entity>
        </entity>
    </document>
</dataConfig>

字段定义

<field name="cn_name" type="textComplex" indexed="true" stored="true" />
<field name="en_name" type="textComplex" indexed="true" stored="true" />

<field name="status" type="int" indexed="true" stored="true" />

<field name="authors" type="textComplex" indexed="true" stored="true" multiValued="true" />

待办事项

  • parentDeltaQuery它获得了父实体的pk,但是当它被调用时,它是做什么的?这有必要吗?
  • 子实体需要deltaQueryparentDeltaQuery吗?
相关问题