1

假设我有这个配置:

数据导入处理程序-config.xml

<dataConfig>
    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1/solr" user="root" password="" batchSize="-1" />
    <document>
        <entity name="Book" query="select id, title from Book;">
            <field column="title" name="title" />
            <entity name="Author" query="select name, alias from Author where id='${Book.id}'">
                <field name="name" column="name" />
                <field name="alias" column="alias" />
            </entity>
        </entity>
    </document>
</dataConfig>

架构.xml

<fields>
    <field name="_version_" type="string" indexed="true" stored="true" multiValued="false" />
    <!-- general -->
    <field name="title" type="text_en" indexed="true" stored="true" multiValued="false" />
    <field name="name" type="text_en" indexed="true" stored="true" multiValued="true" />
    <field name="alias" type="boolean" indexed="true" stored="true" multiValued="true" />
</fields>

我从 Solr 得到的结果(xml 格式)如下所示:

<doc>
    <str name="title">Book with good title</str>
    <arr name="name">
        <str>John Doe 1</str>
        <str>John Doe 2</str>
        <str>John Doe 3</str>
    </arr>
    <arr name="alias">
        <bool>false</str>
        <bool>false</str>
        <bool>True</str>
    </arr>
</doc>

只要数据库中的所有文件都不是 NULL ,这没有任何问题。

当一些别名设置为 NULL 时,我得到了例如:

<doc>
    <str name="title">Book with good title</str>
    <arr name="name">
        <str>John Doe 1</str>
        <str>John Doe 2</str>
        <str>John Doe 3</str>
    </arr>
    <arr name="alias">
        <bool>True</str>
    </arr>
</doc>

但是我不知道哪个作者的别名被设置为空。

1) 是否可以在数据库中保留 NULL 并将数据导入 Solr 没有问题?

我认为以更“面向对象”的格式获取数据会更简单,如下所示:

<doc>
    <str name="title">Book with good title</str>
    <authors>
        <author>
            <str name="name">John Doe 1</str>
            <bool name="alias">false</bool>
        </author>
        <author>
            <str name="name">John Doe 2</str>
            <bool name="alias">false</bool>
        </author>
        <author>
            <str name="name">John Doe 3</str>
            <bool name="alias">True</bool>
        </author>
    <authors>
</doc>

2) 可以通过使用自定义 Solr 字段来实现“面向对象”的风格吗?

4

0 回答 0