don't cache objects for non-existent/unindexed sortedset

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4765@1445913 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-02-13 20:46:50 +00:00
parent 925fb58932
commit 2bccce2777
2 changed files with 14 additions and 2 deletions

View File

@ -1379,8 +1379,12 @@ class FieldCacheImpl implements FieldCache {
} }
final FieldInfo info = reader.getFieldInfos().fieldInfo(field); final FieldInfo info = reader.getFieldInfos().fieldInfo(field);
if (info != null && info.hasDocValues()) { if (info == null) {
return SortedSetDocValues.EMPTY;
} else if (info.hasDocValues()) {
throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType()); throw new IllegalStateException("Type mismatch: " + field + " was indexed as " + info.getDocValuesType());
} else if (!info.isIndexed()) {
return SortedSetDocValues.EMPTY;
} }
DocTermOrds dto = (DocTermOrds) caches.get(DocTermOrds.class).get(reader, new CacheKey(field, null), false); DocTermOrds dto = (DocTermOrds) caches.get(DocTermOrds.class).get(reader, new CacheKey(field, null), false);

View File

@ -544,7 +544,6 @@ public class TestFieldCache extends LuceneTestCase {
assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSet.nextOrd()); assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSet.nextOrd());
assertEquals(2, sortedSet.getValueCount()); assertEquals(2, sortedSet.getValueCount());
// nocommit: not right
bits = FieldCache.DEFAULT.getDocsWithField(ar, "sortedset"); bits = FieldCache.DEFAULT.getDocsWithField(ar, "sortedset");
assertTrue(bits instanceof Bits.MatchAllBits); assertTrue(bits instanceof Bits.MatchAllBits);
@ -594,6 +593,10 @@ public class TestFieldCache extends LuceneTestCase {
sorted.get(0, scratch); sorted.get(0, scratch);
assertTrue(scratch.bytes == BinaryDocValues.MISSING); assertTrue(scratch.bytes == BinaryDocValues.MISSING);
SortedSetDocValues sortedSet = cache.getDocTermOrds(ar, "bogusmultivalued");
sortedSet.setDocument(0);
assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSet.nextOrd());
Bits bits = cache.getDocsWithField(ar, "bogusbits"); Bits bits = cache.getDocsWithField(ar, "bogusbits");
assertFalse(bits.get(0)); assertFalse(bits.get(0));
@ -615,6 +618,7 @@ public class TestFieldCache extends LuceneTestCase {
doc.add(new StoredField("bogusdoubles", "bogus")); doc.add(new StoredField("bogusdoubles", "bogus"));
doc.add(new StoredField("bogusterms", "bogus")); doc.add(new StoredField("bogusterms", "bogus"));
doc.add(new StoredField("bogustermsindex", "bogus")); doc.add(new StoredField("bogustermsindex", "bogus"));
doc.add(new StoredField("bogusmultivalued", "bogus"));
doc.add(new StoredField("bogusbits", "bogus")); doc.add(new StoredField("bogusbits", "bogus"));
iw.addDocument(doc); iw.addDocument(doc);
DirectoryReader ir = iw.getReader(); DirectoryReader ir = iw.getReader();
@ -654,6 +658,10 @@ public class TestFieldCache extends LuceneTestCase {
sorted.get(0, scratch); sorted.get(0, scratch);
assertTrue(scratch.bytes == BinaryDocValues.MISSING); assertTrue(scratch.bytes == BinaryDocValues.MISSING);
SortedSetDocValues sortedSet = cache.getDocTermOrds(ar, "bogusmultivalued");
sortedSet.setDocument(0);
assertEquals(SortedSetDocValues.NO_MORE_ORDS, sortedSet.nextOrd());
Bits bits = cache.getDocsWithField(ar, "bogusbits"); Bits bits = cache.getDocsWithField(ar, "bogusbits");
assertFalse(bits.get(0)); assertFalse(bits.get(0));