开发者

DynamicField names from SQL value

I have this "catch all" field in my schema.xml:

<dynamicFiel开发者_高级运维d name="*_s" type="string" indexed="true" stored="true" />

In the example below lets say i have a table that has 2 fields: "custom_value" and "custom_key" with these values:

custom_key: "mykey"

custom_value: "myvalue"

My Goal is to index a document that has a field called "mykey" and the value "myvalue". How can i do that?

<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>


Found a (hacky?) solution, that works for my purposes, i will not mark this question as answered for a few days, incase someone comes up with a cleaner/better solution.

 <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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜