lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <>
Subject Re: Range queries
Date Thu, 23 Jan 2003 04:28:18 GMT
So you are using 1.3dev1?

I'm not having the same effect you are - and looking at QueryParser.jj 
it does this:

   private Query getRangeQuery(String field,
                               Analyzer analyzer,
                               String part1,
                               String part2,
                               boolean inclusive)
     boolean isDate = false, isNumber = false;

     try {
       DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
       Date d1 = df.parse(part1);
       Date d2 = df.parse(part2);
       part1 = DateField.dateToString(d1);
       part2 = DateField.dateToString(d2);
       isDate = true;
     catch (Exception e) { }

I get all documents if I use "date:[0 TO 20021231]" but none if I do 
"date:[20020101 TO null]", and from the code I'm surmising I'm just 
lucky in the first case because its using a string range query and they 
all just happen to fall in that range (all dateToString's begin with 
"0").  In the second case I'm getting nothing because no dateToString's 
are in that range textually.

So are you certain you're seeing the results you report?  I cannot 
explain the results you see from the code above.  Maybe I'm way off in 
my understanding of this - but I really don't see how YYYYMMDD works 
accurately.  DateFormat.parse throws an exception on strings in that 
format (using DateFormat.SHORT), so QueryParser would never think its 
really a date and convert it properly to its string representation.

Ah, maybe its how we are indexing our fields differently?  How are you 
indexing your my_date_field?  I'm using this syntax:

	Field.Keyword(fieldName, new Date(....))

Maybe you are indexing it as a String with "YYYYMMDD" format?  If so, 
that explains it.


On Wednesday, January 22, 2003, at 10:55  PM, Terry Steichen wrote:
> 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

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message