lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject svn commit: r705893 - in /lucene/java/trunk/contrib: ./ instantiated/src/java/org/apache/lucene/store/instantiated/ instantiated/src/test/org/apache/lucene/store/instantiated/
Date Sat, 18 Oct 2008 16:29:54 GMT
Author: kalle
Date: Sat Oct 18 09:29:53 2008
New Revision: 705893

URL: http://svn.apache.org/viewvc?rev=705893&view=rev
Log:
LUCENE-1423
InstantiatedTermEnum#skipTo(Term) throws ArrayIndexOutOfBoundsException on an empty index.

Added:
    lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java
    lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestRealTime.java
Modified:
    lucene/java/trunk/contrib/CHANGES.txt
    lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedTermEnum.java

Modified: lucene/java/trunk/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/CHANGES.txt?rev=705893&r1=705892&r2=705893&view=diff
==============================================================================
--- lucene/java/trunk/contrib/CHANGES.txt (original)
+++ lucene/java/trunk/contrib/CHANGES.txt Sat Oct 18 09:29:53 2008
@@ -2,6 +2,35 @@
 
 ======================= 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

Modified: lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedTermEnum.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedTermEnum.java?rev=705893&r1=705892&r2=705893&view=diff
==============================================================================
--- lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedTermEnum.java
(original)
+++ lucene/java/trunk/contrib/instantiated/src/java/org/apache/lucene/store/instantiated/InstantiatedTermEnum.java
Sat Oct 18 09:29:53 2008
@@ -84,6 +84,10 @@
     // 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;

Added: lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java?rev=705893&view=auto
==============================================================================
--- lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java
(added)
+++ lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestEmptyIndex.java
Sat Oct 18 09:29:53 2008
@@ -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")));
+
+  }
+
+}

Added: lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestRealTime.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestRealTime.java?rev=705893&view=auto
==============================================================================
--- lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestRealTime.java
(added)
+++ lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestRealTime.java
Sat Oct 18 09:29:53 2008
@@ -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++;
+    }
+  }
+
+}



Mime
View raw message