You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Chris D <un...@hotmail.com> on 2002/11/26 17:04:24 UTC

Bug in current CVS source with DateField

I found that the current code in CVS prevents a 
org.apache.lucene.search.DateFilter from functioning properly.

This fragment is taken from org.apache.lucene.document.DateField


    // Pad with leading zeros
    if (s.length() < DATE_LEN) {
      StringBuffer sb = new StringBuffer(s);
      while (sb.length() < DATE_LEN)
        sb.insert(0, ' ');
      s = sb.toString();
    }


The code is padding ' ' (space) instead of zeros.

Line 5 should be:          sb.insert(0, '0');

Making this change and recompiling gave the expected results.

Looking back,  the lucene-1.2 source uses the following fragment:

    while (s.length() < DATE_LEN)
      s = "0" + s;				  // pad with leading zeros





_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Bug in current CVS source with DateField

Posted by Doug Cutting <cu...@lucene.com>.
[ I moved this discussion to lucene-dev.   -drc ]

This looks like a premature optimization gone bad.

Brian, you made this change.  Would you like to fix it, or should I?

Doug

Chris D wrote:
> 
> I found that the current code in CVS prevents a 
> org.apache.lucene.search.DateFilter from functioning properly.
> 
> This fragment is taken from org.apache.lucene.document.DateField
> 
> 
>    // Pad with leading zeros
>    if (s.length() < DATE_LEN) {
>      StringBuffer sb = new StringBuffer(s);
>      while (sb.length() < DATE_LEN)
>        sb.insert(0, ' ');
>      s = sb.toString();
>    }
> 
> 
> The code is padding ' ' (space) instead of zeros.
> 
> Line 5 should be:          sb.insert(0, '0');
> 
> Making this change and recompiling gave the expected results.
> 
> Looking back,  the lucene-1.2 source uses the following fragment:
> 
>    while (s.length() < DATE_LEN)
>      s = "0" + s;                  // pad with leading zeros
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>