As of Lucene 1.3dev1 at least, some range query syntax changes were made. If you use dates expressed as YYYYMMDD (without doing the dateToString conversion), the expression my_date_field:[0 TO yyyymmdd] returns all entries up to the date yyyymmdd, and the expression my_date_field:[yyyymmdd TO null] returns all entries from the date yyyymmdd forward. (I just verified this.)
Terry ----- Original Message ----- From: "Erik Hatcher" <[EMAIL PROTECTED]> To: "Lucene Users List" <[EMAIL PROTECTED]> Sent: Wednesday, January 22, 2003 10:41 PM Subject: Re: Range queries > 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:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>