-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Query Field with DateBridge
PostPosted: Fri Aug 29, 2008 5:07 am 
Newbie

Joined: Thu Sep 13, 2007 7:01 am
Posts: 11
Hi,

I want to query persons for their birthday using Hibernate Search.

The date fild in my person class is like this:

Code:
@Field(index = Index.UN_TOKENIZED)
@DateBridge(resolution = Resolution.DAY)
private Date birthday;



When i query for
Code:
person.birthday:(19420126)


I get all persons with the birthday 19420125. So there is always a difference of one day. I think this is because the dates are stored GMT based in the index.

Is there a solution for this date-difference problem while searching?

Thanks,

Alexander


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 9:06 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I was facing the same problem once before. The 'problem' is that the DateBridge class is using Lucene's DateTools class for converting to and from dates (http://fisheye.jboss.org/browse/Hibernate/search/trunk/src/java/org/hibernate/search/bridge/builtin/DateBridge.java?r=11625). If you check the documentation of DateTools you will see that it uses UTC as timezone. For that reason you will have to make sure that the date instances you are working with are all in UTC. Given that you are just interested in a resolution of days this should be no problems.

How do you create your date instances in your entities? Check the Calendar class. There is for example a getInstance(TimeZone zone) which allows you to get a Calendar instance with a certain time zone. If you consistently use the UTC timezone in your application everything should be fine.

If your requirements are that you have to preserve the timezone you could write your own DateBridge.

Generally, you have to be careful when constructing/using dates within your java app and then transfering them across to other systems, be it a database or a Lucene index.

Hope this helps.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 3:12 am 
Newbie

Joined: Thu Sep 13, 2007 7:01 am
Posts: 11
@Hardy: thanks for your help. I ended up in using my own DateBridge.

Regards,

Alexander


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.