Skip to content

Apache Lucene open-source search software

LUCENE-799: Added support for Lazy compressed string fields. Thanks to Mike Klaas.

Grant Ingersoll09930c93497a
diff --git a/CHANGES.txt b/CHANGES.txt
index 14df0decef0..fd9a3241a71 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -113,6 +113,8 @@ New features
which allow one to retrieve the size of a field without retrieving the actual field.
(Chuck Williams via Grant Ingersoll)
+15. LUCENE-799: Properly handle lazy, compressed fields. (Mike Klaas via Grant Ingersoll)
+
API Changes
1. LUCENE-438: Remove "final" from Token, implement Cloneable, allow
diff --git a/src/java/org/apache/lucene/index/FieldsReader.java b/src/java/org/apache/lucene/index/FieldsReader.java
index 1ed798654e5..6676951bfae 100644
--- a/src/java/org/apache/lucene/index/FieldsReader.java
+++ b/src/java/org/apache/lucene/index/FieldsReader.java
@@ -362,10 +362,16 @@ final class FieldsReader {
IndexInput localFieldsStream = getFieldStream();
try {
localFieldsStream.seek(pointer);
- //read in chars b/c we already know the length we need to read
- char[] chars = new char[toRead];
- localFieldsStream.readChars(chars, 0, toRead);
- fieldsData = new String(chars);
+ if (isCompressed) {
+ final byte[] b = new byte[toRead];
+ localFieldsStream.readBytes(b, 0, b.length);
+ fieldsData = new String(uncompress(b), "UTF-8");
+ } else {
+ //read in chars b/c we already know the length we need to read
+ char[] chars = new char[toRead];
+ localFieldsStream.readChars(chars, 0, toRead);
+ fieldsData = new String(chars);
+ }
} catch (IOException e) {
throw new FieldReaderException(e);
}
diff --git a/src/test/org/apache/lucene/index/TestFieldsReader.java b/src/test/org/apache/lucene/index/TestFieldsReader.java
index cde6916d52c..25ca4e74cb7 100644
--- a/src/test/org/apache/lucene/index/TestFieldsReader.java
+++ b/src/test/org/apache/lucene/index/TestFieldsReader.java
@@ -93,6 +93,7 @@ public class TestFieldsReader extends TestCase {
lazyFieldNames.add(DocHelper.LAZY_FIELD_KEY);
lazyFieldNames.add(DocHelper.LAZY_FIELD_BINARY_KEY);
lazyFieldNames.add(DocHelper.TEXT_FIELD_UTF2_KEY);
+ lazyFieldNames.add(DocHelper.COMPRESSED_TEXT_FIELD_2_KEY);
SetBasedFieldSelector fieldSelector = new SetBasedFieldSelector(loadFieldNames, lazyFieldNames);
Document doc = reader.doc(0, fieldSelector);
assertTrue("doc is null and it shouldn't be", doc != null);
@@ -102,6 +103,12 @@ public class TestFieldsReader extends TestCase {
String value = field.stringValue();
assertTrue("value is null and it shouldn't be", value != null);
assertTrue(value + " is not equal to " + DocHelper.LAZY_FIELD_TEXT, value.equals(DocHelper.LAZY_FIELD_TEXT) == true);
+ field = doc.getFieldable(DocHelper.COMPRESSED_TEXT_FIELD_2_KEY);
+ assertTrue("field is null and it shouldn't be", field != null);
+ assertTrue("field is not lazy and it should be", field.isLazy());
+ value = field.stringValue();
+ assertTrue("value is null and it shouldn't be", value != null);
+ assertTrue(value + " is not equal to " + DocHelper.FIELD_2_COMPRESSED_TEXT, value.equals(DocHelper.FIELD_2_COMPRESSED_TEXT) == true);
field = doc.getFieldable(DocHelper.TEXT_FIELD_1_KEY);
assertTrue("field is null and it shouldn't be", field != null);
assertTrue("Field is lazy and it should not be", field.isLazy() == false);