2016-08-11 8 views
0

私は2テーブルの顧客と手数料を持っており、関連する1xnはcustomer.id = fees.customerIdです。料金には他の2つの列、lengthrateがあります。私の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のデータ-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のフラットスキーマ、lengthrateエンドアップ「のが解離していることです'を2つのリストとして互いに関連付けます。私はペアの単一のリストを持っていたいので、リスト<length, rate>。私の現在の解決策は、データ設定を

に変更することです。
<entity name="fees" query="SELECT CONCAT(length, ';', rate) AS lengthRatePair FROM fees WHERE id=${customer.id}"> 
    <field column="lengthRatePair" name="lengthRatePair"/> 
</entity> 

そして、クライアントサイドでフィールドを;で分割します。しかし、もっと洗練されたソリューションが必要だと思います。

これを行う正しい方法は何ですか?

答えて

1

Solr/Luceneは、複数値のフィールドにインデックスが付けられたときに値のシーケンスを保持するため、「disassociated」になっても最初の値lengthは最初の値rateに関連付けられます。両方のフィールドで同じ索引を使用して値を検索します。つまり、両方のフィールドのエントリ数を同じにすることが重要です。

あなたの選択したものに関係なく、あなたの他のソリューションもうまくいくでしょう。あなたのクエリレイヤーでそれを処理する必要があります。

子ドキュメントとして扱うと、余計なように聞こえることがあります。これは、ちょうど格納されている値の代わりに何かを与えることなく、ほとんどすべての面を複雑にします。

第3の解決策は、シリアライズされたjson構造をフィールドに追加してドキュメントにも添付することですが、最初の解決策を優先します。クエリー結果にマージするフィールドをクエリレイヤーに伝え、表示/表示レイヤーがプロパティの1つとして{length: .., rate: ...}ハッシュのオブジェクトを受け取るように、クエリレイヤーに構成設定を追加しました。

関連する問題