Solr-DIH定义&导入多对多字段 [英] Solr - DIH define & import many-to-many field

查看:66
本文介绍了Solr-DIH定义&导入多对多字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个MySQL表bookauthor,它们具有many-to-many关系,通过book_author_mapper完成,其行包含列book_id/author_id.

I've two MySQL tables book and author, they have many-to-many relationship, done via book_author_mapper whose row contain columns book_id / author_id.

在Solr中,我有一个查询来获取书单,对于每本书,我需要为该书获取一个author_id数组.

In Solr, I have a query to get book list, for each book I need to get an array of author_id for the book.

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

Currently, I am thinking about to use a multi-valued field to store book ids.

我的问题是:

  • 如何定义字段,以及如何在DIH中编写SQL,看来需要多个SQL,对吗?谢谢.
  • 如果我不仅要获取author_id列表,还要获取每个author_idauthor_name,是否可以?
  • How to define the field, and how to write the SQL in DIH, it seems need multiple SQL, right? Thx.
  • If I want to get not just the author_id list, but as well as author_name for each author_id, is that possible?

推荐答案

查看doc&谷歌搜索,我已经解决了这个问题.

After viewing doc & googling, I have kind solved the problem.

  • 作者
  • book_author_map(这是多对多关系的中间表)
<?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是否必要?

  • TODOs

    • parentDeltaQuery It get pk of parent entity, but when it is called, and what is do? Is that necessary?
    • Does deltaQuery and parentDeltaQuery necessary in sub entity?
    • 这篇关于Solr-DIH定义&amp;导入多对多字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆