【发布时间】:2016-12-18 06:30:52
【问题描述】:
我有两张表客户和费用,由customer.id = fees.customerId 关联 1xn。费用还有另外两列,length 和 rate。我的 solr 配置是:
schema.xml
<schema name="customers" version="1.5">
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="id" type="long" indexed="true" stored="true"/>
<field name="customerName" type="string" indexed="false" stored="true"/>
<field name="length" type="int" indexed="false" stored="true" multiValued="true"/>
<field name="rate" type="float" indexed="false" stored="true" multiValued="true"/>
<uniqueKey>id</uniqueKey>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="string" class="solr.StrField"/>
</schema>
solr-data-config.xml
<entity name="customer" query="SELECT * FROM customers">
<field column="id" name="id"/>
<field column="name" name="customerName"/>
<entity name="fees" query="SELECT length, rate FROM fees WHERE id=${customer.id}">
<field column="length" name="length"/>
<field column="rate" name="rate"/>
</entity>
</entity>
问题在于,由于 Solr 的平面模式,length 和 rate 最终会“分离”为两个列表。我想要一个单对列表,所以一个列表<length, rate>。我目前的解决方案是将数据配置更改为
<entity name="fees" query="SELECT CONCAT(length, ';', rate) AS lengthRatePair FROM fees WHERE id=${customer.id}">
<field column="lengthRatePair" name="lengthRatePair"/>
</entity>
然后在客户端用 ; 分割字段。但我认为必须有一个更优雅的解决方案。
这样做的正确方法是什么?
【问题讨论】:
标签: xml solr schema parent-child