Index: src/test/org/apache/lucene/index/TestStressIndexing2.java =================================================================== --- src/test/org/apache/lucene/index/TestStressIndexing2.java (revision 887525) +++ src/test/org/apache/lucene/index/TestStressIndexing2.java (working copy) @@ -28,6 +28,7 @@ import junit.framework.TestCase; +// nocommit -- cut test over to flex API public class TestStressIndexing2 extends LuceneTestCase { static int maxFields=4; static int bigFieldSize=10; Index: src/test/org/apache/lucene/index/TestFlex.java =================================================================== --- src/test/org/apache/lucene/index/TestFlex.java (revision 0) +++ src/test/org/apache/lucene/index/TestFlex.java (revision 0) @@ -0,0 +1,61 @@ +package org.apache.lucene.index; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.*; +import java.util.*; +import org.apache.lucene.store.*; +import org.apache.lucene.index.*; +import org.apache.lucene.search.*; +import org.apache.lucene.analysis.*; +import org.apache.lucene.document.*; +import org.apache.lucene.util.*; + +public class TestFlex extends LuceneTestCase { + + // Test non-flex API emulated on flex index + public void testNonFlex() throws Exception { + Directory d = new MockRAMDirectory(); + + final int DOC_COUNT = 177; + + IndexWriter w = new IndexWriter(d, new WhitespaceAnalyzer(), + IndexWriter.MaxFieldLength.UNLIMITED); + w.setMaxBufferedDocs(7); + Document doc = new Document(); + doc.add(new Field("field1", "this is field1", Field.Store.NO, Field.Index.ANALYZED)); + doc.add(new Field("field2", "this is field2", Field.Store.NO, Field.Index.ANALYZED)); + doc.add(new Field("field3", "aaa", Field.Store.NO, Field.Index.ANALYZED)); + doc.add(new Field("field4", "bbb", Field.Store.NO, Field.Index.ANALYZED)); + for(int i=0;i commitUserData) throws IOException { + r.doCommit(commitUserData); + } + + protected void doClose() throws IOException { + r.doClose(); + } + + public Collection getFieldNames(FieldOption fldOption) { + return r.getFieldNames(fldOption); + } + } + + public void testExternalReader() throws Exception { + Directory d = new MockRAMDirectory(); + + final int DOC_COUNT = 177; + + IndexWriter w = new IndexWriter(d, new WhitespaceAnalyzer(), + IndexWriter.MaxFieldLength.UNLIMITED); + w.setMaxBufferedDocs(7); + Document doc = new Document(); + doc.add(new Field("field1", "this is field1", Field.Store.NO, Field.Index.ANALYZED)); + doc.add(new Field("field2", "this is field2", Field.Store.NO, Field.Index.ANALYZED)); + doc.add(new Field("field3", "aaa", Field.Store.NO, Field.Index.ANALYZED)); + doc.add(new Field("field4", "bbb", Field.Store.NO, Field.Index.ANALYZED)); + for(int i=0;i 0 - && Character.isHighSurrogate(text.charAt(text.length() - 1))) + && Character.isHighSurrogate(text.charAt(text.length() - 1))) { tr = new TermRef(t.text() + "\uDC00"); - else + } else { tr = new TermRef(t.text()); + } TermsEnum.SeekStatus status = terms.seek(tr); if (status == TermsEnum.SeekStatus.END) { - // leave currentTerm null + // Rollover to the next field + terms = null; + next(); } else if (status == TermsEnum.SeekStatus.FOUND) { + // Found exactly the term currentTerm = tr; } else { + // Found another term, in this same field currentTerm = terms.term(); } + } else { + // Advance to first term in this field: + next(); } } } else { @@ -1433,7 +1445,8 @@ // This field still has terms return true; } else { - // Done producing terms from this field + // Done producing terms from this field; advance + // to next field terms = null; } } @@ -1441,10 +1454,8 @@ @Override public Term term() { - if (terms != null && !done) { - if (currentTerm != null) { - return new Term(currentField, currentTerm.toString()); - } + if (!done && terms != null && currentTerm != null) { + return new Term(currentField, currentTerm.toString()); } return null; } Index: src/java/org/apache/lucene/index/LegacyTerms.java =================================================================== --- src/java/org/apache/lucene/index/LegacyTerms.java (revision 887525) +++ src/java/org/apache/lucene/index/LegacyTerms.java (working copy) @@ -17,9 +17,10 @@ * limitations under the License. */ - import java.io.IOException; +import org.apache.lucene.util.StringHelper; + /** Implements flex API (FieldsEnum/TermsEnum) on top of * pre-flex API. Used only for IndexReader impls outside * Lucene's core. */ @@ -30,7 +31,7 @@ LegacyTerms(IndexReader r, String field) { this.r = r; - this.field = field; + this.field = StringHelper.intern(field); } @Override Index: src/java/org/apache/lucene/index/LegacyFields.java =================================================================== --- src/java/org/apache/lucene/index/LegacyFields.java (revision 887525) +++ src/java/org/apache/lucene/index/LegacyFields.java (working copy) @@ -37,7 +37,6 @@ @Override public Terms terms(String field) throws IOException { - // nocommit return new LegacyTerms(r, field); } }