Solr DIH动态字段名称&转换价值

时间:2011-05-30 20:01:50

标签: lucene solr dih

我有一个DIH的工作solr现在我需要添加多行,这是与solr索引文档的一对多关系

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

我需要将基于FK(post_id)的所有行插入到具有动态名称的solr doc中,并根据类型转换值

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 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

我想我可以使用DIHCustomTransformer来调用一个函数,但我还不确定 http://wiki.apache.org/solr/DIHCustomTransformer

任何启蒙都将受到赞赏