WELCOME!

What is Pinoy? It's a slang for Filipino, a person who comes from the Republic of the Philippines, or commonly known as the Philippine Islands (PI). I am a Filipino and works as an Oracle DBA in the United States. Whenever an issue arises or just for experiments, I usually forget what I did to solve/conduct them. There must be a central location where I can put everything. Thus, this blog was born. It's a collection of ideas, tips and tricks, scripts, or anything interesting that happened to me on an Oracle database or any other stuff.

The simpler, the better! has always been my motto. You don't have to complicate things. Simple things, for me, is always easier, just like my site.

FYI, anything that is written here is based on my personal experiences and is not endorsed by any other party. Also, I will not be held liable for issues that can arise by following whatever I did. Just like any other good DBA would say... ALWAYS TEST!

Hope you can find this site helpful in whatever you need and remember, I am not a guru.

Jul 21, 2011

SOLR: dataImportHandler and Oracle

We are going to test the latest version of SOLR (3.3) and we need to populate it with data that is as close as the what we have on production. However, the script that populates the production index will not work with the new version because there are fields that were taken out due to localSOLR not being used with 3.3. Thus, a data-config.xml was created to be used by the data import handler.

Reviewing the schema.xml, I was caught by surprise with this definition:

  <field name="AD_ID" type="text" indexed="true" stored="true" required="true"/>
  <dynamicField name="PHOTO_*"  type="string"  indexed="true"  stored="true"/>

And the output is similar to this:

<str name="AD_ID">1</str>
<str name="PHOTO_1">image_1.jpg,</str>
<str name="PHOTO_2">image_2.jpg,</str>
<str name="PHOTO_3">image_3.jpg,</str>
<str name="PHOTO_4">image_4.jpg,</str>
<str name="PHOTO_5">image_5.jpg,</str>


How  can we achieve this? We can create a user-defined transformer using JAVA script. Here's what my data-config.xml would look like:


<dataConfig>
<dataSource driver="oracle.jdbc.driver.OracleDriver"
            url="jdbc:oracle:thin:@//hostname.com:port/SID"
            user="username" password="password" />
<script>
  <![CDATA[
    function photoFunction(row) {
      var seqNum = row.get("SEQ_NUM");
      var imageName = row.get("IMAGE_NAME");
      var fieldName = "PHOTO_" + segNum;
      row.put(fieldName, imageName);
      return row;
    }
  ]]>
</script>
<document name="Doc">
  <entity name="Ad" pk="AD_ID"
          query="select a.ad_id, a.other_columns
                   from table_name a
                   where conditions">
    <entity name="Photo"
            query="select p.seq_num, p.image_name
                     from photo_table p
                     where p.ad_id = '${Ad.AD_ID}'
                     order by p.display_order"
            transformer="script:photoFunction" />
  </entity>
</document>
</dataConfig>

A MySQL database can also be used by changing the dataSource part.

No comments:

Post a Comment