-->
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: fulltextquery to date now
PostPosted: Thu Jul 05, 2012 9:54 am 
Regular
Regular

Joined: Thu Jun 16, 2011 12:03 pm
Posts: 94
Hi all,

I would like to query my index to get all data to some date. Every row has a publication date and i would like to use this date to get my results using the actual day time.

Code:
@Field
   @DateBridge(resolution=Resolution.SECOND)
   protected Date publicationDate = new Date();


i have read in hibernate search in action book about using rangequery to query using dates. In luke i can get the data using this query [* TO NOW] but i can not do this with hibernate search.

I tried:

Code:
andQuery.add(new TermQuery(new Term(field, "[* TO NOW]")), Occur.MUST);


i also tried:

Code:
TermRangeQuery rq = new TermRangeQuery(field, DateTools.dateToString(new Date(), DateTools.Resolution.SECOND), DateTools.dateToString(new Date(), DateTools.Resolution.SECOND),false, true);
andQuery.add(rq, Occur.MUST);


none of these solutions helps me to get the data till actual date.

any ideas?

thanks in advance!


Top
 Profile  
 
 Post subject: Re: fulltextquery to date now
PostPosted: Thu Jul 05, 2012 12:59 pm 
Hibernate Team
Hibernate Team

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

the term query won't work, because it does not understand about the query syntax "[* TO NOW]". For that to work you have to use a query parser. The term query just searches for the terms as you specify them.

A term range query should work. To have an open end point you should pass in null. You also need to double check whether DateTools.dateToString(new Date(), DateTools.Resolution.SECOND) created the same values as you have in the index. It should since @DateBridge uses DateTools under the hood.

--Hardy


Top
 Profile  
 
 Post subject: Re: fulltextquery to date now
PostPosted: Fri Jul 06, 2012 5:46 am 
Regular
Regular

Joined: Thu Jun 16, 2011 12:03 pm
Posts: 94
hi!

I did it this way just in case anybody wants to do the same query:

Code:
                // add date publication [* TO NOW]
                TermRangeQuery rq = new TermRangeQuery("publicationDate", null, DateTools.dateToString(new Date(), DateTools.Resolution.DAY), true, true);
                andQuery.add(rq, Occur.MUST);


and the property publicationDate in my entity has the same resolution as the Termquery, Resolution.DAY.

see u!


Top
 Profile  
 
 Post subject: Re: fulltextquery to date now
PostPosted: Fri Jul 06, 2012 5:54 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Thanks for the update :-)


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.