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.codecs.*; import org.apache.lucene.index.codecs.standard.*; 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 = newDirectory(newRandom()); final int DOC_COUNT = 177; IndexWriter w = new IndexWriter(d, new MockAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED); for(int iter=0;iter<2;iter++) { if (iter == 0) { 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<DOC_COUNT;i++) { w.addDocument(doc); } } else { w.optimize(); } IndexReader r = w.getReader(); TermsEnum terms = MultiFields.getTerms(r, "field3").iterator(); assertEquals(TermsEnum.SeekStatus.END, terms.seek(new BytesRef("abc"))); r.close(); } w.close(); d.close(); } public void testTermOrd() throws Exception { Random random = newRandom(); Directory d = newDirectory(random); IndexWriter w = new IndexWriter(d, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setCodecProvider(_TestUtil.alwaysCodec("Standard"))); Document doc = new Document(); doc.add(new Field("f", "a b c", Field.Store.NO, Field.Index.ANALYZED)); w.addDocument(doc); IndexReader r = w.getReader(); TermsEnum terms = r.getSequentialSubReaders()[0].fields().terms("f").iterator(); assertTrue(terms.next() != null); assertEquals(0, terms.ord()); r.close(); w.close(); d.close(); } }