>             if (termEnum==null || term.field() != field) break;  // CHANGE 
> here

Errr, that should be term==null of course.

>             if (term==null || term.field() != field) break;  // CHANGE here

And it *may* be slightly speedier to check for null just before the
do/while loop instead:

if (termEnum.term() != null) {
  do {
 [...]
  } while(...)
}

-Yonik

On 4/14/05, Yonik Seeley <[EMAIL PROTECTED]> wrote:
> 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 <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to