Solr-DIH定义&导入多对多字段 [英] Solr - DIH define & import many-to-many field
本文介绍了Solr-DIH定义&导入多对多字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个MySQL表book
和author
,它们具有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_id
的author_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 asauthor_name
for eachauthor_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&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') > '${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,但是在调用它时,该怎么办?那有必要吗? - 子实体中的
deltaQuery
和parentDeltaQuery
是否必要? parentDeltaQuery
It get pk of parent entity, but when it is called, and what is do? Is that necessary?- Does
deltaQuery
andparentDeltaQuery
necessary in sub entity?
TODOs
这篇关于Solr-DIH定义&导入多对多字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文