-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate Lucene Index search
PostPosted: Wed Mar 19, 2008 1:26 pm 
Newbie

Joined: Wed Mar 12, 2008 11:45 am
Posts: 5
Hello,

I am using Hibernate lucene combination to search the index. I have troble searching the date range.

The below code returning the results when you give the date with out time

String queryString= "updateTime:["2008-03-18" TO 2008-04-18]";
Query query = qp.parse(queryString);
Hits hits = bbMuniDetailsSearcher.search(query);

but it is not returning anything when I use the date and time

String queryString= "updateTime:["2008-04-18 21:02:31.093" TO 2008-04-18]";
Query query = qp.parse(queryString);
Hits hits = bbMuniDetailsSearcher.search(query);


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 20, 2008 6:25 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
the format you are using in you range query isn't correct
(I guess, it actually depends on how you indexed the dates).

All rangequeries (the "field:[fromxx TO toyy]" use string comparison to determine order,
so all numbers and dates have a special format in indexes to allow for correct range queries.

for example:

int 5 --> String "00000005" (don't actually remember how many 0's)
date 2008-03-08 --> String "20080308" assuming 03 is the month (yyyyMMdd format).

The actual date format depends on the resolution you've chosen on your entity,
I would recommend you "Resolution.DAY".

Warning: range queries are rewritten to boolean queries containing all possible terms in the range, so your example "2008-03-18" TO 2008-04-18 will possibly translate in
20080318 or 20080319 or 20080320 or ... or 20080418.
You must guarantee not to exceed the lucene limit for boolean clauses (1024);
So if you are using rangequeries by day you probably won't index the minutes seconds and milliseconds, as it will explode the query: choose the resolution carefully, and even so be prepared to catch an exception if you give too much options to the user.

You should use the luke tool http://www.getopt.org/luke/ to inspect you index and verify
the index format; you can also use it to test queries.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 20, 2008 6:41 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Nearly forgot:
don't write you own converter, use
Code:
org.apache.lucene.document.DateTools

to get the correct string from your date,
then you can use the QueryParser as you are doing, or use the RangeQuery class
to define it programmatically instead of by appending strings.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 20, 2008 8:23 am 
Newbie

Joined: Wed Mar 12, 2008 11:45 am
Posts: 5
Thanks for your reply. I will try this


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.