Custom Transformer to handle Timestamp

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom Transformer to handle Timestamp

convoyer
Hi all

I am using solr to index data from my database.
In my database there is a timestamp field of which data will be in the form of,
15-09-08 06:28:38.442000000 AM. The column is of type TIMESTAMP in the oracle db.
So in the schema.xml  i have mentioned as:
   <field name="LOGIN_TIMESTAMP" type="date" indexed="true" stored="true" /> 

While indexing data in the debug mode i get this timestamp  value as
<arr>
    <str>oracle.sql.TIMESTAMP:oracle.sql.TIMESTAMP@f536e8</str>
</arr>

And when i do a searching this value is not displaying while all other fields indexed along with it are getting displayed.

1) So do i need to write a custom transformer to add these values to the index.
2)And if yes I am confused how it is? Is there a sample code somewhere?
I have tried the sample TrimTransformer and it is working. But can i convert this string to a valid date format.(I am not a java expert.. )?

Expecting your reply
Thanks in advance
Con

Reply | Threaded
Open this post in threaded view
|

Re: Custom Transformer to handle Timestamp

Shalin Shekhar Mangar
On Tue, Jan 13, 2009 at 12:53 AM, con <[hidden email]> wrote:

>
> Hi all
>
> I am using solr to index data from my database.
> In my database there is a timestamp field of which data will be in the form
> of,
> 15-09-08 06:28:38.442000000 AM. The column is of type TIMESTAMP in the
> oracle db.
> So in the schema.xml  i have mentioned as:
>   <field name="LOGIN_TIMESTAMP" type="date" indexed="true" stored="true" />
>
> While indexing data in the debug mode i get this timestamp  value as
> <arr>
>    <str>oracle.sql.TIMESTAMP:oracle.sql.TIMESTAMP@f536e8</str>
> </arr>
>
> And when i do a searching this value is not displaying while all other
> fields indexed along with it are getting displayed.


Hmm, interesting. It seems oracle.sql.TIMESTAMP does not inherit from
java.sql.Timestamp or java.util.Date. This is why DataImportHandler/Solr
cannot make sense out of it and the string representation is being stored in
the index.

However it has a toJdbc() method which will return a Jdbc compatible object.

http://download-uk.oracle.com/otn_hosted_doc/jdeveloper/904preview/jdbc-javadoc/oracle/sql/TIMESTAMP.html#toJdbc()


> 1) So do i need to write a custom transformer to add these values to the
> index.


Yes, it seems like that is the only way.


> 2)And if yes I am confused how it is? Is there a sample code somewhere?


Yes, see an example here -- http://wiki.apache.org/solr/DIHCustomTransformer


>
> I have tried the sample TrimTransformer and it is working. But can i
> convert
> this string to a valid date format.(I am not a java expert..:-( )?


I would start by trying something like this:

oracle.jdbc.TIMESTAMP timestamp = (oracle.jdbc.TIMESTAMP)
row.get("your_timestamp_field_name");
row.put("your_timestamp_field_name", timestamp.toJdbc());


>
> --
> View this message in context:
> http://www.nabble.com/Custom-Transformer-to-handle-Timestamp-tp21421742p21421742.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
>


--
Regards,
Shalin Shekhar Mangar.
Reply | Threaded
Open this post in threaded view
|

Re: Custom Transformer to handle Timestamp

convoyer
Thanks Shalin

That really helped
I have created a plugin class and now things are working fine
Thanks Again

Regards
Con


Shalin Shekhar Mangar wrote
On Tue, Jan 13, 2009 at 12:53 AM, con <convoyer@gmail.com> wrote:

>
> Hi all
>
> I am using solr to index data from my database.
> In my database there is a timestamp field of which data will be in the form
> of,
> 15-09-08 06:28:38.442000000 AM. The column is of type TIMESTAMP in the
> oracle db.
> So in the schema.xml  i have mentioned as:
>   <field name="LOGIN_TIMESTAMP" type="date" indexed="true" stored="true" />
>
> While indexing data in the debug mode i get this timestamp  value as
> <arr>
>    <str>oracle.sql.TIMESTAMP:oracle.sql.TIMESTAMP@f536e8</str>
> </arr>
>
> And when i do a searching this value is not displaying while all other
> fields indexed along with it are getting displayed.


Hmm, interesting. It seems oracle.sql.TIMESTAMP does not inherit from
java.sql.Timestamp or java.util.Date. This is why DataImportHandler/Solr
cannot make sense out of it and the string representation is being stored in
the index.

However it has a toJdbc() method which will return a Jdbc compatible object.

http://download-uk.oracle.com/otn_hosted_doc/jdeveloper/904preview/jdbc-javadoc/oracle/sql/TIMESTAMP.html#toJdbc()


> 1) So do i need to write a custom transformer to add these values to the
> index.


Yes, it seems like that is the only way.


> 2)And if yes I am confused how it is? Is there a sample code somewhere?


Yes, see an example here -- http://wiki.apache.org/solr/DIHCustomTransformer


>
> I have tried the sample TrimTransformer and it is working. But can i
> convert
> this string to a valid date format.(I am not a java expert..:-( )?


I would start by trying something like this:

oracle.jdbc.TIMESTAMP timestamp = (oracle.jdbc.TIMESTAMP)
row.get("your_timestamp_field_name");
row.put("your_timestamp_field_name", timestamp.toJdbc());


>
> --
> View this message in context:
> http://www.nabble.com/Custom-Transformer-to-handle-Timestamp-tp21421742p21421742.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
>


--
Regards,
Shalin Shekhar Mangar.