mysql - Solr - DIH 定义和导入多对多字段

标签 mysql solr lucene dih

我有两个 MySQL 表 bookauthor,它们具有 多对多 关系,通过 book_author_mapper< 完成 其行包含列 book_id/author_id

在 Solr 中,我有一个获取图书列表的查询,对于每本书,我需要获取该书的 author_id 数组。

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

我的问题是:

  • 字段怎么定义,DIH里面的SQL怎么写,好像需要多条SQL吧?谢谢。
  • 如果我不仅要获取 author_id 列表,还要获取每个 author_idauthor_name,这可能吗?<

最佳答案

在查看文档和谷歌搜索后,我已经很好地解决了这个问题。

表格

  • 作者
  • 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 在子实体中是否必要?

关于mysql - Solr - DIH 定义和导入多对多字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32263896/

相关文章:

php - 试图加入 3 个 mysql 表,但我没有得到预期的结果。什么是错误?

java - 在检索图像时已为此响应调用 getOutputStream()

PHP/MYSQL 按 id 删除行

mysql - 选择具有 LIKE 条件的更大日期

mysql - 分类网站的数据库结构

elasticsearch - Elasticsearch索引映射更新

Lucene fieldNorm 相似度计算与查询时值的差异

mysql - Solr DataImportHandler MySQL 5.0 SELECT CONCAT 查询结果采用base64编码

Solr过滤器查询中多值字段的 bool 查询

c# - 如何使用 lucene.Net 进行正则表达式搜索