LUCENE-4425: Unclear documentation of StoredFieldVisitor.binaryValue

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1390683 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-09-26 19:16:37 +00:00
parent bddab9a355
commit 65d22acbbb
7 changed files with 16 additions and 11 deletions

View File

@ -139,6 +139,10 @@ API Changes
Bits as liveDocs, then use the flex apis (fields(), terms(), etc) directly. Bits as liveDocs, then use the flex apis (fields(), terms(), etc) directly.
(Mike McCandless, Robert Muir) (Mike McCandless, Robert Muir)
* LUCENE-4425: clarify documentation of StoredFieldVisitor.binaryValue
and simplify the api to binaryField(FieldInfo, byte[]).
(Adrien Grand, Robert Muir)
Bug Fixes Bug Fixes
* LUCENE-4423: DocumentStoredFieldVisitor.binaryField ignored offset and * LUCENE-4423: DocumentStoredFieldVisitor.binaryField ignored offset and

View File

@ -139,10 +139,9 @@ public class SimpleTextStoredFieldsReader extends StoredFieldsReader {
if (type == TYPE_STRING) { if (type == TYPE_STRING) {
visitor.stringField(fieldInfo, new String(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, "UTF-8")); visitor.stringField(fieldInfo, new String(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, "UTF-8"));
} else if (type == TYPE_BINARY) { } else if (type == TYPE_BINARY) {
// TODO: who owns the bytes?
byte[] copy = new byte[scratch.length-VALUE.length]; byte[] copy = new byte[scratch.length-VALUE.length];
System.arraycopy(scratch.bytes, scratch.offset+VALUE.length, copy, 0, copy.length); System.arraycopy(scratch.bytes, scratch.offset+VALUE.length, copy, 0, copy.length);
visitor.binaryField(fieldInfo, copy, 0, copy.length); visitor.binaryField(fieldInfo, copy);
} else if (type == TYPE_INT) { } else if (type == TYPE_INT) {
UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, scratchUTF16); UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, scratchUTF16);
visitor.intField(fieldInfo, Integer.parseInt(scratchUTF16.toString())); visitor.intField(fieldInfo, Integer.parseInt(scratchUTF16.toString()));

View File

@ -188,7 +188,7 @@ public final class Lucene40StoredFieldsReader extends StoredFieldsReader impleme
byte bytes[] = new byte[length]; byte bytes[] = new byte[length];
fieldsStream.readBytes(bytes, 0, length); fieldsStream.readBytes(bytes, 0, length);
if ((bits & FIELD_IS_BINARY) != 0) { if ((bits & FIELD_IS_BINARY) != 0) {
visitor.binaryField(info, bytes, 0, bytes.length); visitor.binaryField(info, bytes);
} else { } else {
visitor.stringField(info, new String(bytes, 0, bytes.length, IOUtils.CHARSET_UTF_8)); visitor.stringField(info, new String(bytes, 0, bytes.length, IOUtils.CHARSET_UTF_8));
} }

View File

@ -58,8 +58,8 @@ public class DocumentStoredFieldVisitor extends StoredFieldVisitor {
} }
@Override @Override
public void binaryField(FieldInfo fieldInfo, byte[] value, int offset, int length) throws IOException { public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException {
doc.add(new StoredField(fieldInfo.name, value, offset, length)); doc.add(new StoredField(fieldInfo.name, value));
} }
@Override @Override

View File

@ -41,8 +41,10 @@ public abstract class StoredFieldVisitor {
protected StoredFieldVisitor() { protected StoredFieldVisitor() {
} }
/** Process a binary field. */ /** Process a binary field.
public void binaryField(FieldInfo fieldInfo, byte[] value, int offset, int length) throws IOException { * @param value newly allocated byte array with the binary contents.
*/
public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException {
} }
/** Process a string field */ /** Process a string field */

View File

@ -72,8 +72,8 @@ public final class FieldFilterAtomicReader extends FilterAtomicReader {
public void document(final int docID, final StoredFieldVisitor visitor) throws IOException { public void document(final int docID, final StoredFieldVisitor visitor) throws IOException {
super.document(docID, new StoredFieldVisitor() { super.document(docID, new StoredFieldVisitor() {
@Override @Override
public void binaryField(FieldInfo fieldInfo, byte[] value, int offset, int length) throws IOException { public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException {
visitor.binaryField(fieldInfo, value, offset, length); visitor.binaryField(fieldInfo, value);
} }
@Override @Override

View File

@ -451,8 +451,8 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrIn
} }
@Override @Override
public void binaryField(FieldInfo fieldInfo, byte[] value, int offset, int length) throws IOException { public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException {
doc.add(new StoredField(fieldInfo.name, value, offset, length)); doc.add(new StoredField(fieldInfo.name, value));
} }
@Override @Override