From 65d22acbbb2d837672b816039fb375741351c750 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 26 Sep 2012 19:16:37 +0000 Subject: [PATCH] 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 --- lucene/CHANGES.txt | 4 ++++ .../codecs/simpletext/SimpleTextStoredFieldsReader.java | 3 +-- .../lucene/codecs/lucene40/Lucene40StoredFieldsReader.java | 2 +- .../apache/lucene/document/DocumentStoredFieldVisitor.java | 4 ++-- .../java/org/apache/lucene/index/StoredFieldVisitor.java | 6 ++++-- .../org/apache/lucene/index/FieldFilterAtomicReader.java | 4 ++-- .../src/java/org/apache/solr/search/SolrIndexSearcher.java | 4 ++-- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index f8d287d312b..56061e561e8 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -139,6 +139,10 @@ API Changes Bits as liveDocs, then use the flex apis (fields(), terms(), etc) directly. (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 * LUCENE-4423: DocumentStoredFieldVisitor.binaryField ignored offset and diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsReader.java index 3cbbb894f83..4ca78b22a04 100644 --- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsReader.java +++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsReader.java @@ -139,10 +139,9 @@ public class SimpleTextStoredFieldsReader extends StoredFieldsReader { if (type == TYPE_STRING) { visitor.stringField(fieldInfo, new String(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, "UTF-8")); } else if (type == TYPE_BINARY) { - // TODO: who owns the bytes? byte[] copy = new byte[scratch.length-VALUE.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) { UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, scratchUTF16); visitor.intField(fieldInfo, Integer.parseInt(scratchUTF16.toString())); diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java index 3ab1b586819..bcdcdae83be 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsReader.java @@ -188,7 +188,7 @@ public final class Lucene40StoredFieldsReader extends StoredFieldsReader impleme byte bytes[] = new byte[length]; fieldsStream.readBytes(bytes, 0, length); if ((bits & FIELD_IS_BINARY) != 0) { - visitor.binaryField(info, bytes, 0, bytes.length); + visitor.binaryField(info, bytes); } else { visitor.stringField(info, new String(bytes, 0, bytes.length, IOUtils.CHARSET_UTF_8)); } diff --git a/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java b/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java index a8927363dc3..340f2c41a13 100644 --- a/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java +++ b/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java @@ -58,8 +58,8 @@ public class DocumentStoredFieldVisitor extends StoredFieldVisitor { } @Override - public void binaryField(FieldInfo fieldInfo, byte[] value, int offset, int length) throws IOException { - doc.add(new StoredField(fieldInfo.name, value, offset, length)); + public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException { + doc.add(new StoredField(fieldInfo.name, value)); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/index/StoredFieldVisitor.java b/lucene/core/src/java/org/apache/lucene/index/StoredFieldVisitor.java index 9967ca99a24..88ead6467cf 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StoredFieldVisitor.java +++ b/lucene/core/src/java/org/apache/lucene/index/StoredFieldVisitor.java @@ -41,8 +41,10 @@ public abstract class StoredFieldVisitor { protected StoredFieldVisitor() { } - /** Process a binary field. */ - public void binaryField(FieldInfo fieldInfo, byte[] value, int offset, int length) throws IOException { + /** Process a binary field. + * @param value newly allocated byte array with the binary contents. + */ + public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException { } /** Process a string field */ diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/FieldFilterAtomicReader.java b/lucene/test-framework/src/java/org/apache/lucene/index/FieldFilterAtomicReader.java index 6744e2bda9a..f79ac4de076 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/index/FieldFilterAtomicReader.java +++ b/lucene/test-framework/src/java/org/apache/lucene/index/FieldFilterAtomicReader.java @@ -72,8 +72,8 @@ public final class FieldFilterAtomicReader extends FilterAtomicReader { public void document(final int docID, final StoredFieldVisitor visitor) throws IOException { super.document(docID, new StoredFieldVisitor() { @Override - public void binaryField(FieldInfo fieldInfo, byte[] value, int offset, int length) throws IOException { - visitor.binaryField(fieldInfo, value, offset, length); + public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException { + visitor.binaryField(fieldInfo, value); } @Override diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java index 256f80c46b4..a3645949eac 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -451,8 +451,8 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrIn } @Override - public void binaryField(FieldInfo fieldInfo, byte[] value, int offset, int length) throws IOException { - doc.add(new StoredField(fieldInfo.name, value, offset, length)); + public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException { + doc.add(new StoredField(fieldInfo.name, value)); } @Override