I forgot: As we already have a new API, we can change this behaviour for TermsEnums easily and it seems for the SegmentTermsEnums its already done. A lot of people on java-user always had the same problem, that you need to use a do-while-loop which is not intuitive.
----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: u...@thetaphi.de > -----Original Message----- > From: Uwe Schindler [mailto:u...@thetaphi.de] > Sent: Thursday, December 03, 2009 10:00 AM > To: java-dev@lucene.apache.org > Subject: RE: svn commit: r886339 - > /lucene/java/branches/flex_1458/src/test/org/apache/lucene/search/TestNume > ricRangeQuery32.java > > I already wrote an comment in the flex issue about that. Its not really > good. Maybe we should change the FilteredTermsEnum also to require calling > next() first, which makes it more useable like an iterator. I was always > not > so happy with the fact, that you need to have the strange do...while loop. > > For NRQ, the change is simple, just remove the next() call in the ctor. > For > other FilteredTermsEnums its similar, just move the seek code to the first > next call. > > In my opinion, code should look like that: > > TermsEnum te = MTQ.getTermsEnum(); > TermRef term; > while ((term = te.next()) != null) { > .. > } > > Uwe > > ----- > Uwe Schindler > H.-H.-Meier-Allee 63, D-28213 Bremen > http://www.thetaphi.de > eMail: u...@thetaphi.de > > > -----Original Message----- > > From: Mark Miller [mailto:markrmil...@gmail.com] > > Sent: Thursday, December 03, 2009 12:56 AM > > To: java-dev@lucene.apache.org > > Subject: Re: svn commit: r886339 - > > > /lucene/java/branches/flex_1458/src/test/org/apache/lucene/search/TestNume > > ricRangeQuery32.java > > > > I see where I was confused - I was looking at the javadoc for TermsEnum, > > which says you must call next or seek before getting the term - but I > > was more confused than straightened out when I saw FilteredTermsEnum > > said the enum must already be positioned at the first term - it didn't > > dawn on me that they acted different in that regard - thats why I put > > the nocommit - was a bit confused. Looking at the code, it makes sense > > now though. > > > > I do agree that its a bit confusing now that you have to call .empty > > first now. Thats what led me down the path of trying .next != null - > > didn't even occur to me there was a .empty. Knew something was screwy > > though, even with the test passing. > > > --- > > > lucene/java/branches/flex_1458/src/test/org/apache/lucene/search/TestNumer > > icRangeQuery32.java (original) > > > +++ > > > lucene/java/branches/flex_1458/src/test/org/apache/lucene/search/TestNumer > > icRangeQuery32.java Wed Dec 2 23:27:49 2009 > > > @@ -443,9 +443,8 @@ > > > NumericRangeQuery<Integer> q = > > NumericRangeQuery.newIntRange("field4", 4, > > > lower, upper, true, true); > > > FilteredTermsEnum termEnum = > > q.getTermsEnum(searcher.getIndexReader()); > > > - //nocommit: double check this merge 'fix' > > > int count = 0; > > > - if (termEnum.next() != null) { > > > + if (!termEnum.empty()) { > > > do { > > > final TermRef t = termEnum.term(); > > > if (t != null) { > > > @@ -457,7 +456,7 @@ > > > break; > > > } while (termEnum.next() != null); > > > } > > > - assertFalse(termEnum.next() != null); > > > + assertNotNull(termEnum.next()); > > > System.out.println("TermEnum on 'field4' for range [" + lower + > "," > > + upper > > > + "] contained " + count + " terms."); > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org > > For additional commands, e-mail: java-dev-h...@lucene.apache.org > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-dev-h...@lucene.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org For additional commands, e-mail: java-dev-h...@lucene.apache.org