LUCENE-1423

InstantiatedTermEnum#skipTo(Term) throws ArrayIndexOutOfBoundsException on an empty index.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@705893 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Karl-Johan Wettin 2008-10-18 16:29:53 +00:00
parent d2ff5ee3bb
commit 456b10fdf9
4 changed files with 176 additions and 0 deletions

View File

@ -2,6 +2,35 @@ Lucene contrib change Log
======================= Trunk (not yet released) =======================
Changes in runtime behavior
(None)
API Changes
(None)
Bug fixes
1. LUCENE-1423: InstantiatedTermEnum#skipTo(Term) throws ArrayIndexOutOfBounds on empty index.
(Karl Wettin)
New features
(None)
Documentation
(None)
Build
(None)
Test Cases
(None)
======================= Release 2.4.0 2008-10-06 =======================
Changes in runtime behavior

View File

@ -84,6 +84,10 @@ public class InstantiatedTermEnum
// in lucene for many years now, so there is
// very to gain by optimizing this method more,
if (reader.getIndex().getOrderedTerms().length == 0) {
return false;
}
InstantiatedTerm term = reader.getIndex().findTerm(target);
if (term != null) {
this.term = term;

View File

@ -0,0 +1,77 @@
/**
* Copyright 2006 The Apache Software Foundation
*
* Licensed 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.
*/
package org.apache.lucene.store.instantiated;
import junit.framework.TestCase;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocCollector;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermEnum;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
public class TestEmptyIndex extends TestCase {
public void testSearch() throws Exception {
InstantiatedIndex ii = new InstantiatedIndex();
IndexReader r = new InstantiatedIndexReader(ii);
IndexSearcher s = new IndexSearcher(r);
TopDocCollector c = new TopDocCollector(1);
s.search(new TermQuery(new Term("foo", "bar")), c);
assertEquals(0, c.getTotalHits());
s.close();
r.close();
ii.close();
}
public void testTermEnum() throws Exception {
InstantiatedIndex ii = new InstantiatedIndex();
IndexReader r = new InstantiatedIndexReader(ii);
termEnumTest(r);
r.close();
ii.close();
// make sure a Directory acts the same
Directory d = new RAMDirectory();
new IndexWriter(d, null, true, IndexWriter.MaxFieldLength.UNLIMITED).close();
r = IndexReader.open(d);
termEnumTest(r);
r.close();
d.close();
}
public void termEnumTest(IndexReader r) throws Exception {
TermEnum terms = r.terms();
assertNull(terms.term());
assertFalse(terms.next());
assertFalse(terms.skipTo(new Term("foo", "bar")));
}
}

View File

@ -0,0 +1,66 @@
/**
* Copyright 2006 The Apache Software Foundation
*
* Licensed 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.
*/
package org.apache.lucene.store.instantiated;
import junit.framework.TestCase;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.TopDocCollector;
import org.apache.lucene.search.HitCollector;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.Term;
public class TestRealTime extends TestCase {
public void test() throws Exception {
InstantiatedIndex index = new InstantiatedIndex();
InstantiatedIndexReader reader = new InstantiatedIndexReader(index);
IndexSearcher searcher = new IndexSearcher(reader);
InstantiatedIndexWriter writer = new InstantiatedIndexWriter(index);
Document doc;
Collector collector;
doc = new Document();
doc.add(new Field("f", "a", Field.Store.NO, Field.Index.NOT_ANALYZED));
writer.addDocument(doc);
writer.commit();
collector = new Collector();
searcher.search(new TermQuery(new Term("f", "a")), collector);
assertEquals(1, collector.hits);
doc = new Document();
doc.add(new Field("f", "a", Field.Store.NO, Field.Index.NOT_ANALYZED));
writer.addDocument(doc);
writer.commit();
collector = new Collector();
searcher.search(new TermQuery(new Term("f", "a")), collector);
assertEquals(2, collector.hits);
}
public static class Collector extends HitCollector {
private int hits = 0;
public void collect(int doc, float score) {
hits++;
}
}
}