mirror of https://github.com/apache/lucene.git
LUCENE-1510
InstantiatedIndexReader#norms methods throws NullPointerException on empty index. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@732661 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3f72bc813f
commit
f991524da8
|
@ -19,6 +19,9 @@ Bug fixes
|
|||
same way IndexWriter does. Parts of InstantiatedIndex was not Serializable.
|
||||
(Karl Wettin)
|
||||
|
||||
3. LUCENE-1510: InstantiatedIndexReader#norms methods throws NullPointerException on empty index.
|
||||
(Karl Wettin, Robert Newson)
|
||||
|
||||
New features
|
||||
|
||||
1. LUCENE-1470: Added TrieRangeQuery, a much faster implementation of
|
||||
|
|
|
@ -280,6 +280,9 @@ public class InstantiatedIndexReader extends IndexReader {
|
|||
*/
|
||||
public byte[] norms(String field) throws IOException {
|
||||
byte[] norms = getIndex().getNormsByFieldNameAndDocumentNumber().get(field);
|
||||
if (norms == null) {
|
||||
return new byte[0]; // todo a static final zero length attribute?
|
||||
}
|
||||
if (updatedNormsByFieldNameAndDocumentNumber != null) {
|
||||
norms = norms.clone();
|
||||
List<NormUpdate> updated = updatedNormsByFieldNameAndDocumentNumber.get(field);
|
||||
|
@ -294,6 +297,9 @@ public class InstantiatedIndexReader extends IndexReader {
|
|||
|
||||
public void norms(String field, byte[] bytes, int offset) throws IOException {
|
||||
byte[] norms = getIndex().getNormsByFieldNameAndDocumentNumber().get(field);
|
||||
if (norms == null) {
|
||||
return;
|
||||
}
|
||||
System.arraycopy(norms, 0, bytes, offset, norms.length);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,16 +17,19 @@
|
|||
package org.apache.lucene.store.instantiated;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.index.TermEnum;
|
||||
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;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TestEmptyIndex extends TestCase {
|
||||
|
||||
public void testSearch() throws Exception {
|
||||
|
@ -47,6 +50,38 @@ public class TestEmptyIndex extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
public void testNorms() throws Exception {
|
||||
|
||||
InstantiatedIndex ii = new InstantiatedIndex();
|
||||
IndexReader r = new InstantiatedIndexReader(ii);
|
||||
testNorms(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);
|
||||
testNorms(r);
|
||||
r.close();
|
||||
d.close();
|
||||
|
||||
}
|
||||
|
||||
private void testNorms(IndexReader r) throws IOException {
|
||||
byte[] norms;
|
||||
norms = r.norms("foo");
|
||||
assertNotNull(norms);
|
||||
assertEquals(0, norms.length);
|
||||
norms = new byte[10];
|
||||
Arrays.fill(norms, (byte)10);
|
||||
r.norms("foo", norms, 10);
|
||||
for (byte b : norms) {
|
||||
assertEquals((byte)10, b);
|
||||
}
|
||||
}
|
||||
|
||||
public void testTermEnum() throws Exception {
|
||||
|
||||
InstantiatedIndex ii = new InstantiatedIndex();
|
||||
|
|
Loading…
Reference in New Issue