2011-10-13 31 views
1

我有這樣的「一網打盡」場在我的schema.xml:下面DynamicField名

<dynamicField name="*_s" type="string" indexed="true" stored="true" /> 

在這個例子中可以說我有有2個字段的表:「custom_value」和「custom_key 「這些價值觀:

custom_key 」的myKey「

custom_value: 」myvalue的「

我的目標是指數,有一個叫做場的文檔 」的myKey「 和值 」myvalue的「。我怎樣才能做到這一點?

<dataConfig> 
<dataSource type="JdbcDataSource" 
driver="com.mysql.jdbc.Driver" 
url="jdbc:mysql://localhost/MY_DB" 
user="MYUSER" 
password="MYPASS" 
batchSize="-1"/> 

<document> 
    <entity name="article" query="SELECT id, custom_key, custom_value FROM mytable"> 
     <field column="id" name="id"/> 
     <field column="custom_value" name=":::WHAT TO PUT HERE?:::_s"/> 
    </entity> 
</document> 

回答

1

發現了一個(哈克?)解決方案,這對於我而言的作品,我不會慶祝這個問題進行回答了幾天,櫃面有人想出了一個更清潔/更好的解決方案。

<dataConfig> 
    <script><![CDATA[ 
      function insertVariants(row)  { 
       row.put(row.get('custom_key') + '_custom', row.get('custom_value')); 
       return row; 
      } 
    ]]></script> 

    <dataSource type="JdbcDataSource" 
driver="com.mysql.jdbc.Driver" 
url="jdbc:mysql://localhost/MY_DB" 
user="MYUSER" 
password="MYPASS" 
batchSize="-1"/> 

<document> 
    <entity name="article" query="SELECT id, custom_key, custom_value FROM mytable" transformer="script:insertVariants"> 
     <field column="id" name="id"/> 
    </entity> 
</document> 

</dataConfig> 
+1

不是一個hacky的解決方案。這是正確的。 –