lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <li...@ehatchersolutions.com>
Subject Re: Range queries
Date Thu, 23 Jan 2003 03:41:31 GMT
Followup: after looking at QueryParser.jj (my apologies for not looking 
deeper before), it *does* support readable date range queries.  But the 
dates must both be valid and adhere to DateFormat.SHORT style.  I 
changed the code I previously sent to this:

         String begin = "1/1/02";
         String end = "12/31/02";

And the results were the same, all expected documents were returned.  
It does not work to use "null" for begin or end to leave either side of 
the range open-ended.

	Erik


On Wednesday, January 22, 2003, at 08:56  PM, Erik Hatcher wrote:
> I wanted to see this first-hand, so I wrote some test code to 
> understand how dates are represented and how QueryParser deals with 
> them.  I've indexed 500 documents with random dates between 1/1/2002 
> and 12/31/2002.
>
> Here's what works:
>
>         QueryParser parser = new QueryParser("contents", new 
> StandardAnalyzer());
>         String begin = DateField.dateToString(new Date(102, 0, 01)); 
> // 20020101
>         String end = DateField.dateToString(new Date(102, 11, 31)); // 
> 20021231
>         String q = "date:[" + begin + " TO " + end + "]";
>         System.out.println("q = " + q);
>         Query query = parser.parse(q);
>         System.out.println("query = " + query.toString("date"));
>         Hits hits = searcher.search(query);
>         System.out.println("# found = " + hits.length());
>
> Here's the output:
>
> q = date:[0cvx9a8w0 TO 0daddkbk0]
> query = [0cvx9a8w0-0daddkbk0]
> # found = 500
>
> If I change begin and end to "20020101" and "20021231" respectively I 
> get zero hits.
>
> I'm running the latest Lucene version from CVS, in case that makes a 
> difference.
>
> So, while I would love it if QueryParser behaved with the YYYYMMDD 
> syntax, it does not.  Or am I missing something here?
>
> Any JavaCC wizzes out there that could modify it to take readable date 
> formats and construct the query using the dateToString?  That would be 
> sweet!    Has anyone created any JavaScript that mimics the 
> dateToString functionality that you'd share?
>
> 	Erik


--
To unsubscribe, e-mail:   <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>


Mime
View raw message