所以我有一些數據,我想放入Solr的索引標準化表格,本與MySQL的多行映射項目到Solr
+----+--------------+--------------+---------+
| id | name | attribute | value |
+----+--------------+--------------+---------+
| 1 | Apple | color | green |
| 1 | Apple | shape | round |
| 1 | Apple | origin | Belgium |
| 2 | Motorbike | type | fast |
| 2 | Motorbike | nr of wheels | 2 |
| 3 | Office chair | color | grayish |
| 3 | Office chair | spins | yes |
+----+--------------+--------------+---------+
一些類似於現在,我寧願它被索引爲每個唯一ID(即項目)的一個文檔。但是,我將不得不將n個屬性合併到一個文檔中。要做到這一點,我需要用我的dataConfig做一些魔術。但是,我如何存儲和映射n個字段?這是使用動態字段的正確時機嗎?
這是我目前的嘗試。我很確定這是無效的。
<dataConfig>
<dataSource
type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/mystuff"
user="root" password="*****"/>
<document name="doc">
<entity name="t1" query="select * from item_to_id_table">
<field name="id" column="id"/>
<field name="name" column="name"/>
<entity name="t2" query="select * from my_flat_table"
cacheKey="t1.id"
cacheLookup="t2.id">
<!-- alt 1 -->
<field name="$(t2.attribute)" column="value" />
<!-- alt 2 -->
<entity name="properties" query="select property, value from t2"
cacheKey="$(t2.attribute)"
cacheLookup="property">
<field name="$(properties.property)" column="value" />
</entity>
</entity>
</entity>
</document>
</dataConfig>
我敢肯定,無論是兩個備選方案是有效的,我會盡快嘗試出來,除非我能想出更好的東西。也許腳本轉換爲第三種選擇。
這個用例是否合理與Solr一起使用?
** [本博客文章](HTTP ://www.chrisumbel.com/article/solr_dataimporthandler_dih_scripttransformer)**看起來很有希望。 – worldsayshi
[有點相關](http://stackoverflow.com/questions/7917317/dynamic-column-names-using-dih-dataimporthandler)。 – worldsayshi