2011-05-30 59 views
1

我有一個工作與DIH SOLR現在我需要添加多行這是一家以關注Solr索引的文檔Solr的DIH動態提交姓名和轉換價值

TABLE: 
ID:int PK 
post_id:int FK 
name:string 
value:text 
type:(int|string) 

我需要插入基於所有行一對多的關係在FK(post_id)轉換爲solr文檔,並帶有動態名稱和基於類型的轉換值

SELECT name,value,type FROM TABLE WHERE post_id='${post_entity.id}'; 

loop 
insert into solr fieldname: meta_{$name} value: if type int cast to int else just value 
end loop 

任何人都知道如何做到這一點?

回答

2

不知道如果你有答案了,但我的理解是,你需要在數據處理程序文檔中創建多個實體選項卡,爲每個要添加的新多值字段創建一個,並指示根文檔中的ID。請看下面的例子: 在DataHandler.xml文件:

<dataConfig> 
<dataSource name="jdbc" driver="org.postgresql.Driver" url="jdbc:postgresql://localhost/bedrock" user="postgres" password="test" batchSize="1000" readOnly="true" autoCommit="false" transactionIsolation="TRANSACTION_READ_COMMITTED" holdability="CLOSE_CURSORS_AT_COMMIT" /> 
<document name="doc-a"> 
    <entity name="employee-root" datasource="jdbc" pk="id" query =" 
     select 
      a.id as id, 
      a.name as name, 
      a.dept as dept, 
      a.jobtitle as jobtitle, 
      a.last_change as last_change 
     from employee a 
     " 
    transformer="RegexTransformer,DateFormatTransformer,TemplateTransformer"> 
     <field column = "id" /> 
     <field column = "name" /> 
     <field column = "dept" /> 
     <field column = "jobtitle" /> 
    <entity name="employee-hobby" datasource="jdbc" query =" 
     select 
      employee_hobby as features 
      from employee_hobby 
      where employee_id = ${employee-root.id} 
     " 
     transformer="RegexTransformer,DateFormatTransformer,TemplateTransformer"> 
     <field column = "features" /> 

    </entity> 
    </entity> 
</document> 

+0

感謝阿道夫,事實上,我創建的多實體我DIH配置裏面,但我需要在這裏做的子實體過程中額外的過程 – Komang 2011-12-11 02:23:52