mirror of https://github.com/apache/lucene.git
LUCENE-799: Added support for Lazy compressed string fields. Thanks to Mike Klaas.
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@507009 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
95bab8401f
commit
09930c9349
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue