lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yonik Seeley <ysee...@gmail.com>
Subject Re: Strange sort error
Date Thu, 14 Apr 2005 14:28:44 GMT
I haven't tried it, but I think the fix should be easy... never throw
that exception.  Either check for null before the loop, or in the
loop.

Original code for native int sorting:

        TermEnum termEnum = reader.terms (new Term (field, ""));
        try {
          if (termEnum.term() == null) {
            throw new RuntimeException ("no terms in field " + field);
          }
          do {
            Term term = termEnum.term();
            if (term.field() != field) break;
            int termval = Integer.parseInt (term.text());
            termDocs.seek (termEnum);
            while (termDocs.next()) {
              retArray[termDocs.doc()] = termval;
            }
          } while (termEnum.next());
        } finally {
          termDocs.close();
          termEnum.close();
        }

------------- possible fix --------------
        TermEnum termEnum = reader.terms (new Term (field, ""));
        try {  
          do {
            Term term = termEnum.term();
            if (termEnum==null || term.field() != field) break;  // CHANGE here
            int termval = Integer.parseInt (term.text());
            termDocs.seek (termEnum);
            while (termDocs.next()) {
              retArray[termDocs.doc()] = termval;
            }
          } while (termEnum.next());
        } finally {
          termDocs.close();
          termEnum.close();
        }

-Yonik

On 4/13/05, Daniel Naber <lucenelist@danielnaber.de> wrote:
> On Tuesday 12 April 2005 20:04, Bill Tschumy wrote:
> 
> > Here is a small program that will manifest the error. Hopefully 
> > someone can explain the problem. It happens with Lucene 1.4.2 and 
> > 1.4.3.
> 
> This is the code that throws the exception (from FieldCacheImpl.java):
> 
>   TermEnum termEnum = reader.terms (new Term (field, ""));
>   (...)
>   if (termEnum.term() == null) {
>       throw new RuntimeException ("no terms in field " + field);
>   }
> 
> The problem is that a TermEnum always returns all terms after a given one,
> not only terms in the same field. So the check is incomplete. If one
> changes the if like this, one will always get an exception if there are no
> terms in the field, as the exception claims:
> 
>   if (termEnum.term() == null || !termEnum.term().field().equals(field)) {
> 
> The other issue is that you probably expect to not get an exception at all,
> as there are no matches. Lucene doesn't first search and then sort, these
> tasks are parallel I think. So this is not that easy to fix (and I doubt
> if one should try).
> 
> Could you open a bug report for the problem with the exception that seems
> to occur only sometimes? The change suggested above needs to be tested
> before it can be committed and a bug report is useful for that.
> 
> Regards
>  Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message