From 1b8048415a6fa655664c0f5012b9095ea04a659e Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Thu, 5 Jul 2012 20:53:09 +0000 Subject: [PATCH 01/13] Create branch for LUCENE-3312 git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1357905 13f79535-47bb-0310-9956-ffa450edef68 From 1db6d571ebaac087d7a6ba783cdfb9d6e0050b8c Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Thu, 5 Jul 2012 21:37:19 +0000 Subject: [PATCH 02/13] Commit lucene-3312-patch-06.patch (merged to current trunk and formatting changes in IR removed) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1357938 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/codecs/DocValuesConsumer.java | 16 +- .../lucene/codecs/StoredFieldsWriter.java | 34 +-- .../lucene40/Lucene40StoredFieldsWriter.java | 8 +- .../lucene/codecs/lucene40/values/Bytes.java | 3 +- .../values/FixedStraightBytesImpl.java | 8 +- .../lucene/codecs/lucene40/values/Floats.java | 3 +- .../lucene/codecs/lucene40/values/Ints.java | 3 +- .../lucene40/values/PackedIntValues.java | 3 +- .../lucene40/values/VarStraightBytesImpl.java | 8 +- .../SimpleTextDocValuesConsumer.java | 4 +- .../SimpleTextStoredFieldsWriter.java | 4 +- .../lucene/document/ByteDocValuesField.java | 2 +- .../document/DerefBytesDocValuesField.java | 2 +- .../org/apache/lucene/document/Document.java | 97 +++++++-- .../document/DocumentStoredFieldVisitor.java | 9 +- .../lucene/document/DoubleDocValuesField.java | 2 +- .../apache/lucene/document/DoubleField.java | 1 - .../org/apache/lucene/document/Field.java | 3 +- .../org/apache/lucene/document/FieldType.java | 27 +-- .../lucene/document/FloatDocValuesField.java | 2 +- .../apache/lucene/document/FloatField.java | 1 - .../lucene/document/IntDocValuesField.java | 2 +- .../org/apache/lucene/document/IntField.java | 1 - .../lucene/document/LongDocValuesField.java | 2 +- .../document/PackedLongDocValuesField.java | 2 +- .../lucene/document/ShortDocValuesField.java | 2 +- .../document/SortedBytesDocValuesField.java | 2 +- .../lucene/document/StoredDocument.java | 201 ++++++++++++++++++ .../apache/lucene/document/StoredField.java | 12 +- .../document/StraightBytesDocValuesField.java | 2 +- .../org/apache/lucene/index/CheckIndex.java | 3 +- .../lucene/index/DocFieldProcessor.java | 15 +- .../lucene/index/DocInverterPerField.java | 2 +- .../apache/lucene/index/DocumentsWriter.java | 4 +- .../index/DocumentsWriterPerThread.java | 8 +- .../org/apache/lucene/index/FieldInfos.java | 2 +- .../index/FreqProxTermsWriterPerField.java | 7 +- .../apache/lucene/index/IndexDocument.java | 26 +++ .../org/apache/lucene/index/IndexReader.java | 9 +- .../org/apache/lucene/index/IndexWriter.java | 16 +- .../apache/lucene/index/IndexableField.java | 20 +- .../lucene/index/IndexableFieldType.java | 10 - .../java/org/apache/lucene/index/Norm.java | 5 +- .../lucene/index/NormsConsumerPerField.java | 4 +- .../PersistentSnapshotDeletionPolicy.java | 14 +- .../apache/lucene/index/StorableField.java | 44 ++++ .../lucene/index/StorableFieldType.java | 25 +++ .../lucene/index/StoredFieldsConsumer.java | 8 +- .../index/TermVectorsConsumerPerField.java | 2 +- .../apache/lucene/search/IndexSearcher.java | 5 +- .../org/apache/lucene/search/NRTManager.java | 17 +- .../apache/lucene/util/FilterIterator.java | 68 ++++++ 52 files changed, 611 insertions(+), 169 deletions(-) create mode 100644 lucene/core/src/java/org/apache/lucene/document/StoredDocument.java create mode 100644 lucene/core/src/java/org/apache/lucene/index/IndexDocument.java create mode 100644 lucene/core/src/java/org/apache/lucene/index/StorableField.java create mode 100644 lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java create mode 100644 lucene/core/src/java/org/apache/lucene/util/FilterIterator.java diff --git a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java index 4e1e5362b5e..c052dc3caa9 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/DocValuesConsumer.java @@ -28,21 +28,23 @@ import org.apache.lucene.document.LongDocValuesField; import org.apache.lucene.document.PackedLongDocValuesField; import org.apache.lucene.document.ShortDocValuesField; import org.apache.lucene.document.SortedBytesDocValuesField; +import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StraightBytesDocValuesField; import org.apache.lucene.index.AtomicReader; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.index.MergeState; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; /** - * Abstract API that consumes {@link IndexableField}s. + * Abstract API that consumes {@link StorableField}s. * {@link DocValuesConsumer} are always associated with a specific field and * segments. Concrete implementations of this API write the given - * {@link IndexableField} into a implementation specific format depending on + * {@link StorableField} into a implementation specific format depending on * the fields meta-data. * * @lucene.experimental @@ -53,7 +55,7 @@ public abstract class DocValuesConsumer { protected abstract Type getType(); /** - * Adds the given {@link IndexableField} instance to this + * Adds the given {@link StorableField} instance to this * {@link DocValuesConsumer} * * @param docID @@ -64,7 +66,7 @@ public abstract class DocValuesConsumer { * @throws IOException * if an {@link IOException} occurs */ - public abstract void add(int docID, IndexableField value) + public abstract void add(int docID, StorableField value) throws IOException; /** @@ -73,7 +75,7 @@ public abstract class DocValuesConsumer { * @param docCount * the total number of documents in this {@link DocValuesConsumer}. * Must be greater than or equal the last given docID to - * {@link #add(int, IndexableField)}. + * {@link #add(int, StorableField)}. * @throws IOException */ public abstract void finish(int docCount) throws IOException; @@ -136,7 +138,7 @@ public abstract class DocValuesConsumer { assert source != null; int docID = docBase; final Type type = getType(); - final Field scratchField; + final StoredField scratchField; switch(type) { case VAR_INTS: scratchField = new PackedLongDocValuesField("", (long) 0); @@ -202,7 +204,7 @@ public abstract class DocValuesConsumer { * ID must always be greater than the previous ID or 0 if called the * first time. */ - protected void mergeDoc(Field scratchField, Source source, int docID, int sourceDoc) + protected void mergeDoc(StoredField scratchField, Source source, int docID, int sourceDoc) throws IOException { switch(getType()) { case BYTES_FIXED_DEREF: diff --git a/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java index 7e67b50c070..cb55a414fa5 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java @@ -1,5 +1,17 @@ package org.apache.lucene.codecs; +import java.io.Closeable; +import java.io.IOException; + +import org.apache.lucene.document.Document; +import org.apache.lucene.document.StoredDocument; +import org.apache.lucene.index.FieldInfo; +import org.apache.lucene.index.FieldInfos; +import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.MergeState; +import org.apache.lucene.index.StorableField; +import org.apache.lucene.util.Bits; + /** * Copyright 2004 The Apache Software Foundation * @@ -33,7 +45,7 @@ import org.apache.lucene.util.Bits; *
    *
  1. For every document, {@link #startDocument(int)} is called, * informing the Codec how many fields will be written. - *
  2. {@link #writeField(FieldInfo, IndexableField)} is called for + *
  3. {@link #writeField(FieldInfo, StorableField)} is called for * each field in the document. *
  4. After all documents have been written, {@link #finish(FieldInfos, int)} * is called for verification/sanity-checks. @@ -45,14 +57,14 @@ import org.apache.lucene.util.Bits; public abstract class StoredFieldsWriter implements Closeable { /** Called before writing the stored fields of the document. - * {@link #writeField(FieldInfo, IndexableField)} will be called + * {@link #writeField(FieldInfo, StorableField)} will be called * numStoredFields times. Note that this is * called even if the document has no stored fields, in * this case numStoredFields will be zero. */ public abstract void startDocument(int numStoredFields) throws IOException; /** Writes a single stored field. */ - public abstract void writeField(FieldInfo info, IndexableField field) throws IOException; + public abstract void writeField(FieldInfo info, StorableField field) throws IOException; /** Aborts writing entirely, implementation should remove * any partially-written files, etc. */ @@ -69,7 +81,7 @@ public abstract class StoredFieldsWriter implements Closeable { /** Merges in the stored fields from the readers in * mergeState. The default implementation skips * over deleted documents, and uses {@link #startDocument(int)}, - * {@link #writeField(FieldInfo, IndexableField)}, and {@link #finish(FieldInfos, int)}, + * {@link #writeField(FieldInfo, StorableField)}, and {@link #finish(int)}, * returning the number of documents that were written. * Implementations can override this method for more sophisticated * merging (bulk-byte copying, etc). */ @@ -89,7 +101,7 @@ public abstract class StoredFieldsWriter implements Closeable { // on the fly? // NOTE: it's very important to first assign to doc then pass it to // fieldsWriter.addDocument; see LUCENE-1282 - Document doc = reader.document(i); + StoredDocument doc = reader.document(i); addDocument(doc, mergeState.fieldInfos); docCount++; mergeState.checkAbort.work(300); @@ -100,20 +112,16 @@ public abstract class StoredFieldsWriter implements Closeable { } /** sugar method for startDocument() + writeField() for every stored field in the document */ - protected final void addDocument(Iterable doc, FieldInfos fieldInfos) throws IOException { + protected final void addDocument(Iterable doc, FieldInfos fieldInfos) throws IOException { int storedCount = 0; - for (IndexableField field : doc) { - if (field.fieldType().stored()) { - storedCount++; - } + for (StorableField field : doc) { + storedCount++; } startDocument(storedCount); - for (IndexableField field : doc) { - if (field.fieldType().stored()) { + for (StorableField field : doc) { writeField(fieldInfos.fieldInfo(field.name()), field); - } } } } diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java index ed699cdfabb..2d33fe8a0a3 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java @@ -22,6 +22,7 @@ import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.codecs.StoredFieldsReader; import org.apache.lucene.codecs.StoredFieldsWriter; import org.apache.lucene.document.Document; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.AtomicReader; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; @@ -29,6 +30,7 @@ import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.MergeState; import org.apache.lucene.index.SegmentReader; +import org.apache.lucene.index.StorableField; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -131,7 +133,7 @@ public final class Lucene40StoredFieldsWriter extends StoredFieldsWriter { IndexFileNames.segmentFileName(segment, "", FIELDS_INDEX_EXTENSION)); } - public void writeField(FieldInfo info, IndexableField field) throws IOException { + public void writeField(FieldInfo info, StorableField field) throws IOException { fieldsStream.writeVInt(info.number); int bits = 0; final BytesRef bytes; @@ -297,7 +299,7 @@ public final class Lucene40StoredFieldsWriter extends StoredFieldsWriter { // on the fly? // NOTE: it's very important to first assign to doc then pass it to // fieldsWriter.addDocument; see LUCENE-1282 - Document doc = reader.document(j); + StoredDocument doc = reader.document(j); addDocument(doc, mergeState.fieldInfos); docCount++; mergeState.checkAbort.work(300); @@ -324,7 +326,7 @@ public final class Lucene40StoredFieldsWriter extends StoredFieldsWriter { for (; docCount < maxDoc; docCount++) { // NOTE: it's very important to first assign to doc then pass it to // fieldsWriter.addDocument; see LUCENE-1282 - Document doc = reader.document(docCount); + StoredDocument doc = reader.document(docCount); addDocument(doc, mergeState.fieldInfos); mergeState.checkAbort.work(300); } diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java index cbec979bd78..dd7599e2bc8 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Bytes.java @@ -30,6 +30,7 @@ import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.store.DataOutput; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; @@ -420,7 +421,7 @@ public final class Bytes { } @Override - public void add(int docID, IndexableField value) throws IOException { + public void add(int docID, StorableField value) throws IOException { BytesRef bytes = value.binaryValue(); assert bytes != null; if (bytes.length == 0) { // default value - skip it diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/FixedStraightBytesImpl.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/FixedStraightBytesImpl.java index bc072adc586..0ba456afdeb 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/FixedStraightBytesImpl.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/FixedStraightBytesImpl.java @@ -22,12 +22,12 @@ import java.io.IOException; import org.apache.lucene.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.codecs.lucene40.values.Bytes.BytesSourceBase; import org.apache.lucene.codecs.lucene40.values.Bytes.BytesWriterBase; +import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StraightBytesDocValuesField; -import org.apache.lucene.document.Field; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -74,7 +74,7 @@ class FixedStraightBytesImpl { } @Override - public void add(int docID, IndexableField value) throws IOException { + public void add(int docID, StorableField value) throws IOException { final BytesRef bytes = value.binaryValue(); assert bytes != null; assert lastDocID < docID; @@ -201,7 +201,7 @@ class FixedStraightBytesImpl { } @Override - protected void mergeDoc(Field scratchField, Source source, int docID, int sourceDoc) throws IOException { + protected void mergeDoc(StoredField scratchField, Source source, int docID, int sourceDoc) throws IOException { assert lastDocID < docID; setMergeBytes(source, sourceDoc); if (size == -1) { diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java index c8a96fd5440..e8724a3df5a 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Floats.java @@ -24,6 +24,7 @@ import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -88,7 +89,7 @@ public class Floats { } @Override - public void add(int docID, IndexableField value) throws IOException { + public void add(int docID, StorableField value) throws IOException { template.toBytes(value.numericValue().doubleValue(), bytesRef); bytesSpareField.setBytesValue(bytesRef); super.add(docID, bytesSpareField); diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java index 2d937f6b25d..33ef01f5c4f 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/Ints.java @@ -25,6 +25,7 @@ import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -112,7 +113,7 @@ public final class Ints { } @Override - public void add(int docID, IndexableField value) throws IOException { + public void add(int docID, StorableField value) throws IOException { template.toBytes(value.numericValue().longValue(), bytesRef); bytesSpareField.setBytesValue(bytesRef); super.add(docID, bytesSpareField); diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java index c40534f0af2..13cacf9a199 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/PackedIntValues.java @@ -26,6 +26,7 @@ import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -126,7 +127,7 @@ class PackedIntValues { } @Override - public void add(int docID, IndexableField docValue) throws IOException { + public void add(int docID, StorableField docValue) throws IOException { final long v = docValue.numericValue().longValue(); assert lastDocId < docID; if (!started) { diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java index 126c11da02d..7efe24c807c 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/values/VarStraightBytesImpl.java @@ -22,11 +22,11 @@ import java.io.IOException; import org.apache.lucene.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.codecs.lucene40.values.Bytes.BytesSourceBase; import org.apache.lucene.codecs.lucene40.values.Bytes.BytesWriterBase; -import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredField; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -86,7 +86,7 @@ class VarStraightBytesImpl { } @Override - public void add(int docID, IndexableField value) throws IOException { + public void add(int docID, StorableField value) throws IOException { final BytesRef bytes = value.binaryValue(); assert bytes != null; assert !merge; @@ -156,7 +156,7 @@ class VarStraightBytesImpl { } @Override - protected void mergeDoc(Field scratchField, Source source, int docID, int sourceDoc) throws IOException { + protected void mergeDoc(StoredField scratchField, Source source, int docID, int sourceDoc) throws IOException { assert merge; assert lastDocID < docID; source.getBytes(sourceDoc, bytesRef); diff --git a/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesConsumer.java index f662b220cbe..96aac281faa 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesConsumer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextDocValuesConsumer.java @@ -21,7 +21,7 @@ import org.apache.lucene.codecs.DocValuesArraySource; import org.apache.lucene.codecs.DocValuesConsumer; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.IndexFileNames; -import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; @@ -72,7 +72,7 @@ public class SimpleTextDocValuesConsumer extends DocValuesConsumer { } @Override - public void add(int docID, IndexableField value) throws IOException { + public void add(int docID, StorableField value) throws IOException { assert docID >= 0; final int ord, vSize; switch (type) { diff --git a/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsWriter.java index 3d38879e5c0..6a9b223c2a5 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextStoredFieldsWriter.java @@ -23,7 +23,7 @@ import org.apache.lucene.codecs.StoredFieldsWriter; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.IndexFileNames; -import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; @@ -89,7 +89,7 @@ public class SimpleTextStoredFieldsWriter extends StoredFieldsWriter { } @Override - public void writeField(FieldInfo info, IndexableField field) throws IOException { + public void writeField(FieldInfo info, StorableField field) throws IOException { write(FIELD); write(Integer.toString(info.number)); newLine(); diff --git a/lucene/core/src/java/org/apache/lucene/document/ByteDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/ByteDocValuesField.java index 915f5f15c4e..707ec2e8bc4 100644 --- a/lucene/core/src/java/org/apache/lucene/document/ByteDocValuesField.java +++ b/lucene/core/src/java/org/apache/lucene/document/ByteDocValuesField.java @@ -36,7 +36,7 @@ import org.apache.lucene.index.DocValues; * @see DocValues for further information * */ -public class ByteDocValuesField extends Field { +public class ByteDocValuesField extends StoredField { public static final FieldType TYPE = new FieldType(); static { diff --git a/lucene/core/src/java/org/apache/lucene/document/DerefBytesDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/DerefBytesDocValuesField.java index 99d68291463..a4f9ab2f763 100644 --- a/lucene/core/src/java/org/apache/lucene/document/DerefBytesDocValuesField.java +++ b/lucene/core/src/java/org/apache/lucene/document/DerefBytesDocValuesField.java @@ -41,7 +41,7 @@ import org.apache.lucene.util.BytesRef; * @see DocValues for further information * */ -public class DerefBytesDocValuesField extends Field { +public class DerefBytesDocValuesField extends StoredField { // TODO: ideally indexer figures out var vs fixed on its own!? public static final FieldType TYPE_FIXED_LEN = new FieldType(); diff --git a/lucene/core/src/java/org/apache/lucene/document/Document.java b/lucene/core/src/java/org/apache/lucene/document/Document.java index da8424b54c4..4f3251ee551 100644 --- a/lucene/core/src/java/org/apache/lucene/document/Document.java +++ b/lucene/core/src/java/org/apache/lucene/document/Document.java @@ -19,11 +19,16 @@ package org.apache.lucene.document; import java.util.*; +import org.apache.lucene.index.IndexDocument; import org.apache.lucene.index.IndexReader; // for javadoc import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.IndexSearcher; // for javadoc import org.apache.lucene.search.ScoreDoc; // for javadoc import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.FilterIterator; + +import com.google.common.collect.AbstractIterator; /** Documents are the unit of indexing and search. * @@ -38,18 +43,15 @@ import org.apache.lucene.util.BytesRef; * ScoreDoc#doc} or {@link IndexReader#document(int)}. */ -public final class Document implements Iterable { +public final class Document implements IndexDocument{ - private final List fields = new ArrayList(); + private final List fields = new ArrayList(); + + //private final List fields /** Constructs a new document with no fields. */ public Document() {} - - @Override - public Iterator iterator() { - return fields.iterator(); - } - + /** *

    Adds a field to a document. Several fields may be added with * the same name. In this case, if the fields are indexed, their text is @@ -60,7 +62,7 @@ public final class Document implements Iterable { * a document has to be deleted from an index and a new changed version of that * document has to be added.

    */ - public final void add(IndexableField field) { + public final void add(Field field) { fields.add(field); } @@ -75,9 +77,9 @@ public final class Document implements Iterable { * document has to be added.

    */ public final void removeField(String name) { - Iterator it = fields.iterator(); + Iterator it = fields.iterator(); while (it.hasNext()) { - IndexableField field = it.next(); + Field field = it.next(); if (field.name().equals(name)) { it.remove(); return; @@ -95,9 +97,9 @@ public final class Document implements Iterable { * document has to be added.

    */ public final void removeFields(String name) { - Iterator it = fields.iterator(); + Iterator it = fields.iterator(); while (it.hasNext()) { - IndexableField field = it.next(); + Field field = it.next(); if (field.name().equals(name)) { it.remove(); } @@ -116,7 +118,10 @@ public final class Document implements Iterable { */ public final BytesRef[] getBinaryValues(String name) { final List result = new ArrayList(); - for (IndexableField field : fields) { + Iterator it = storedFieldsIterator(); + + while (it.hasNext()) { + StorableField field = it.next(); if (field.name().equals(name)) { final BytesRef bytes = field.binaryValue(); if (bytes != null) { @@ -138,7 +143,10 @@ public final class Document implements Iterable { * @return a byte[] containing the binary field value or null */ public final BytesRef getBinaryValue(String name) { - for (IndexableField field : fields) { + Iterator it = storedFieldsIterator(); + + while (it.hasNext()) { + StorableField field = it.next(); if (field.name().equals(name)) { final BytesRef bytes = field.binaryValue(); if (bytes != null) { @@ -188,7 +196,12 @@ public final class Document implements Iterable { * IndexReader#document(int)}. */ public final List getFields() { - return fields; + List result = new ArrayList(); + for (IndexableField field : fields) { + result.add(field); + } + + return result; } private final static String[] NO_STRINGS = new String[0]; @@ -205,7 +218,10 @@ public final class Document implements Iterable { */ public final String[] getValues(String name) { List result = new ArrayList(); - for (IndexableField field : fields) { + Iterator it = storedFieldsIterator(); + + while (it.hasNext()) { + StorableField field = it.next(); if (field.name().equals(name) && field.stringValue() != null) { result.add(field.stringValue()); } @@ -227,7 +243,10 @@ public final class Document implements Iterable { * the actual numeric field instance back, use {@link #getField}. */ public final String get(String name) { - for (IndexableField field : fields) { + Iterator it = storedFieldsIterator(); + + while (it.hasNext()) { + StorableField field = it.next(); if (field.name().equals(name) && field.stringValue() != null) { return field.stringValue(); } @@ -249,4 +268,46 @@ public final class Document implements Iterable { buffer.append(">"); return buffer.toString(); } + + @Override + public Iterable indexableFields() { + Iterator it = indexedFieldsIterator(); + + List result = new ArrayList(); + while(it.hasNext()) { + result.add(it.next()); + } + + return result; + } + + @Override + public Iterable storableFields() { + Iterator it = storedFieldsIterator(); + + List result = new ArrayList(); + while(it.hasNext()) { + result.add(it.next()); + } + + return result; + } + + public Iterator storedFieldsIterator() { + return new FilterIterator(fields.iterator()) { + @Override + protected boolean predicateFunction(Field field) { + return field.type.stored(); + } + }; + } + + public Iterator indexedFieldsIterator() { + return new FilterIterator(fields.iterator()) { + @Override + protected boolean predicateFunction(Field field) { + return field.type.indexed(); + } + }; + } } 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 275dc94374f..9b72651c5fa 100644 --- a/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java +++ b/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java @@ -34,7 +34,7 @@ import org.apache.lucene.index.StoredFieldVisitor; * @lucene.experimental */ public class DocumentStoredFieldVisitor extends StoredFieldVisitor { - private final Document doc = new Document(); + private final StoredDocument doc = new StoredDocument(); private final Set fieldsToAdd; /** Load only fields named in the provided Set<String>. */ @@ -62,12 +62,15 @@ public class DocumentStoredFieldVisitor extends StoredFieldVisitor { @Override public void stringField(FieldInfo fieldInfo, String value) throws IOException { + /* final FieldType ft = new FieldType(TextField.TYPE_STORED); ft.setStoreTermVectors(fieldInfo.hasVectors()); ft.setIndexed(fieldInfo.isIndexed()); ft.setOmitNorms(fieldInfo.omitsNorms()); ft.setIndexOptions(fieldInfo.getIndexOptions()); - doc.add(new Field(fieldInfo.name, value, ft)); + */ + doc.add(new StoredField(fieldInfo.name, value)); + //doc.add(new Field(fieldInfo.name, value, ft)); } @Override @@ -95,7 +98,7 @@ public class DocumentStoredFieldVisitor extends StoredFieldVisitor { return fieldsToAdd == null || fieldsToAdd.contains(fieldInfo.name) ? Status.YES : Status.NO; } - public Document getDocument() { + public StoredDocument getDocument() { return doc; } } diff --git a/lucene/core/src/java/org/apache/lucene/document/DoubleDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/DoubleDocValuesField.java index 1a0c225ee38..c7d0fb113ed 100644 --- a/lucene/core/src/java/org/apache/lucene/document/DoubleDocValuesField.java +++ b/lucene/core/src/java/org/apache/lucene/document/DoubleDocValuesField.java @@ -36,7 +36,7 @@ import org.apache.lucene.index.DocValues; * @see DocValues for further information * */ -public class DoubleDocValuesField extends Field { +public class DoubleDocValuesField extends StoredField { public static final FieldType TYPE = new FieldType(); static { diff --git a/lucene/core/src/java/org/apache/lucene/document/DoubleField.java b/lucene/core/src/java/org/apache/lucene/document/DoubleField.java index 32a01460d38..17fb53374d5 100644 --- a/lucene/core/src/java/org/apache/lucene/document/DoubleField.java +++ b/lucene/core/src/java/org/apache/lucene/document/DoubleField.java @@ -116,7 +116,6 @@ public final class DoubleField extends Field { public static final FieldType TYPE_NOT_STORED = new FieldType(); static { - TYPE_NOT_STORED.setIndexed(true); TYPE_NOT_STORED.setTokenized(true); TYPE_NOT_STORED.setOmitNorms(true); TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS_ONLY); diff --git a/lucene/core/src/java/org/apache/lucene/document/Field.java b/lucene/core/src/java/org/apache/lucene/document/Field.java index 47cd3e44f27..e12f86008d4 100644 --- a/lucene/core/src/java/org/apache/lucene/document/Field.java +++ b/lucene/core/src/java/org/apache/lucene/document/Field.java @@ -31,6 +31,7 @@ import org.apache.lucene.index.IndexWriter; // javadocs import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.IndexableFieldType; import org.apache.lucene.index.Norm; // javadocs +import org.apache.lucene.index.StorableField; import org.apache.lucene.util.BytesRef; import org.apache.lucene.index.FieldInvertState; // javadocs @@ -59,7 +60,7 @@ import org.apache.lucene.index.FieldInvertState; // javadocs * Field it is used in. It is strongly recommended that no * changes be made after Field instantiation. */ -public class Field implements IndexableField { +public class Field implements IndexableField, StorableField { protected final FieldType type; protected final String name; diff --git a/lucene/core/src/java/org/apache/lucene/document/FieldType.java b/lucene/core/src/java/org/apache/lucene/document/FieldType.java index 07cf30d11e5..facfcc75728 100644 --- a/lucene/core/src/java/org/apache/lucene/document/FieldType.java +++ b/lucene/core/src/java/org/apache/lucene/document/FieldType.java @@ -20,13 +20,14 @@ package org.apache.lucene.document; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.IndexableFieldType; +import org.apache.lucene.index.StorableFieldType; import org.apache.lucene.search.NumericRangeQuery; // javadocs import org.apache.lucene.util.NumericUtils; /** * Describes the properties of a field. */ -public class FieldType implements IndexableFieldType { +public class FieldType implements IndexableFieldType, StorableFieldType { /** Data type of the numeric value * @since 3.2 @@ -41,10 +42,10 @@ public class FieldType implements IndexableFieldType { private boolean storeTermVectorPositions; private boolean omitNorms; private IndexOptions indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; - private DocValues.Type docValueType; private NumericType numericType; private boolean frozen; private int numericPrecisionStep = NumericUtils.PRECISION_STEP_DEFAULT; + private DocValues.Type docValueType; public FieldType(FieldType ref) { this.indexed = ref.indexed(); @@ -150,16 +151,6 @@ public class FieldType implements IndexableFieldType { this.indexOptions = value; } - public void setDocValueType(DocValues.Type type) { - checkIfFrozen(); - docValueType = type; - } - - @Override - public DocValues.Type docValueType() { - return docValueType; - } - public void setNumericType(NumericType type) { checkIfFrozen(); numericType = type; @@ -238,4 +229,16 @@ public class FieldType implements IndexableFieldType { return result.toString(); } + + /* from StorableFieldType */ + + @Override + public DocValues.Type docValueType() { + return docValueType; + } + + public void setDocValueType(DocValues.Type type) { + checkIfFrozen(); + docValueType = type; + } } diff --git a/lucene/core/src/java/org/apache/lucene/document/FloatDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/FloatDocValuesField.java index 6add5e56866..178a82a0ec3 100644 --- a/lucene/core/src/java/org/apache/lucene/document/FloatDocValuesField.java +++ b/lucene/core/src/java/org/apache/lucene/document/FloatDocValuesField.java @@ -35,7 +35,7 @@ import org.apache.lucene.index.DocValues; * @see DocValues for further information * */ -public class FloatDocValuesField extends Field { +public class FloatDocValuesField extends StoredField { public static final FieldType TYPE = new FieldType(); static { diff --git a/lucene/core/src/java/org/apache/lucene/document/FloatField.java b/lucene/core/src/java/org/apache/lucene/document/FloatField.java index dcb5ea76cfc..9ac68f7b91f 100644 --- a/lucene/core/src/java/org/apache/lucene/document/FloatField.java +++ b/lucene/core/src/java/org/apache/lucene/document/FloatField.java @@ -116,7 +116,6 @@ public final class FloatField extends Field { public static final FieldType TYPE_NOT_STORED = new FieldType(); static { - TYPE_NOT_STORED.setIndexed(true); TYPE_NOT_STORED.setTokenized(true); TYPE_NOT_STORED.setOmitNorms(true); TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS_ONLY); diff --git a/lucene/core/src/java/org/apache/lucene/document/IntDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/IntDocValuesField.java index 7b10662a7e3..0193e6909b0 100644 --- a/lucene/core/src/java/org/apache/lucene/document/IntDocValuesField.java +++ b/lucene/core/src/java/org/apache/lucene/document/IntDocValuesField.java @@ -35,7 +35,7 @@ import org.apache.lucene.index.DocValues; * @see DocValues for further information * */ -public class IntDocValuesField extends Field { +public class IntDocValuesField extends StoredField { public static final FieldType TYPE = new FieldType(); static { diff --git a/lucene/core/src/java/org/apache/lucene/document/IntField.java b/lucene/core/src/java/org/apache/lucene/document/IntField.java index 648da431b78..7250d75fc25 100644 --- a/lucene/core/src/java/org/apache/lucene/document/IntField.java +++ b/lucene/core/src/java/org/apache/lucene/document/IntField.java @@ -116,7 +116,6 @@ public final class IntField extends Field { public static final FieldType TYPE_NOT_STORED = new FieldType(); static { - TYPE_NOT_STORED.setIndexed(true); TYPE_NOT_STORED.setTokenized(true); TYPE_NOT_STORED.setOmitNorms(true); TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS_ONLY); diff --git a/lucene/core/src/java/org/apache/lucene/document/LongDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/LongDocValuesField.java index 0b78eb93c4a..2a3f22caac1 100644 --- a/lucene/core/src/java/org/apache/lucene/document/LongDocValuesField.java +++ b/lucene/core/src/java/org/apache/lucene/document/LongDocValuesField.java @@ -35,7 +35,7 @@ import org.apache.lucene.index.DocValues; * @see DocValues for further information * */ -public class LongDocValuesField extends Field { +public class LongDocValuesField extends StoredField { public static final FieldType TYPE = new FieldType(); static { diff --git a/lucene/core/src/java/org/apache/lucene/document/PackedLongDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/PackedLongDocValuesField.java index eceff093ab5..c1e72b3c8eb 100644 --- a/lucene/core/src/java/org/apache/lucene/document/PackedLongDocValuesField.java +++ b/lucene/core/src/java/org/apache/lucene/document/PackedLongDocValuesField.java @@ -39,7 +39,7 @@ import org.apache.lucene.index.AtomicReader; // javadocs * @see DocValues for further information * */ -public class PackedLongDocValuesField extends Field { +public class PackedLongDocValuesField extends StoredField { public static final FieldType TYPE = new FieldType(); static { diff --git a/lucene/core/src/java/org/apache/lucene/document/ShortDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/ShortDocValuesField.java index 2b08803197e..79c0bdee403 100644 --- a/lucene/core/src/java/org/apache/lucene/document/ShortDocValuesField.java +++ b/lucene/core/src/java/org/apache/lucene/document/ShortDocValuesField.java @@ -36,7 +36,7 @@ import org.apache.lucene.index.DocValues; * @see DocValues for further information * */ -public class ShortDocValuesField extends Field { +public class ShortDocValuesField extends StoredField { public static final FieldType TYPE = new FieldType(); static { diff --git a/lucene/core/src/java/org/apache/lucene/document/SortedBytesDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/SortedBytesDocValuesField.java index 07892ced7c6..f8e9ce991f7 100644 --- a/lucene/core/src/java/org/apache/lucene/document/SortedBytesDocValuesField.java +++ b/lucene/core/src/java/org/apache/lucene/document/SortedBytesDocValuesField.java @@ -37,7 +37,7 @@ import org.apache.lucene.util.BytesRef; * @see DocValues for further information * */ -public class SortedBytesDocValuesField extends Field { +public class SortedBytesDocValuesField extends StoredField { // TODO: ideally indexer figures out var vs fixed on its own!? public static final FieldType TYPE_FIXED_LEN = new FieldType(); diff --git a/lucene/core/src/java/org/apache/lucene/document/StoredDocument.java b/lucene/core/src/java/org/apache/lucene/document/StoredDocument.java new file mode 100644 index 00000000000..a2eab0b0931 --- /dev/null +++ b/lucene/core/src/java/org/apache/lucene/document/StoredDocument.java @@ -0,0 +1,201 @@ +package org.apache.lucene.document; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.lucene.index.StorableField; +import org.apache.lucene.util.BytesRef; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class StoredDocument implements Iterable{ + + private final List fields = new ArrayList(); + + + public final void add(StorableField field) { + fields.add(field); + } + + public StorableField[] getFields(String name) { + List result = new ArrayList(); + for (StorableField field : fields) { + if (field.name().equals(name)) { + result.add(field); + } + } + + return result.toArray(new StorableField[result.size()]); + } + + public final StorableField getField(String name) { + for (StorableField field : fields) { + if (field.name().equals(name)) { + return field; + } + } + return null; + } + + public final void removeField(String name) { + Iterator it = fields.iterator(); + while (it.hasNext()) { + StorableField field = it.next(); + if (field.name().equals(name)) { + it.remove(); + return; + } + } + } + + /** + *

    Removes all fields with the given name from the document. + * If there is no field with the specified name, the document remains unchanged.

    + *

    Note that the removeField(s) methods like the add method only make sense + * prior to adding a document to an index. These methods cannot + * be used to change the content of an existing index! In order to achieve this, + * a document has to be deleted from an index and a new changed version of that + * document has to be added.

    + */ + public final void removeFields(String name) { + Iterator it = fields.iterator(); + while (it.hasNext()) { + StorableField field = it.next(); + if (field.name().equals(name)) { + it.remove(); + } + } + } + + public final List getFields() { + return fields; + } + + @Override + public Iterator iterator() { + return this.fields.iterator(); + } + + /** + * Returns an array of byte arrays for of the fields that have the name specified + * as the method parameter. This method returns an empty + * array when there are no matching fields. It never + * returns null. + * + * @param name the name of the field + * @return a byte[][] of binary field values + */ + public final BytesRef[] getBinaryValues(String name) { + final List result = new ArrayList(); + for (StorableField field : fields) { + if (field.name().equals(name)) { + final BytesRef bytes = field.binaryValue(); + if (bytes != null) { + result.add(bytes); + } + } + } + + return result.toArray(new BytesRef[result.size()]); + } + + /** + * Returns an array of bytes for the first (or only) field that has the name + * specified as the method parameter. This method will return null + * if no binary fields with the specified name are available. + * There may be non-binary fields with the same name. + * + * @param name the name of the field. + * @return a byte[] containing the binary field value or null + */ + public final BytesRef getBinaryValue(String name) { + for (StorableField field : fields) { + if (field.name().equals(name)) { + final BytesRef bytes = field.binaryValue(); + if (bytes != null) { + return bytes; + } + } + } + return null; + } + private final static String[] NO_STRINGS = new String[0]; + + /** + * Returns an array of values of the field specified as the method parameter. + * This method returns an empty array when there are no + * matching fields. It never returns null. + * For {@link IntField}, {@link LongField}, {@link + * FloatField} and {@link DoubleField} it returns the string value of the number. If you want + * the actual numeric field instances back, use {@link #getFields}. + * @param name the name of the field + * @return a String[] of field values + */ + public final String[] getValues(String name) { + List result = new ArrayList(); + for (StorableField field : fields) { + if (field.name().equals(name) && field.stringValue() != null) { + result.add(field.stringValue()); + } + } + + if (result.size() == 0) { + return NO_STRINGS; + } + + return result.toArray(new String[result.size()]); + } + + /** Returns the string value of the field with the given name if any exist in + * this document, or null. If multiple fields exist with this name, this + * method returns the first value added. If only binary fields with this name + * exist, returns null. + * For {@link IntField}, {@link LongField}, {@link + * FloatField} and {@link DoubleField} it returns the string value of the number. If you want + * the actual numeric field instance back, use {@link #getField}. + */ + public final String get(String name) { + for (StorableField field : fields) { + if (field.name().equals(name) && field.stringValue() != null) { + return field.stringValue(); + } + } + return null; + } + + public Document asIndexable() { + Document doc = new Document(); + + for (StorableField field : fields) { + Field newField = new Field(field.name(), field.fieldType()); + + newField.fieldsData = field.stringValue(); + if (newField.fieldsData == null) + newField.fieldsData = field.numericValue(); + if (newField.fieldsData == null) + newField.fieldsData = field.binaryValue(); + if (newField.fieldsData == null) + newField.fieldsData = field.readerValue(); + + doc.add(newField); + } + + return doc; + } +} diff --git a/lucene/core/src/java/org/apache/lucene/document/StoredField.java b/lucene/core/src/java/org/apache/lucene/document/StoredField.java index 692768a5a8c..d5e046a87f8 100644 --- a/lucene/core/src/java/org/apache/lucene/document/StoredField.java +++ b/lucene/core/src/java/org/apache/lucene/document/StoredField.java @@ -24,7 +24,7 @@ import org.apache.lucene.util.BytesRef; /** A field whose value is stored so that {@link * IndexSearcher#doc} and {@link IndexReader#document} will * return the field and its value. */ -public final class StoredField extends Field { +public class StoredField extends Field { public final static FieldType TYPE; static { @@ -33,6 +33,16 @@ public final class StoredField extends Field { TYPE.freeze(); } + protected StoredField(String name, FieldType type) { + super(name, type); + this.type.setStored(true); + } + + public StoredField(String name, BytesRef bytes, FieldType type) { + super(name, bytes, type); + this.type.setStored(true); + } + public StoredField(String name, byte[] value) { super(name, value, TYPE); } diff --git a/lucene/core/src/java/org/apache/lucene/document/StraightBytesDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/StraightBytesDocValuesField.java index a59dd47f188..3fc912ba5cd 100644 --- a/lucene/core/src/java/org/apache/lucene/document/StraightBytesDocValuesField.java +++ b/lucene/core/src/java/org/apache/lucene/document/StraightBytesDocValuesField.java @@ -40,7 +40,7 @@ import org.apache.lucene.util.BytesRef; * @see DocValues for further information * */ -public class StraightBytesDocValuesField extends Field { +public class StraightBytesDocValuesField extends StoredField { // TODO: ideally indexer figures out var vs fixed on its own!? public static final FieldType TYPE_FIXED_LEN = new FieldType(); diff --git a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java index c6281bb723e..6ec7284b594 100644 --- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java +++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java @@ -31,6 +31,7 @@ import org.apache.lucene.codecs.BlockTreeTermsReader; import org.apache.lucene.codecs.Codec; import org.apache.lucene.document.Document; import org.apache.lucene.document.FieldType; // for javadocs +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DocValues.SortedSource; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.search.DocIdSetIterator; @@ -1227,7 +1228,7 @@ public class CheckIndex { for (int j = 0; j < info.info.getDocCount(); ++j) { // Intentionally pull even deleted documents to // make sure they too are not corrupt: - Document doc = reader.document(j); + StoredDocument doc = reader.document(j); if (liveDocs == null || liveDocs.get(j)) { status.docCount++; status.totFields += doc.getFields().size(); diff --git a/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java b/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java index 09299701ad3..15389c8387d 100644 --- a/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java +++ b/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java @@ -218,7 +218,7 @@ final class DocFieldProcessor extends DocConsumer { // seen before (eg suddenly turning on norms or // vectors, etc.): - for(IndexableField field : docState.doc) { + for(IndexableField field : docState.doc.indexableFields()) { final String fieldName = field.name(); // Make sure we have a PerField allocated @@ -266,17 +266,24 @@ final class DocFieldProcessor extends DocConsumer { } fp.addField(field); + } + for (StorableField field: docState.doc.storableFields()) { + final String fieldName = field.name(); - if (field.fieldType().stored()) { - fieldsWriter.addField(field, fp.fieldInfo); + // Make sure we have a PerField allocated + final int hashPos = fieldName.hashCode() & hashMask; + DocFieldProcessorPerField fp = fieldHash[hashPos]; + while(fp != null && !fp.fieldInfo.name.equals(fieldName)) { + fp = fp.next; } + final DocValues.Type dvType = field.fieldType().docValueType(); if (dvType != null) { DocValuesConsumerHolder docValuesConsumer = docValuesConsumer(dvType, docState, fp.fieldInfo); DocValuesConsumer consumer = docValuesConsumer.docValuesConsumer; if (docValuesConsumer.compatibility == null) { - consumer.add(docState.docID, field); + consumer.add(docState.docID, (StorableField) field); docValuesConsumer.compatibility = new TypeCompatibility(dvType, consumer.getValueSize()); } else if (docValuesConsumer.compatibility.isCompatible(dvType, diff --git a/lucene/core/src/java/org/apache/lucene/index/DocInverterPerField.java b/lucene/core/src/java/org/apache/lucene/index/DocInverterPerField.java index 0ef2a6f6a2c..667deaae4a3 100644 --- a/lucene/core/src/java/org/apache/lucene/index/DocInverterPerField.java +++ b/lucene/core/src/java/org/apache/lucene/index/DocInverterPerField.java @@ -75,7 +75,7 @@ final class DocInverterPerField extends DocFieldConsumerPerField { // TODO FI: this should be "genericized" to querying // consumer if it wants to see this particular field // tokenized. - if (fieldType.indexed() && doInvert) { + if (doInvert) { // if the field omits norms, the boost cannot be indexed. if (fieldType.omitNorms() && field.boost() != 1.0f) { diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java index b66e088a039..4d3754b5a10 100644 --- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriter.java @@ -322,7 +322,7 @@ final class DocumentsWriter { return maybeMerge; } - boolean updateDocuments(final Iterable> docs, final Analyzer analyzer, + boolean updateDocuments(final Iterable docs, final Analyzer analyzer, final Term delTerm) throws IOException { boolean maybeMerge = preUpdate(); @@ -353,7 +353,7 @@ final class DocumentsWriter { return postUpdate(flushingDWPT, maybeMerge); } - boolean updateDocument(final Iterable doc, final Analyzer analyzer, + boolean updateDocument(final IndexDocument doc, final Analyzer analyzer, final Term delTerm) throws IOException { boolean maybeMerge = preUpdate(); diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java index ec393366a22..9a2792742d5 100644 --- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java +++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java @@ -93,7 +93,7 @@ class DocumentsWriterPerThread { InfoStream infoStream; Similarity similarity; int docID; - Iterable doc; + IndexDocument doc; String maxTermPrefix; DocState(DocumentsWriterPerThread docWriter, InfoStream infoStream) { @@ -224,7 +224,7 @@ class DocumentsWriterPerThread { return retval; } - public void updateDocument(Iterable doc, Analyzer analyzer, Term delTerm) throws IOException { + public void updateDocument(IndexDocument doc, Analyzer analyzer, Term delTerm) throws IOException { assert writer.testPoint("DocumentsWriterPerThread addDocument start"); assert deleteQueue != null; docState.doc = doc; @@ -277,7 +277,7 @@ class DocumentsWriterPerThread { } } - public int updateDocuments(Iterable> docs, Analyzer analyzer, Term delTerm) throws IOException { + public int updateDocuments(Iterable docs, Analyzer analyzer, Term delTerm) throws IOException { assert writer.testPoint("DocumentsWriterPerThread addDocuments start"); assert deleteQueue != null; docState.analyzer = analyzer; @@ -289,7 +289,7 @@ class DocumentsWriterPerThread { } int docCount = 0; try { - for(Iterable doc : docs) { + for(IndexDocument doc : docs) { docState.doc = doc; docState.docID = numDocsInRAM; docCount++; diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java index f0ff871b64f..1b9a98d924c 100644 --- a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java +++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java @@ -260,7 +260,7 @@ public class FieldInfos implements Iterable { // rather, each component in the chain should update // what it "owns". EG fieldType.indexOptions() should // be updated by maybe FreqProxTermsWriterPerField: - return addOrUpdateInternal(name, -1, fieldType.indexed(), false, + return addOrUpdateInternal(name, -1, true, false, fieldType.omitNorms(), false, fieldType.indexOptions(), null, null); } diff --git a/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java b/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java index 425f158afce..2ca2ed97d76 100644 --- a/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java +++ b/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java @@ -103,12 +103,7 @@ final class FreqProxTermsWriterPerField extends TermsHashConsumerPerField implem @Override boolean start(IndexableField[] fields, int count) { - for(int i=0;i indexableFields(); + public Iterable storableFields(); +} diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexReader.java b/lucene/core/src/java/org/apache/lucene/index/IndexReader.java index 59b6e911929..9c4624a7dbb 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexReader.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexReader.java @@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.document.Document; import org.apache.lucene.document.DocumentStoredFieldVisitor; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.search.SearcherManager; // javadocs import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.util.Bits; @@ -340,7 +341,7 @@ public abstract class IndexReader implements Closeable { // TODO: we need a separate StoredField, so that the // Document returned here contains that class not // IndexableField - public final Document document(int docID) throws IOException { + public final StoredDocument document(int docID) throws IOException { final DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(); document(docID, visitor); return visitor.getDocument(); @@ -351,8 +352,10 @@ public abstract class IndexReader implements Closeable { * fields. Note that this is simply sugar for {@link * DocumentStoredFieldVisitor#DocumentStoredFieldVisitor(Set)}. */ - public final Document document(int docID, Set fieldsToLoad) throws IOException { - final DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(fieldsToLoad); + public final StoredDocument document(int docID, Set fieldsToLoad) + throws IOException { + final DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor( + fieldsToLoad); document(docID, visitor); return visitor.getDocument(); } diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java index 498c5be24da..5950e1c042b 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -1050,7 +1050,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error */ - public void addDocument(Iterable doc) throws IOException { + public void addDocument(IndexDocument doc) throws IOException { addDocument(doc, analyzer); } @@ -1069,7 +1069,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error */ - public void addDocument(Iterable doc, Analyzer analyzer) throws IOException { + public void addDocument(IndexDocument doc, Analyzer analyzer) throws IOException { updateDocument(null, doc, analyzer); } @@ -1114,7 +1114,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * * @lucene.experimental */ - public void addDocuments(Iterable> docs) throws IOException { + public void addDocuments(Iterable docs) throws IOException { addDocuments(docs, analyzer); } @@ -1129,7 +1129,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * * @lucene.experimental */ - public void addDocuments(Iterable> docs, Analyzer analyzer) throws IOException { + public void addDocuments(Iterable docs, Analyzer analyzer) throws IOException { updateDocuments(null, docs, analyzer); } @@ -1146,7 +1146,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * * @lucene.experimental */ - public void updateDocuments(Term delTerm, Iterable> docs) throws IOException { + public void updateDocuments(Term delTerm, Iterable docs) throws IOException { updateDocuments(delTerm, docs, analyzer); } @@ -1164,7 +1164,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * * @lucene.experimental */ - public void updateDocuments(Term delTerm, Iterable> docs, Analyzer analyzer) throws IOException { + public void updateDocuments(Term delTerm, Iterable docs, Analyzer analyzer) throws IOException { ensureOpen(); try { boolean success = false; @@ -1289,7 +1289,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error */ - public void updateDocument(Term term, Iterable doc) throws IOException { + public void updateDocument(Term term, IndexDocument doc) throws IOException { ensureOpen(); updateDocument(term, doc, getAnalyzer()); } @@ -1312,7 +1312,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error */ - public void updateDocument(Term term, Iterable doc, Analyzer analyzer) + public void updateDocument(Term term, IndexDocument doc, Analyzer analyzer) throws IOException { ensureOpen(); try { diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexableField.java b/lucene/core/src/java/org/apache/lucene/index/IndexableField.java index 0408bab4d99..8154fc33303 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexableField.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexableField.java @@ -37,25 +37,10 @@ public interface IndexableField { /** Field name */ public String name(); - + /** {@link IndexableFieldType} describing the properties * of this field. */ public IndexableFieldType fieldType(); - - /** Field boost (you must pre-multiply in any doc boost). */ - public float boost(); - - /** Non-null if this field has a binary value */ - public BytesRef binaryValue(); - - /** Non-null if this field has a string value */ - public String stringValue(); - - /** Non-null if this field has a Reader value */ - public Reader readerValue(); - - /** Non-null if this field has a numeric value */ - public Number numericValue(); /** * Creates the TokenStream used for indexing this field. If appropriate, @@ -67,4 +52,7 @@ public interface IndexableField { * @throws IOException Can be thrown while creating the TokenStream */ public TokenStream tokenStream(Analyzer analyzer) throws IOException; + + /** Field boost (you must pre-multiply in any doc boost). */ + public float boost(); } diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java b/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java index 38b974954a6..98fbd7e9dc3 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java @@ -25,12 +25,6 @@ import org.apache.lucene.index.FieldInfo.IndexOptions; */ public interface IndexableFieldType { - /** True if this field should be indexed (inverted) */ - public boolean indexed(); - - /** True if the field's value should be stored */ - public boolean stored(); - /** True if this field's value should be analyzed */ public boolean tokenized(); @@ -49,8 +43,4 @@ public interface IndexableFieldType { /** {@link IndexOptions}, describing what should be * recorded into the inverted index */ public IndexOptions indexOptions(); - - /** DocValues type; if non-null then the field's value - * will be indexed into docValues */ - public DocValues.Type docValueType(); } diff --git a/lucene/core/src/java/org/apache/lucene/index/Norm.java b/lucene/core/src/java/org/apache/lucene/index/Norm.java index 4f338c36025..2e668a00eeb 100644 --- a/lucene/core/src/java/org/apache/lucene/index/Norm.java +++ b/lucene/core/src/java/org/apache/lucene/index/Norm.java @@ -26,6 +26,7 @@ import org.apache.lucene.document.LongDocValuesField; import org.apache.lucene.document.PackedLongDocValuesField; import org.apache.lucene.document.ShortDocValuesField; import org.apache.lucene.document.SortedBytesDocValuesField; +import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StraightBytesDocValuesField; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.search.similarities.Similarity; @@ -43,13 +44,13 @@ import org.apache.lucene.util.BytesRef; * @lucene.internal */ public final class Norm { - private Field field; + private StoredField field; private BytesRef spare; /** * Returns the {@link IndexableField} representation for this norm */ - public IndexableField field() { + public StoredField field() { return field; } diff --git a/lucene/core/src/java/org/apache/lucene/index/NormsConsumerPerField.java b/lucene/core/src/java/org/apache/lucene/index/NormsConsumerPerField.java index 6532330cb1f..47c5f675044 100644 --- a/lucene/core/src/java/org/apache/lucene/index/NormsConsumerPerField.java +++ b/lucene/core/src/java/org/apache/lucene/index/NormsConsumerPerField.java @@ -51,10 +51,10 @@ final class NormsConsumerPerField extends InvertedDocEndConsumerPerField impleme similarity.computeNorm(fieldState, norm); if (norm.type() != null) { - IndexableField field = norm.field(); + StorableField field = norm.field(); // some similarity might not compute any norms DocValuesConsumer consumer = getConsumer(norm.type()); - consumer.add(docState.docID, field); + consumer.add(docState.docID, (StorableField) field); } } } diff --git a/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java b/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java index ebae93a549b..24cdfd6a76f 100644 --- a/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java +++ b/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java @@ -26,6 +26,8 @@ import java.util.Map.Entry; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.StoredDocument; +import org.apache.lucene.document.StoredField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Version; @@ -67,12 +69,12 @@ public class PersistentSnapshotDeletionPolicy extends SnapshotDeletionPolicy { int numDocs = r.numDocs(); // index is allowed to have exactly one document or 0. if (numDocs == 1) { - Document doc = r.document(r.maxDoc() - 1); + StoredDocument doc = r.document(r.maxDoc() - 1); if (doc.getField(SNAPSHOTS_ID) == null) { throw new IllegalStateException("directory is not a valid snapshots store!"); } doc.removeField(SNAPSHOTS_ID); - for (IndexableField f : doc) { + for (StorableField f : doc) { snapshots.put(f.name(), f.stringValue()); } } else if (numDocs != 0) { @@ -184,14 +186,12 @@ public class PersistentSnapshotDeletionPolicy extends SnapshotDeletionPolicy { private void persistSnapshotInfos(String id, String segment) throws IOException { writer.deleteAll(); Document d = new Document(); - FieldType ft = new FieldType(); - ft.setStored(true); - d.add(new Field(SNAPSHOTS_ID, "", ft)); + d.add(new StoredField(SNAPSHOTS_ID, "")); for (Entry e : super.getSnapshots().entrySet()) { - d.add(new Field(e.getKey(), e.getValue(), ft)); + d.add(new StoredField(e.getKey(), e.getValue())); } if (id != null) { - d.add(new Field(id, segment, ft)); + d.add(new StoredField(id, segment)); } writer.addDocument(d); writer.commit(); diff --git a/lucene/core/src/java/org/apache/lucene/index/StorableField.java b/lucene/core/src/java/org/apache/lucene/index/StorableField.java new file mode 100644 index 00000000000..767f3c94c94 --- /dev/null +++ b/lucene/core/src/java/org/apache/lucene/index/StorableField.java @@ -0,0 +1,44 @@ +package org.apache.lucene.index; + +import java.io.Reader; + +import org.apache.lucene.document.FieldType; +import org.apache.lucene.util.BytesRef; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public interface StorableField { + + /** Field name */ + public String name(); + + /** Field type */ + public FieldType fieldType(); + + /** Non-null if this field has a binary value */ + public BytesRef binaryValue(); + + /** Non-null if this field has a string value */ + public String stringValue(); + + /** Non-null if this field has a Reader value */ + public Reader readerValue(); + + /** Non-null if this field has a numeric value */ + public Number numericValue(); +} diff --git a/lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java b/lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java new file mode 100644 index 00000000000..38f65ed523f --- /dev/null +++ b/lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java @@ -0,0 +1,25 @@ +package org.apache.lucene.index; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public interface StorableFieldType { + + /** DocValues type; if non-null then the field's value + * will be indexed into docValues */ + public DocValues.Type docValueType(); +} diff --git a/lucene/core/src/java/org/apache/lucene/index/StoredFieldsConsumer.java b/lucene/core/src/java/org/apache/lucene/index/StoredFieldsConsumer.java index 3241d38358a..b22c48a7a42 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StoredFieldsConsumer.java +++ b/lucene/core/src/java/org/apache/lucene/index/StoredFieldsConsumer.java @@ -44,12 +44,12 @@ final class StoredFieldsConsumer { } private int numStoredFields; - private IndexableField[] storedFields; + private StorableField[] storedFields; private FieldInfo[] fieldInfos; public void reset() { numStoredFields = 0; - storedFields = new IndexableField[1]; + storedFields = new StorableField[1]; fieldInfos = new FieldInfo[1]; } @@ -126,10 +126,10 @@ final class StoredFieldsConsumer { assert docWriter.writer.testPoint("StoredFieldsWriter.finishDocument end"); } - public void addField(IndexableField field, FieldInfo fieldInfo) { + public void addField(StorableField field, FieldInfo fieldInfo) { if (numStoredFields == storedFields.length) { int newSize = ArrayUtil.oversize(numStoredFields + 1, RamUsageEstimator.NUM_BYTES_OBJECT_REF); - IndexableField[] newArray = new IndexableField[newSize]; + StorableField[] newArray = new StorableField[newSize]; System.arraycopy(storedFields, 0, newArray, 0, numStoredFields); storedFields = newArray; diff --git a/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java b/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java index e1338402e06..8b263c87411 100644 --- a/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java +++ b/lucene/core/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java @@ -61,7 +61,7 @@ final class TermVectorsConsumerPerField extends TermsHashConsumerPerField { for(int i=0;i.getIndexReader().document(docID) */ - public Document doc(int docID) throws IOException { + public StoredDocument doc(int docID) throws IOException { return reader.document(docID); } @@ -191,7 +192,7 @@ public class IndexSearcher { } /** Sugar for .getIndexReader().document(docID, fieldsToLoad) */ - public final Document document(int docID, Set fieldsToLoad) throws IOException { + public final StoredDocument document(int docID, Set fieldsToLoad) throws IOException { return reader.document(docID, fieldsToLoad); } diff --git a/lucene/core/src/java/org/apache/lucene/search/NRTManager.java b/lucene/core/src/java/org/apache/lucene/search/NRTManager.java index 8f6719c708e..8d3141ce76f 100644 --- a/lucene/core/src/java/org/apache/lucene/search/NRTManager.java +++ b/lucene/core/src/java/org/apache/lucene/search/NRTManager.java @@ -27,6 +27,7 @@ import java.util.concurrent.locks.ReentrantLock; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexDocument; import org.apache.lucene.index.IndexReader; // javadocs import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexableField; @@ -153,25 +154,25 @@ public class NRTManager extends ReferenceManager { this.writer = writer; } - public long updateDocument(Term t, Iterable d, Analyzer a) throws IOException { + public long updateDocument(Term t, IndexDocument d, Analyzer a) throws IOException { writer.updateDocument(t, d, a); // Return gen as of when indexing finished: return indexingGen.get(); } - public long updateDocument(Term t, Iterable d) throws IOException { + public long updateDocument(Term t, IndexDocument d) throws IOException { writer.updateDocument(t, d); // Return gen as of when indexing finished: return indexingGen.get(); } - public long updateDocuments(Term t, Iterable> docs, Analyzer a) throws IOException { + public long updateDocuments(Term t, Iterable docs, Analyzer a) throws IOException { writer.updateDocuments(t, docs, a); // Return gen as of when indexing finished: return indexingGen.get(); } - public long updateDocuments(Term t, Iterable> docs) throws IOException { + public long updateDocuments(Term t, Iterable docs) throws IOException { writer.updateDocuments(t, docs); // Return gen as of when indexing finished: return indexingGen.get(); @@ -207,25 +208,25 @@ public class NRTManager extends ReferenceManager { return indexingGen.get(); } - public long addDocument(Iterable d, Analyzer a) throws IOException { + public long addDocument(IndexDocument d, Analyzer a) throws IOException { writer.addDocument(d, a); // Return gen as of when indexing finished: return indexingGen.get(); } - public long addDocuments(Iterable> docs, Analyzer a) throws IOException { + public long addDocuments(Iterable docs, Analyzer a) throws IOException { writer.addDocuments(docs, a); // Return gen as of when indexing finished: return indexingGen.get(); } - public long addDocument(Iterable d) throws IOException { + public long addDocument(IndexDocument d) throws IOException { writer.addDocument(d); // Return gen as of when indexing finished: return indexingGen.get(); } - public long addDocuments(Iterable> docs) throws IOException { + public long addDocuments(Iterable docs) throws IOException { writer.addDocuments(docs); // Return gen as of when indexing finished: return indexingGen.get(); diff --git a/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java b/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java new file mode 100644 index 00000000000..c72956eb910 --- /dev/null +++ b/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java @@ -0,0 +1,68 @@ +package org.apache.lucene.util; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +public abstract class FilterIterator implements Iterator { + + private Iterator iterator; + private T next = null; + private boolean nextIsSet = false; + + protected abstract boolean predicateFunction(U field); + + public FilterIterator(Iterator baseIterator) { + this.iterator = baseIterator; + } + + public boolean hasNext() { + if (nextIsSet) { + return true; + } else { + return setNext(); + } + } + + public T next() { + if (!nextIsSet) { + if (!setNext()) { + throw new NoSuchElementException(); + } + } + nextIsSet = false; + return next; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + + private boolean setNext() { + while (iterator.hasNext()) { + U object = iterator.next(); + if (predicateFunction(object)) { + next = object; + nextIsSet = true; + return true; + } + } + return false; + } +} From 00d53046db9a8a41e495b8e95d3ebf7cf16bdd13 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Mon, 9 Jul 2012 13:06:35 +0000 Subject: [PATCH 03/13] LUCENE-3312: Apply lucene-3312-patch-07.patch git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1359139 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/document/Document.java | 10 +- .../document/DocumentStoredFieldVisitor.java | 5 +- .../apache/lucene/document/DoubleField.java | 1 + .../org/apache/lucene/document/FieldType.java | 4 +- .../apache/lucene/document/FloatField.java | 1 + .../org/apache/lucene/document/IntField.java | 1 + .../document/PackedLongDocValuesField.java | 1 + .../lucene/document/StoredDocument.java | 18 ++- .../apache/lucene/document/StoredField.java | 6 +- .../lucene/index/DocFieldProcessor.java | 103 +++++++-------- .../org/apache/lucene/index/FieldInfos.java | 2 +- .../org/apache/lucene/index/GeneralField.java | 44 +++++++ .../apache/lucene/index/IndexableField.java | 9 +- .../lucene/index/IndexableFieldType.java | 10 ++ .../apache/lucene/index/StorableField.java | 19 +-- .../src/test/org/apache/lucene/TestDemo.java | 3 +- .../test/org/apache/lucene/TestSearch.java | 2 +- .../lucene/TestSearchForDuplicates.java | 4 +- .../codecs/appending/TestAppendingCodec.java | 3 +- .../codecs/lucene40/values/TestDocValues.java | 16 +-- .../lucene/document/TestBinaryDocument.java | 12 +- .../apache/lucene/document/TestDocument.java | 13 +- .../apache/lucene/index/TestAddIndexes.java | 3 +- .../index/TestBackwardsCompatibility.java | 15 +-- .../apache/lucene/index/TestCustomNorms.java | 3 +- .../lucene/index/TestDirectoryReader.java | 25 ++-- .../index/TestDirectoryReaderReopen.java | 3 +- .../apache/lucene/index/TestDocTermOrds.java | 4 +- .../lucene/index/TestDocumentWriter.java | 5 +- .../lucene/index/TestDuelingCodecs.java | 15 +-- .../apache/lucene/index/TestFieldInfos.java | 2 +- .../apache/lucene/index/TestFieldsReader.java | 11 +- .../apache/lucene/index/TestIndexWriter.java | 13 +- .../lucene/index/TestIndexWriterMerging.java | 3 +- .../lucene/index/TestIndexWriterReader.java | 9 +- .../lucene/index/TestIndexWriterUnicode.java | 3 +- .../lucene/index/TestIndexableField.java | 118 ++++++++++++++---- .../org/apache/lucene/index/TestNorms.java | 5 +- .../index/TestParallelAtomicReader.java | 5 +- .../index/TestParallelCompositeReader.java | 5 +- .../lucene/index/TestPostingsOffsets.java | 2 +- .../lucene/index/TestRandomStoredFields.java | 3 +- .../lucene/index/TestSegmentMerger.java | 5 +- .../lucene/index/TestSegmentReader.java | 7 +- .../lucene/index/TestStressIndexing2.java | 17 +-- .../apache/lucene/index/TestStressNRT.java | 5 +- .../apache/lucene/index/TestTermsEnum.java | 2 +- .../search/TestBooleanMinShouldMatch.java | 3 +- .../apache/lucene/search/TestDateSort.java | 3 +- .../search/TestDisjunctionMaxQuery.java | 3 +- .../apache/lucene/search/TestNRTManager.java | 11 +- .../search/TestNumericRangeQuery32.java | 7 +- .../search/TestNumericRangeQuery64.java | 7 +- .../org/apache/lucene/search/TestSort.java | 12 +- .../search/spans/TestSpansAdvanced.java | 3 +- .../apache/lucene/store/TestRAMDirectory.java | 3 +- .../org/apache/lucene/demo/SearchFiles.java | 3 +- .../demo/xmlparser/FormBasedXmlQueryDemo.java | 3 +- .../lucene/analysis/CollationTestBase.java | 6 +- .../org/apache/lucene/index/DocHelper.java | 5 + .../lucene/index/RandomIndexWriter.java | 26 ++-- .../ThreadedIndexingAndSearchingTestCase.java | 13 +- .../org/apache/lucene/util/_TestUtil.java | 2 +- 63 files changed, 423 insertions(+), 262 deletions(-) create mode 100644 lucene/core/src/java/org/apache/lucene/index/GeneralField.java diff --git a/lucene/core/src/java/org/apache/lucene/document/Document.java b/lucene/core/src/java/org/apache/lucene/document/Document.java index 4f3251ee551..049035deaf4 100644 --- a/lucene/core/src/java/org/apache/lucene/document/Document.java +++ b/lucene/core/src/java/org/apache/lucene/document/Document.java @@ -28,8 +28,6 @@ import org.apache.lucene.search.ScoreDoc; // for javadoc import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FilterIterator; -import com.google.common.collect.AbstractIterator; - /** Documents are the unit of indexing and search. * * A Document is a set of fields. Each field has a name and a textual value. @@ -66,6 +64,14 @@ public final class Document implements IndexDocument{ fields.add(field); } + public final void add(IndexableField field) { + fields.add((Field) field); + } + + public final void add(StorableField field) { + fields.add((Field) field); + } + /** *

    Removes field with the specified name from the document. * If multiple fields exist with this name, this method removes the first field that has been added. 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 9b72651c5fa..c7ecc4e562c 100644 --- a/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java +++ b/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java @@ -62,15 +62,12 @@ public class DocumentStoredFieldVisitor extends StoredFieldVisitor { @Override public void stringField(FieldInfo fieldInfo, String value) throws IOException { - /* final FieldType ft = new FieldType(TextField.TYPE_STORED); ft.setStoreTermVectors(fieldInfo.hasVectors()); ft.setIndexed(fieldInfo.isIndexed()); ft.setOmitNorms(fieldInfo.omitsNorms()); ft.setIndexOptions(fieldInfo.getIndexOptions()); - */ - doc.add(new StoredField(fieldInfo.name, value)); - //doc.add(new Field(fieldInfo.name, value, ft)); + doc.add(new StoredField(fieldInfo.name, value, ft)); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/document/DoubleField.java b/lucene/core/src/java/org/apache/lucene/document/DoubleField.java index 17fb53374d5..32a01460d38 100644 --- a/lucene/core/src/java/org/apache/lucene/document/DoubleField.java +++ b/lucene/core/src/java/org/apache/lucene/document/DoubleField.java @@ -116,6 +116,7 @@ public final class DoubleField extends Field { public static final FieldType TYPE_NOT_STORED = new FieldType(); static { + TYPE_NOT_STORED.setIndexed(true); TYPE_NOT_STORED.setTokenized(true); TYPE_NOT_STORED.setOmitNorms(true); TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS_ONLY); diff --git a/lucene/core/src/java/org/apache/lucene/document/FieldType.java b/lucene/core/src/java/org/apache/lucene/document/FieldType.java index facfcc75728..61e2c7347bb 100644 --- a/lucene/core/src/java/org/apache/lucene/document/FieldType.java +++ b/lucene/core/src/java/org/apache/lucene/document/FieldType.java @@ -20,14 +20,13 @@ package org.apache.lucene.document; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.IndexableFieldType; -import org.apache.lucene.index.StorableFieldType; import org.apache.lucene.search.NumericRangeQuery; // javadocs import org.apache.lucene.util.NumericUtils; /** * Describes the properties of a field. */ -public class FieldType implements IndexableFieldType, StorableFieldType { +public class FieldType implements IndexableFieldType { /** Data type of the numeric value * @since 3.2 @@ -240,5 +239,6 @@ public class FieldType implements IndexableFieldType, StorableFieldType { public void setDocValueType(DocValues.Type type) { checkIfFrozen(); docValueType = type; + this.stored = true; } } diff --git a/lucene/core/src/java/org/apache/lucene/document/FloatField.java b/lucene/core/src/java/org/apache/lucene/document/FloatField.java index 9ac68f7b91f..dcb5ea76cfc 100644 --- a/lucene/core/src/java/org/apache/lucene/document/FloatField.java +++ b/lucene/core/src/java/org/apache/lucene/document/FloatField.java @@ -116,6 +116,7 @@ public final class FloatField extends Field { public static final FieldType TYPE_NOT_STORED = new FieldType(); static { + TYPE_NOT_STORED.setIndexed(true); TYPE_NOT_STORED.setTokenized(true); TYPE_NOT_STORED.setOmitNorms(true); TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS_ONLY); diff --git a/lucene/core/src/java/org/apache/lucene/document/IntField.java b/lucene/core/src/java/org/apache/lucene/document/IntField.java index 7250d75fc25..648da431b78 100644 --- a/lucene/core/src/java/org/apache/lucene/document/IntField.java +++ b/lucene/core/src/java/org/apache/lucene/document/IntField.java @@ -116,6 +116,7 @@ public final class IntField extends Field { public static final FieldType TYPE_NOT_STORED = new FieldType(); static { + TYPE_NOT_STORED.setIndexed(true); TYPE_NOT_STORED.setTokenized(true); TYPE_NOT_STORED.setOmitNorms(true); TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS_ONLY); diff --git a/lucene/core/src/java/org/apache/lucene/document/PackedLongDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/PackedLongDocValuesField.java index c1e72b3c8eb..401245295c0 100644 --- a/lucene/core/src/java/org/apache/lucene/document/PackedLongDocValuesField.java +++ b/lucene/core/src/java/org/apache/lucene/document/PackedLongDocValuesField.java @@ -44,6 +44,7 @@ public class PackedLongDocValuesField extends StoredField { public static final FieldType TYPE = new FieldType(); static { TYPE.setDocValueType(DocValues.Type.VAR_INTS); + TYPE.setStored(true); TYPE.freeze(); } diff --git a/lucene/core/src/java/org/apache/lucene/document/StoredDocument.java b/lucene/core/src/java/org/apache/lucene/document/StoredDocument.java index a2eab0b0931..563ea2a8219 100644 --- a/lucene/core/src/java/org/apache/lucene/document/StoredDocument.java +++ b/lucene/core/src/java/org/apache/lucene/document/StoredDocument.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.StorableField; import org.apache.lucene.util.BytesRef; @@ -183,7 +184,7 @@ public class StoredDocument implements Iterable{ Document doc = new Document(); for (StorableField field : fields) { - Field newField = new Field(field.name(), field.fieldType()); + Field newField = new Field(field.name(), (FieldType) field.fieldType()); newField.fieldsData = field.stringValue(); if (newField.fieldsData == null) @@ -198,4 +199,19 @@ public class StoredDocument implements Iterable{ return doc; } + + /** Prints the fields of a document for human consumption. */ + @Override + public final String toString() { + StringBuilder buffer = new StringBuilder(); + buffer.append("StoredDocument<"); + for (int i = 0; i < fields.size(); i++) { + StorableField field = fields.get(i); + buffer.append(field.toString()); + if (i != fields.size()-1) + buffer.append(" "); + } + buffer.append(">"); + return buffer.toString(); + } } diff --git a/lucene/core/src/java/org/apache/lucene/document/StoredField.java b/lucene/core/src/java/org/apache/lucene/document/StoredField.java index d5e046a87f8..692d48d2152 100644 --- a/lucene/core/src/java/org/apache/lucene/document/StoredField.java +++ b/lucene/core/src/java/org/apache/lucene/document/StoredField.java @@ -35,12 +35,10 @@ public class StoredField extends Field { protected StoredField(String name, FieldType type) { super(name, type); - this.type.setStored(true); } public StoredField(String name, BytesRef bytes, FieldType type) { super(name, bytes, type); - this.type.setStored(true); } public StoredField(String name, byte[] value) { @@ -58,6 +56,10 @@ public class StoredField extends Field { public StoredField(String name, String value) { super(name, value, TYPE); } + + public StoredField(String name, String value, FieldType type) { + super(name, value, type); + } public StoredField(String name, int value) { super(name, TYPE); diff --git a/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java b/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java index 15389c8387d..5f7a4acb456 100644 --- a/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java +++ b/lucene/core/src/java/org/apache/lucene/index/DocFieldProcessor.java @@ -28,6 +28,7 @@ import org.apache.lucene.codecs.Codec; import org.apache.lucene.codecs.DocValuesConsumer; import org.apache.lucene.codecs.FieldInfosWriter; import org.apache.lucene.codecs.PerDocConsumer; +import org.apache.lucene.document.FieldType; import org.apache.lucene.index.DocumentsWriterPerThread.DocState; import org.apache.lucene.index.TypePromoter.TypeCompatibility; import org.apache.lucene.store.IOContext; @@ -220,62 +221,18 @@ final class DocFieldProcessor extends DocConsumer { for(IndexableField field : docState.doc.indexableFields()) { final String fieldName = field.name(); + IndexableFieldType ft = field.fieldType(); - // Make sure we have a PerField allocated - final int hashPos = fieldName.hashCode() & hashMask; - DocFieldProcessorPerField fp = fieldHash[hashPos]; - while(fp != null && !fp.fieldInfo.name.equals(fieldName)) { - fp = fp.next; - } - - if (fp == null) { - - // TODO FI: we need to genericize the "flags" that a - // field holds, and, how these flags are merged; it - // needs to be more "pluggable" such that if I want - // to have a new "thing" my Fields can do, I can - // easily add it - FieldInfo fi = fieldInfos.addOrUpdate(fieldName, field.fieldType()); - - fp = new DocFieldProcessorPerField(this, fi); - fp.next = fieldHash[hashPos]; - fieldHash[hashPos] = fp; - totalFieldCount++; - - if (totalFieldCount >= fieldHash.length/2) { - rehash(); - } - } else { - fieldInfos.addOrUpdate(fp.fieldInfo.name, field.fieldType()); - } - - if (thisFieldGen != fp.lastGen) { - - // First time we're seeing this field for this doc - fp.fieldCount = 0; - - if (fieldCount == fields.length) { - final int newSize = fields.length*2; - DocFieldProcessorPerField newArray[] = new DocFieldProcessorPerField[newSize]; - System.arraycopy(fields, 0, newArray, 0, fieldCount); - fields = newArray; - } - - fields[fieldCount++] = fp; - fp.lastGen = thisFieldGen; - } + DocFieldProcessorPerField fp = processField(fieldInfos, thisFieldGen, fieldName, ft); fp.addField(field); } for (StorableField field: docState.doc.storableFields()) { final String fieldName = field.name(); + IndexableFieldType ft = field.fieldType(); - // Make sure we have a PerField allocated - final int hashPos = fieldName.hashCode() & hashMask; - DocFieldProcessorPerField fp = fieldHash[hashPos]; - while(fp != null && !fp.fieldInfo.name.equals(fieldName)) { - fp = fp.next; - } + DocFieldProcessorPerField fp = processField(fieldInfos, thisFieldGen, fieldName, ft); + fieldsWriter.addField(field, fp.fieldInfo); final DocValues.Type dvType = field.fieldType().docValueType(); if (dvType != null) { @@ -320,6 +277,54 @@ final class DocFieldProcessor extends DocConsumer { } } + private DocFieldProcessorPerField processField(FieldInfos.Builder fieldInfos, + final int thisFieldGen, final String fieldName, IndexableFieldType ft) { + // Make sure we have a PerField allocated + final int hashPos = fieldName.hashCode() & hashMask; + DocFieldProcessorPerField fp = fieldHash[hashPos]; + while(fp != null && !fp.fieldInfo.name.equals(fieldName)) { + fp = fp.next; + } + + if (fp == null) { + + // TODO FI: we need to genericize the "flags" that a + // field holds, and, how these flags are merged; it + // needs to be more "pluggable" such that if I want + // to have a new "thing" my Fields can do, I can + // easily add it + FieldInfo fi = fieldInfos.addOrUpdate(fieldName, ft); + + fp = new DocFieldProcessorPerField(this, fi); + fp.next = fieldHash[hashPos]; + fieldHash[hashPos] = fp; + totalFieldCount++; + + if (totalFieldCount >= fieldHash.length/2) { + rehash(); + } + } else { + fieldInfos.addOrUpdate(fp.fieldInfo.name, ft); + } + + if (thisFieldGen != fp.lastGen) { + + // First time we're seeing this field for this doc + fp.fieldCount = 0; + + if (fieldCount == fields.length) { + final int newSize = fields.length*2; + DocFieldProcessorPerField newArray[] = new DocFieldProcessorPerField[newSize]; + System.arraycopy(fields, 0, newArray, 0, fieldCount); + fields = newArray; + } + + fields[fieldCount++] = fp; + fp.lastGen = thisFieldGen; + } + return fp; + } + private static final Comparator fieldsComp = new Comparator() { public int compare(DocFieldProcessorPerField o1, DocFieldProcessorPerField o2) { return o1.fieldInfo.name.compareTo(o2.fieldInfo.name); diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java index 1b9a98d924c..f0ff871b64f 100644 --- a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java +++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java @@ -260,7 +260,7 @@ public class FieldInfos implements Iterable { // rather, each component in the chain should update // what it "owns". EG fieldType.indexOptions() should // be updated by maybe FreqProxTermsWriterPerField: - return addOrUpdateInternal(name, -1, true, false, + return addOrUpdateInternal(name, -1, fieldType.indexed(), false, fieldType.omitNorms(), false, fieldType.indexOptions(), null, null); } diff --git a/lucene/core/src/java/org/apache/lucene/index/GeneralField.java b/lucene/core/src/java/org/apache/lucene/index/GeneralField.java new file mode 100644 index 00000000000..e1a203d8bc6 --- /dev/null +++ b/lucene/core/src/java/org/apache/lucene/index/GeneralField.java @@ -0,0 +1,44 @@ +package org.apache.lucene.index; + +import java.io.Reader; + +import org.apache.lucene.util.BytesRef; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public interface GeneralField { + + /** Field name */ + public String name(); + + /** {@link IndexableFieldType} describing the properties + * of this field. */ + public IndexableFieldType fieldType(); + + /** Non-null if this field has a binary value */ + public BytesRef binaryValue(); + + /** Non-null if this field has a string value */ + public String stringValue(); + + /** Non-null if this field has a Reader value */ + public Reader readerValue(); + + /** Non-null if this field has a numeric value */ + public Number numericValue(); +} diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexableField.java b/lucene/core/src/java/org/apache/lucene/index/IndexableField.java index 8154fc33303..ba8a84cc8a9 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexableField.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexableField.java @@ -33,14 +33,7 @@ import org.apache.lucene.util.BytesRef; * * @lucene.experimental */ -public interface IndexableField { - - /** Field name */ - public String name(); - - /** {@link IndexableFieldType} describing the properties - * of this field. */ - public IndexableFieldType fieldType(); +public interface IndexableField extends GeneralField { /** * Creates the TokenStream used for indexing this field. If appropriate, diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java b/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java index 98fbd7e9dc3..d0e546debea 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java @@ -25,6 +25,12 @@ import org.apache.lucene.index.FieldInfo.IndexOptions; */ public interface IndexableFieldType { + /** True if this field should be indexed (inverted) */ + public boolean indexed(); + + /** True if the field's value should be stored */ + public boolean stored(); + /** True if this field's value should be analyzed */ public boolean tokenized(); @@ -43,4 +49,8 @@ public interface IndexableFieldType { /** {@link IndexOptions}, describing what should be * recorded into the inverted index */ public IndexOptions indexOptions(); + + /** DocValues type; if non-null then the field's value + * will be indexed into docValues */ + public DocValues.Type docValueType(); } diff --git a/lucene/core/src/java/org/apache/lucene/index/StorableField.java b/lucene/core/src/java/org/apache/lucene/index/StorableField.java index 767f3c94c94..ed9621eb041 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StorableField.java +++ b/lucene/core/src/java/org/apache/lucene/index/StorableField.java @@ -22,23 +22,6 @@ import org.apache.lucene.util.BytesRef; * limitations under the License. */ -public interface StorableField { - - /** Field name */ - public String name(); +public interface StorableField extends GeneralField { - /** Field type */ - public FieldType fieldType(); - - /** Non-null if this field has a binary value */ - public BytesRef binaryValue(); - - /** Non-null if this field has a string value */ - public String stringValue(); - - /** Non-null if this field has a Reader value */ - public Reader readerValue(); - - /** Non-null if this field has a numeric value */ - public Number numericValue(); } diff --git a/lucene/core/src/test/org/apache/lucene/TestDemo.java b/lucene/core/src/test/org/apache/lucene/TestDemo.java index 9f36dfebb6a..8d532041754 100644 --- a/lucene/core/src/test/org/apache/lucene/TestDemo.java +++ b/lucene/core/src/test/org/apache/lucene/TestDemo.java @@ -23,6 +23,7 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; @@ -64,7 +65,7 @@ public class TestDemo extends LuceneTestCase { assertEquals(1, hits.totalHits); // Iterate through the results: for (int i = 0; i < hits.scoreDocs.length; i++) { - Document hitDoc = isearcher.doc(hits.scoreDocs[i].doc); + StoredDocument hitDoc = isearcher.doc(hits.scoreDocs[i].doc); assertEquals(text, hitDoc.get("fieldname")); } diff --git a/lucene/core/src/test/org/apache/lucene/TestSearch.java b/lucene/core/src/test/org/apache/lucene/TestSearch.java index 98ee9c9b546..235f45b7ea9 100644 --- a/lucene/core/src/test/org/apache/lucene/TestSearch.java +++ b/lucene/core/src/test/org/apache/lucene/TestSearch.java @@ -110,7 +110,7 @@ public class TestSearch extends LuceneTestCase { out.println(hits.length + " total results"); for (int i = 0 ; i < hits.length && i < 10; i++) { - Document d = searcher.doc(hits[i].doc); + StoredDocument d = searcher.doc(hits[i].doc); out.println(i + " " + hits[i].score + " " + d.get("contents")); } } diff --git a/lucene/core/src/test/org/apache/lucene/TestSearchForDuplicates.java b/lucene/core/src/test/org/apache/lucene/TestSearchForDuplicates.java index eecf92a460c..ad1f06ec5db 100644 --- a/lucene/core/src/test/org/apache/lucene/TestSearchForDuplicates.java +++ b/lucene/core/src/test/org/apache/lucene/TestSearchForDuplicates.java @@ -127,7 +127,7 @@ public class TestSearchForDuplicates extends LuceneTestCase { out.println(hits.length + " total results\n"); for (int i = 0 ; i < hits.length; i++) { if ( i < 10 || (i > 94 && i < 105) ) { - Document d = searcher.doc(hits[i].doc); + StoredDocument d = searcher.doc(hits[i].doc); out.println(i + " " + d.get(ID_FIELD)); } } @@ -137,7 +137,7 @@ public class TestSearchForDuplicates extends LuceneTestCase { assertEquals("total results", expectedCount, hits.length); for (int i = 0 ; i < hits.length; i++) { if (i < 10 || (i > 94 && i < 105) ) { - Document d = searcher.doc(hits[i].doc); + StoredDocument d = searcher.doc(hits[i].doc); assertEquals("check " + i, String.valueOf(i), d.get(ID_FIELD)); } } diff --git a/lucene/core/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java b/lucene/core/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java index 422d9329d96..a83fea8159a 100644 --- a/lucene/core/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java +++ b/lucene/core/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java @@ -24,6 +24,7 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.codecs.appending.AppendingCodec; import org.apache.lucene.document.Document; import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DocsEnum; @@ -128,7 +129,7 @@ public class TestAppendingCodec extends LuceneTestCase { writer.close(); IndexReader reader = DirectoryReader.open(dir, 1); assertEquals(2, reader.numDocs()); - Document doc2 = reader.document(0); + StoredDocument doc2 = reader.document(0); assertEquals(text, doc2.get("f")); Fields fields = MultiFields.getFields(reader); Terms terms = fields.terms("f"); diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene40/values/TestDocValues.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene40/values/TestDocValues.java index c8fcd9eda8c..4aa02a8e46c 100644 --- a/lucene/core/src/test/org/apache/lucene/codecs/lucene40/values/TestDocValues.java +++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene40/values/TestDocValues.java @@ -28,12 +28,14 @@ import org.apache.lucene.codecs.DocValuesConsumer; import org.apache.lucene.codecs.lucene40.values.Bytes; import org.apache.lucene.codecs.lucene40.values.Floats; import org.apache.lucene.codecs.lucene40.values.Ints; +import org.apache.lucene.document.FieldType; import org.apache.lucene.index.DocValues.SortedSource; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.IndexableFieldType; +import org.apache.lucene.index.StorableField; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.Counter; @@ -438,21 +440,11 @@ public class TestDocValues extends LuceneTestCase { return getSource(values).asSortedSource(); } - public static class DocValueHolder implements IndexableField { + public static class DocValueHolder implements StorableField { BytesRef bytes; Number numberValue; Comparator comp; - @Override - public TokenStream tokenStream(Analyzer a) { - return null; - } - - @Override - public float boost() { - return 0.0f; - } - @Override public String name() { return "test"; @@ -479,7 +471,7 @@ public class TestDocValues extends LuceneTestCase { } @Override - public IndexableFieldType fieldType() { + public FieldType fieldType() { return null; } } diff --git a/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java b/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java index 45c72cf0617..cb3092b8e1e 100644 --- a/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java +++ b/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java @@ -37,8 +37,8 @@ public class TestBinaryDocument extends LuceneTestCase { { FieldType ft = new FieldType(); ft.setStored(true); - IndexableField binaryFldStored = new StoredField("binaryStored", binaryValStored.getBytes()); - IndexableField stringFldStored = new Field("stringStored", binaryValStored, ft); + StoredField binaryFldStored = new StoredField("binaryStored", binaryValStored.getBytes()); + Field stringFldStored = new Field("stringStored", binaryValStored, ft); Document doc = new Document(); @@ -56,7 +56,7 @@ public class TestBinaryDocument extends LuceneTestCase { /** open a reader and fetch the document */ IndexReader reader = writer.getReader(); - Document docFromReader = reader.document(0); + StoredDocument docFromReader = reader.document(0); assertTrue(docFromReader != null); /** fetch the binary stored field and compare it's content with the original one */ @@ -75,8 +75,8 @@ public class TestBinaryDocument extends LuceneTestCase { } public void testCompressionTools() throws Exception { - IndexableField binaryFldCompressed = new StoredField("binaryCompressed", CompressionTools.compress(binaryValCompressed.getBytes())); - IndexableField stringFldCompressed = new StoredField("stringCompressed", CompressionTools.compressString(binaryValCompressed)); + StoredField binaryFldCompressed = new StoredField("binaryCompressed", CompressionTools.compress(binaryValCompressed.getBytes())); + StoredField stringFldCompressed = new StoredField("stringCompressed", CompressionTools.compressString(binaryValCompressed)); Document doc = new Document(); @@ -90,7 +90,7 @@ public class TestBinaryDocument extends LuceneTestCase { /** open a reader and fetch the document */ IndexReader reader = writer.getReader(); - Document docFromReader = reader.document(0); + StoredDocument docFromReader = reader.document(0); assertTrue(docFromReader != null); /** fetch the binary compressed field and compare it's content with the original one */ diff --git a/lucene/core/src/test/org/apache/lucene/document/TestDocument.java b/lucene/core/src/test/org/apache/lucene/document/TestDocument.java index d33116bc607..a62a2b39569 100644 --- a/lucene/core/src/test/org/apache/lucene/document/TestDocument.java +++ b/lucene/core/src/test/org/apache/lucene/document/TestDocument.java @@ -50,9 +50,9 @@ public class TestDocument extends LuceneTestCase { FieldType ft = new FieldType(); ft.setStored(true); - IndexableField stringFld = new Field("string", binaryVal, ft); - IndexableField binaryFld = new StoredField("binary", binaryVal.getBytes("UTF-8")); - IndexableField binaryFld2 = new StoredField("binary", binaryVal2.getBytes("UTF-8")); + Field stringFld = new Field("string", binaryVal, ft); + StoredField binaryFld = new StoredField("binary", binaryVal.getBytes("UTF-8")); + StoredField binaryFld2 = new StoredField("binary", binaryVal2.getBytes("UTF-8")); doc.add(stringFld); doc.add(binaryFld); @@ -179,7 +179,7 @@ public class TestDocument extends LuceneTestCase { ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; assertEquals(1, hits.length); - doAssert(searcher.doc(hits[0].doc), true); + doAssert(searcher.doc(hits[0].doc)); writer.close(); reader.close(); dir.close(); @@ -214,6 +214,9 @@ public class TestDocument extends LuceneTestCase { return doc; } + private void doAssert(StoredDocument doc) { + doAssert(doc.asIndexable(), true); + } private void doAssert(Document doc, boolean fromIndex) { IndexableField[] keywordFieldValues = doc.getFields("keyword"); IndexableField[] textFieldValues = doc.getFields("text"); @@ -268,7 +271,7 @@ public class TestDocument extends LuceneTestCase { assertEquals(3, hits.length); int result = 0; for (int i = 0; i < 3; i++) { - Document doc2 = searcher.doc(hits[i].doc); + StoredDocument doc2 = searcher.doc(hits[i].doc); Field f = (Field) doc2.getField("id"); if (f.stringValue().equals("id1")) result |= 1; else if (f.stringValue().equals("id2")) result |= 2; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java index 7d394ec96e6..efa608caf53 100755 --- a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java @@ -45,6 +45,7 @@ import org.apache.lucene.codecs.pulsing.Pulsing40PostingsFormat; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; @@ -1245,7 +1246,7 @@ public class TestAddIndexes extends LuceneTestCase { w.close(); assertEquals(2, r3.numDocs()); for(int docID=0;docID<2;docID++) { - Document d = r3.document(docID); + StoredDocument d = r3.document(docID); if (d.get("id").equals("1")) { assertEquals("doc1 field1", d.get("f1")); } else { diff --git a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java index 1e7bff43972..56c14fdea7a 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java @@ -43,6 +43,7 @@ import org.apache.lucene.document.LongField; import org.apache.lucene.document.PackedLongDocValuesField; import org.apache.lucene.document.ShortDocValuesField; import org.apache.lucene.document.SortedBytesDocValuesField; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StraightBytesDocValuesField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; @@ -328,13 +329,13 @@ public class TestBackwardsCompatibility extends LuceneTestCase { for(int i=0;i<35;i++) { if (liveDocs.get(i)) { - Document d = reader.document(i); - List fields = d.getFields(); + StoredDocument d = reader.document(i); + List fields = d.getFields(); boolean isProxDoc = d.getField("content3") == null; if (isProxDoc) { final int numFields = is40Index ? 7 : 5; assertEquals(numFields, fields.size()); - IndexableField f = d.getField("id"); + StorableField f = d.getField("id"); assertEquals(""+i, f.stringValue()); f = d.getField("utf8"); @@ -405,7 +406,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase { ScoreDoc[] hits = searcher.search(new TermQuery(new Term(new String("content"), "aaa")), null, 1000).scoreDocs; // First document should be #0 - Document d = searcher.getIndexReader().document(hits[0].doc); + StoredDocument d = searcher.getIndexReader().document(hits[0].doc); assertEquals("didn't get the right document first", "0", d.get("id")); doTestHits(hits, 34, searcher.getIndexReader()); @@ -458,7 +459,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase { IndexReader reader = DirectoryReader.open(dir); IndexSearcher searcher = new IndexSearcher(reader); ScoreDoc[] hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs; - Document d = searcher.getIndexReader().document(hits[0].doc); + StoredDocument d = searcher.getIndexReader().document(hits[0].doc); assertEquals("wrong first document", "0", d.get("id")); doTestHits(hits, 44, searcher.getIndexReader()); reader.close(); @@ -484,7 +485,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase { IndexSearcher searcher = new IndexSearcher(reader); ScoreDoc[] hits = searcher.search(new TermQuery(new Term("content", "aaa")), null, 1000).scoreDocs; assertEquals("wrong number of hits", 34, hits.length); - Document d = searcher.doc(hits[0].doc); + StoredDocument d = searcher.doc(hits[0].doc); assertEquals("wrong first document", "0", d.get("id")); reader.close(); @@ -752,7 +753,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase { for (int id=10; id<15; id++) { ScoreDoc[] hits = searcher.search(NumericRangeQuery.newIntRange("trieInt", 4, Integer.valueOf(id), Integer.valueOf(id), true, true), 100).scoreDocs; assertEquals("wrong number of hits", 1, hits.length); - Document d = searcher.doc(hits[0].doc); + StoredDocument d = searcher.doc(hits[0].doc); assertEquals(String.valueOf(id), d.get("id")); hits = searcher.search(NumericRangeQuery.newLongRange("trieLong", 4, Long.valueOf(id), Long.valueOf(id), true, true), 100).scoreDocs; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCustomNorms.java b/lucene/core/src/test/org/apache/lucene/index/TestCustomNorms.java index a9addc86097..1a97c49cb02 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestCustomNorms.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestCustomNorms.java @@ -22,6 +22,7 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; @@ -75,7 +76,7 @@ public class TestCustomNorms extends LuceneTestCase { assertEquals(Type.FLOAT_32, normValues.getType()); float[] norms = (float[]) source.getArray(); for (int i = 0; i < open.maxDoc(); i++) { - Document document = open.document(i); + StoredDocument document = open.document(i); float expected = Float.parseFloat(document.get(floatTestField)); assertEquals(expected, norms[i], 0.0f); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java index f9d3bf3afcf..b806e9690ee 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java @@ -32,6 +32,7 @@ import org.apache.lucene.codecs.lucene40.Lucene40PostingsFormat; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; @@ -61,10 +62,10 @@ public class TestDirectoryReader extends LuceneTestCase { assertTrue(reader != null); assertTrue(reader instanceof StandardDirectoryReader); - Document newDoc1 = reader.document(0); + StoredDocument newDoc1 = reader.document(0); assertTrue(newDoc1 != null); assertTrue(DocHelper.numFields(newDoc1) == DocHelper.numFields(doc1) - DocHelper.unstored.size()); - Document newDoc2 = reader.document(1); + StoredDocument newDoc2 = reader.document(1); assertTrue(newDoc2 != null); assertTrue(DocHelper.numFields(newDoc2) == DocHelper.numFields(doc2) - DocHelper.unstored.size()); Terms vector = reader.getTermVectors(0).terms(DocHelper.TEXT_FIELD_2_KEY); @@ -386,11 +387,11 @@ void assertTermDocsCount(String msg, writer.addDocument(doc); writer.close(); DirectoryReader reader = DirectoryReader.open(dir); - Document doc2 = reader.document(reader.maxDoc() - 1); - IndexableField[] fields = doc2.getFields("bin1"); + StoredDocument doc2 = reader.document(reader.maxDoc() - 1); + StorableField[] fields = doc2.getFields("bin1"); assertNotNull(fields); assertEquals(1, fields.length); - IndexableField b1 = fields[0]; + StorableField b1 = fields[0]; assertTrue(b1.binaryValue() != null); BytesRef bytesRef = b1.binaryValue(); assertEquals(bin.length, bytesRef.length); @@ -595,13 +596,13 @@ public void testFilesOpenClose() throws IOException { // check stored fields for (int i = 0; i < index1.maxDoc(); i++) { if (liveDocs1 == null || liveDocs1.get(i)) { - Document doc1 = index1.document(i); - Document doc2 = index2.document(i); - List field1 = doc1.getFields(); - List field2 = doc2.getFields(); + StoredDocument doc1 = index1.document(i); + StoredDocument doc2 = index2.document(i); + List field1 = doc1.getFields(); + List field2 = doc2.getFields(); assertEquals("Different numbers of fields for doc " + i + ".", field1.size(), field2.size()); - Iterator itField1 = field1.iterator(); - Iterator itField2 = field2.iterator(); + Iterator itField1 = field1.iterator(); + Iterator itField2 = field2.iterator(); while (itField1.hasNext()) { Field curField1 = (Field) itField1.next(); Field curField2 = (Field) itField2.next(); @@ -1080,7 +1081,7 @@ public void testFilesOpenClose() throws IOException { Set fieldsToLoad = new HashSet(); assertEquals(0, r.document(0, fieldsToLoad).getFields().size()); fieldsToLoad.add("field1"); - Document doc2 = r.document(0, fieldsToLoad); + StoredDocument doc2 = r.document(0, fieldsToLoad); assertEquals(1, doc2.getFields().size()); assertEquals("foobar", doc2.get("field1")); r.close(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java index 8e6f3ea588e..a76a0a7bbb4 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java @@ -32,6 +32,7 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.search.IndexSearcher; @@ -122,7 +123,7 @@ public class TestDirectoryReaderReopen extends LuceneTestCase { if (i>0) { int k = i-1; int n = j + k*M; - Document prevItereationDoc = reader.document(n); + StoredDocument prevItereationDoc = reader.document(n); assertNotNull(prevItereationDoc); String id = prevItereationDoc.get("id"); assertEquals(k+"_"+j, id); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocTermOrds.java b/lucene/core/src/test/org/apache/lucene/index/TestDocTermOrds.java index 7e55009711e..b459100a342 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDocTermOrds.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDocTermOrds.java @@ -122,7 +122,7 @@ public class TestDocTermOrds extends LuceneTestCase { for(int id=0;id comp = new Comparator() { + Comparator comp = new Comparator() { @Override - public int compare(IndexableField arg0, IndexableField arg1) { + public int compare(StorableField arg0, StorableField arg1) { return arg0.name().compareTo(arg1.name()); } }; Collections.sort(leftDoc.getFields(), comp); Collections.sort(rightDoc.getFields(), comp); - Iterator leftIterator = leftDoc.iterator(); - Iterator rightIterator = rightDoc.iterator(); + Iterator leftIterator = leftDoc.iterator(); + Iterator rightIterator = rightDoc.iterator(); while (leftIterator.hasNext()) { assertTrue(info, rightIterator.hasNext()); assertStoredField(leftIterator.next(), rightIterator.next()); @@ -578,7 +579,7 @@ public class TestDuelingCodecs extends LuceneTestCase { /** * checks that two stored fields are equivalent */ - public void assertStoredField(IndexableField leftField, IndexableField rightField) { + public void assertStoredField(StorableField leftField, StorableField rightField) { assertEquals(info, leftField.name(), rightField.name()); assertEquals(info, leftField.binaryValue(), rightField.binaryValue()); assertEquals(info, leftField.stringValue(), rightField.stringValue()); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFieldInfos.java b/lucene/core/src/test/org/apache/lucene/index/TestFieldInfos.java index 9850a3dbb8e..312ae6ab94f 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestFieldInfos.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestFieldInfos.java @@ -47,7 +47,7 @@ public class TestFieldInfos extends LuceneTestCase { //Positive test of FieldInfos assertTrue(testDoc != null); FieldInfos.Builder builder = new FieldInfos.Builder(); - for (IndexableField field : testDoc) { + for (IndexableField field : testDoc.getFields()) { builder.addOrUpdate(field.name(), field.fieldType()); } FieldInfos fieldInfos = builder.finish(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java b/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java index 5bbc43ad547..cc0956bd9dd 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java @@ -31,6 +31,7 @@ import org.apache.lucene.document.FieldType; import org.apache.lucene.document.FloatField; import org.apache.lucene.document.IntField; import org.apache.lucene.document.LongField; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StringField; import org.apache.lucene.index.FieldInfo.IndexOptions; @@ -55,7 +56,7 @@ public class TestFieldsReader extends LuceneTestCase { public static void beforeClass() throws Exception { fieldInfos = new FieldInfos.Builder(); DocHelper.setupDoc(testDoc); - for (IndexableField field : testDoc) { + for (IndexableField field : testDoc.getFields()) { fieldInfos.addOrUpdate(field.name(), field.fieldType()); } dir = newDirectory(); @@ -79,7 +80,7 @@ public class TestFieldsReader extends LuceneTestCase { assertTrue(dir != null); assertTrue(fieldInfos != null); IndexReader reader = DirectoryReader.open(dir); - Document doc = reader.document(0); + StoredDocument doc = reader.document(0); assertTrue(doc != null); assertTrue(doc.getField(DocHelper.TEXT_FIELD_1_KEY) != null); @@ -104,7 +105,7 @@ public class TestFieldsReader extends LuceneTestCase { DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(DocHelper.TEXT_FIELD_3_KEY); reader.document(0, visitor); - final List fields = visitor.getDocument().getFields(); + final List fields = visitor.getDocument().getFields(); assertEquals(1, fields.size()); assertEquals(DocHelper.TEXT_FIELD_3_KEY, fields.get(0).name()); reader.close(); @@ -279,7 +280,7 @@ public class TestFieldsReader extends LuceneTestCase { doc.add(sf); answers[id] = answer; typeAnswers[id] = typeAnswer; - FieldType ft = new FieldType(IntField.TYPE_NOT_STORED); + FieldType ft = new FieldType(IntField.TYPE_STORED); ft.setNumericPrecisionStep(Integer.MAX_VALUE); doc.add(new IntField("id", id, ft)); w.addDocument(doc); @@ -292,7 +293,7 @@ public class TestFieldsReader extends LuceneTestCase { for(IndexReader sub : r.getSequentialSubReaders()) { final int[] ids = FieldCache.DEFAULT.getInts((AtomicReader) sub, "id", false); for(int docID=0;docID it = doc2.getFields().iterator(); + StoredDocument doc2 = r.document(0); + Iterator it = doc2.getFields().iterator(); assertTrue(it.hasNext()); Field f = (Field) it.next(); assertEquals(f.name(), "zzz"); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMerging.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMerging.java index d07a7756f5f..1ab0190f2c0 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMerging.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMerging.java @@ -21,6 +21,7 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.util.LuceneTestCase; @@ -84,7 +85,7 @@ public class TestIndexWriterMerging extends LuceneTestCase int max = reader.maxDoc(); for (int i = 0; i < max; i++) { - Document temp = reader.document(i); + StoredDocument temp = reader.document(i); //System.out.println("doc "+i+"="+temp.getField("count").stringValue()); //compare the index doc number to the value that it should be if (!temp.getField("count").stringValue().equals((i + startAt) + "")) diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java index 914fccf4195..77f8be60804 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java @@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexSearcher; @@ -141,10 +142,10 @@ public class TestIndexWriterReader extends LuceneTestCase { String id10 = r1.document(10).getField("id").stringValue(); - Document newDoc = r1.document(10); + StoredDocument newDoc = r1.document(10); newDoc.removeField("id"); newDoc.add(newStringField("id", Integer.toString(8000), Field.Store.YES)); - writer.updateDocument(new Term("id", id10), newDoc); + writer.updateDocument(new Term("id", id10), newDoc.asIndexable()); assertFalse(r1.isCurrent()); DirectoryReader r2 = writer.getReader(); @@ -271,9 +272,9 @@ public class TestIndexWriterReader extends LuceneTestCase { assertEquals(100, index2df); // verify the docs are from different indexes - Document doc5 = r1.document(5); + StoredDocument doc5 = r1.document(5); assertEquals("index1", doc5.get("indexname")); - Document doc150 = r1.document(150); + StoredDocument doc150 = r1.document(150); assertEquals("index2", doc150.get("indexname")); r1.close(); writer.close(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java index 11a19e880c9..6ff458190f3 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java @@ -26,6 +26,7 @@ import java.util.Set; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRef; @@ -259,7 +260,7 @@ public class TestIndexWriterUnicode extends LuceneTestCase { w.close(); IndexReader ir = DirectoryReader.open(dir); - Document doc2 = ir.document(0); + StoredDocument doc2 = ir.document(0); for(int i=0;i() { + IndexDocument d = new IndexDocument() { @Override - public Iterator iterator() { - return new Iterator() { - int fieldUpto; - + public Iterable indexableFields() { + return new Iterable() { @Override - public boolean hasNext() { - return fieldUpto < fieldCount; - } + public Iterator iterator() { + return new Iterator() { + int fieldUpto = 0; + private IndexableField next; - @Override - public IndexableField next() { - assert fieldUpto < fieldCount; - if (fieldUpto == 0) { - fieldUpto = 1; - return newStringField("id", ""+finalDocCount, Field.Store.YES); - } else { - return new MyField(finalBaseCount + (fieldUpto++-1)); - } - } + @Override + public boolean hasNext() { + if (fieldUpto >= fieldCount) return false; + next = null; + if (fieldUpto > 1) + next = new MyField(finalBaseCount + (fieldUpto++-1)); + else + fieldUpto = 2; + + if (next != null && next.fieldType().indexed()) return true; + else return this.hasNext(); + } - @Override - public void remove() { - throw new UnsupportedOperationException(); + @Override + public IndexableField next() { + assert fieldUpto <= fieldCount; + if (next == null && !hasNext()) { + return null; + } + else { + return next; + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; } }; } - }); + + @Override + public Iterable storableFields() { + return new Iterable() { + @Override + public Iterator iterator() { + return new Iterator() { + int fieldUpto = 0; + private StorableField next = null; + + @Override + public boolean hasNext() { + + if (fieldUpto == fieldCount) return false; + + next = null; + if (fieldUpto == 0) { + fieldUpto = 1; + next = newStringField("id", ""+finalDocCount, Field.Store.YES); + } else { + next = new MyField(finalBaseCount + (fieldUpto++-1)); + } + + if (next != null && next.fieldType().stored()) return true; + else return this.hasNext(); + } + + @Override + public StorableField next() { + assert fieldUpto <= fieldCount; + if (next == null && !hasNext()) { + return null; + } + else { + return next; + } + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + }; + } + }; + + w.addDocument(d); } final IndexReader r = w.getReader(); @@ -218,10 +281,11 @@ public class TestIndexableField extends LuceneTestCase { if (VERBOSE) { System.out.println("TEST: verify doc id=" + id + " (" + fieldsPerDoc[id] + " fields) counter=" + counter); } + final TopDocs hits = s.search(new TermQuery(new Term("id", ""+id)), 1); assertEquals(1, hits.totalHits); final int docID = hits.scoreDocs[0].doc; - final Document doc = s.doc(docID); + final StoredDocument doc = s.doc(docID); final int endCounter = counter + fieldsPerDoc[id]; while(counter < endCounter) { final String name = "f" + counter; @@ -240,7 +304,7 @@ public class TestIndexableField extends LuceneTestCase { // stored: if (stored) { - IndexableField f = doc.getField(name); + StorableField f = doc.getField(name); assertNotNull("doc " + id + " doesn't have field f" + counter, f); if (binary) { assertNotNull("doc " + id + " doesn't have field f" + counter, f); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestNorms.java b/lucene/core/src/test/org/apache/lucene/index/TestNorms.java index f7447aa44e4..11c27089918 100755 --- a/lucene/core/src/test/org/apache/lucene/index/TestNorms.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestNorms.java @@ -23,6 +23,7 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; @@ -105,7 +106,7 @@ public class TestNorms extends LuceneTestCase { assertEquals(Type.FIXED_INTS_8, normValues.getType()); byte[] norms = (byte[]) source.getArray(); for (int i = 0; i < open.maxDoc(); i++) { - Document document = open.document(i); + StoredDocument document = open.document(i); int expected = Integer.parseInt(document.get(byteTestField)); assertEquals((byte)expected, norms[i]); } @@ -164,7 +165,7 @@ public class TestNorms extends LuceneTestCase { assertEquals(Type.FIXED_INTS_8, normValues.getType()); byte[] norms = (byte[]) source.getArray(); for (int i = 0; i < mergedReader.maxDoc(); i++) { - Document document = mergedReader.document(i); + StoredDocument document = mergedReader.document(i); int expected = Integer.parseInt(document.get(byteTestField)); assertEquals((byte) expected, norms[i]); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestParallelAtomicReader.java b/lucene/core/src/test/org/apache/lucene/index/TestParallelAtomicReader.java index c7760f6317b..58d061b29a9 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestParallelAtomicReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestParallelAtomicReader.java @@ -23,6 +23,7 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; @@ -224,8 +225,8 @@ public class TestParallelAtomicReader extends LuceneTestCase { assertEquals(parallelHits.length, singleHits.length); for(int i = 0; i < parallelHits.length; i++) { assertEquals(parallelHits[i].score, singleHits[i].score, 0.001f); - Document docParallel = parallel.doc(parallelHits[i].doc); - Document docSingle = single.doc(singleHits[i].doc); + StoredDocument docParallel = parallel.doc(parallelHits[i].doc); + StoredDocument docSingle = single.doc(singleHits[i].doc); assertEquals(docParallel.get("f1"), docSingle.get("f1")); assertEquals(docParallel.get("f2"), docSingle.get("f2")); assertEquals(docParallel.get("f3"), docSingle.get("f3")); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestParallelCompositeReader.java b/lucene/core/src/test/org/apache/lucene/index/TestParallelCompositeReader.java index 68b417945c2..994fd2a7560 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestParallelCompositeReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestParallelCompositeReader.java @@ -23,6 +23,7 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; @@ -283,8 +284,8 @@ public class TestParallelCompositeReader extends LuceneTestCase { assertEquals(parallelHits.length, singleHits.length); for(int i = 0; i < parallelHits.length; i++) { assertEquals(parallelHits[i].score, singleHits[i].score, 0.001f); - Document docParallel = parallel.doc(parallelHits[i].doc); - Document docSingle = single.doc(singleHits[i].doc); + StoredDocument docParallel = parallel.doc(parallelHits[i].doc); + StoredDocument docSingle = single.doc(singleHits[i].doc); assertEquals(docParallel.get("f1"), docSingle.get("f1")); assertEquals(docParallel.get("f2"), docSingle.get("f2")); assertEquals(docParallel.get("f3"), docSingle.get("f3")); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java b/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java index 987594c8862..109aa39cde5 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java @@ -240,7 +240,7 @@ public class TestPostingsOffsets extends LuceneTestCase { for(int docCount=0;docCount tokens = new ArrayList(); final int numTokens = atLeast(100); //final int numTokens = atLeast(20); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestRandomStoredFields.java b/lucene/core/src/test/org/apache/lucene/index/TestRandomStoredFields.java index fc74f90b9f7..af3a0f5c36e 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestRandomStoredFields.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestRandomStoredFields.java @@ -29,6 +29,7 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.TermQuery; @@ -121,7 +122,7 @@ public class TestRandomStoredFields extends LuceneTestCase { } TopDocs hits = s.search(new TermQuery(new Term("id", testID)), 1); assertEquals(1, hits.totalHits); - Document doc = r.document(hits.scoreDocs[0].doc); + StoredDocument doc = r.document(hits.scoreDocs[0].doc); Document docExp = docs.get(testID); for(int i=0;i= 1); - Document result = reader.document(0); + StoredDocument result = reader.document(0); assertTrue(result != null); //There are 2 unstored fields on the document that are not preserved across writing assertTrue(DocHelper.numFields(result) == DocHelper.numFields(testDoc) - DocHelper.unstored.size()); - List fields = result.getFields(); - for (final IndexableField field : fields ) { + List fields = result.getFields(); + for (final StorableField field : fields ) { assertTrue(field != null); assertTrue(DocHelper.nameValues.containsKey(field.name())); } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestStressIndexing2.java b/lucene/core/src/test/org/apache/lucene/index/TestStressIndexing2.java index e9caa08ea95..c8776d73c78 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestStressIndexing2.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestStressIndexing2.java @@ -32,6 +32,7 @@ import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.search.DocIdSetIterator; @@ -133,8 +134,8 @@ public class TestStressIndexing2 extends LuceneTestCase { static Term idTerm = new Term("id",""); IndexingThread[] threads; - static Comparator fieldNameComparator = new Comparator() { - public int compare(IndexableField o1, IndexableField o2) { + static Comparator fieldNameComparator = new Comparator() { + public int compare(GeneralField o1, GeneralField o2) { return o1.name().compareTo(o2.name()); } }; @@ -287,7 +288,7 @@ public class TestStressIndexing2 extends LuceneTestCase { Bits liveDocs = ((AtomicReader)sub).getLiveDocs(); System.out.println(" " + ((SegmentReader) sub).getSegmentInfo()); for(int docID=0;docID ff1 = d1.getFields(); - List ff2 = d2.getFields(); + public static void verifyEquals(StoredDocument d1, StoredDocument d2) { + List ff1 = d1.getFields(); + List ff2 = d2.getFields(); Collections.sort(ff1, fieldNameComparator); Collections.sort(ff2, fieldNameComparator); @@ -586,8 +587,8 @@ public class TestStressIndexing2 extends LuceneTestCase { assertEquals(ff1 + " : " + ff2, ff1.size(), ff2.size()); for (int i=0; i> docs) throws Exception { + protected void updateDocuments(Term id, List docs) throws Exception { final long gen = genWriter.updateDocuments(id, docs); // Randomly verify the update "took": @@ -99,7 +100,7 @@ public class TestNRTManager extends ThreadedIndexingAndSearchingTestCase { } @Override - protected void addDocuments(Term id, List> docs) throws Exception { + protected void addDocuments(Term id, List docs) throws Exception { final long gen = genWriter.addDocuments(docs); // Randomly verify the add "took": if (random().nextInt(20) == 2) { @@ -121,7 +122,7 @@ public class TestNRTManager extends ThreadedIndexingAndSearchingTestCase { } @Override - protected void addDocument(Term id, Iterable doc) throws Exception { + protected void addDocument(Term id, IndexDocument doc) throws Exception { final long gen = genWriter.addDocument(doc); // Randomly verify the add "took": @@ -144,7 +145,7 @@ public class TestNRTManager extends ThreadedIndexingAndSearchingTestCase { } @Override - protected void updateDocument(Term id, Iterable doc) throws Exception { + protected void updateDocument(Term id, IndexDocument doc) throws Exception { final long gen = genWriter.updateDocument(id, doc); // Randomly verify the udpate "took": if (random().nextInt(20) == 2) { @@ -373,7 +374,7 @@ public class TestNRTManager extends ThreadedIndexingAndSearchingTestCase { } public void updateDocument(Term term, - Iterable doc, Analyzer analyzer) + IndexDocument doc, Analyzer analyzer) throws IOException { super.updateDocument(term, doc, analyzer); try { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java index 456ec914cb3..4fba715e6db 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.FloatField; import org.apache.lucene.document.IntField; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; @@ -173,7 +174,7 @@ public class TestNumericRangeQuery32 extends LuceneTestCase { ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count"+type, count, sd.length ); - Document doc=searcher.doc(sd[0].doc); + StoredDocument doc=searcher.doc(sd[0].doc); assertEquals("First doc"+type, 2*distance+startOffset, doc.getField(field).numericValue().intValue()); doc=searcher.doc(sd[sd.length-1].doc); assertEquals("Last doc"+type, (1+count)*distance+startOffset, doc.getField(field).numericValue().intValue()); @@ -227,7 +228,7 @@ public class TestNumericRangeQuery32 extends LuceneTestCase { ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", count, sd.length ); - Document doc=searcher.doc(sd[0].doc); + StoredDocument doc=searcher.doc(sd[0].doc); assertEquals("First doc", startOffset, doc.getField(field).numericValue().intValue()); doc=searcher.doc(sd[sd.length-1].doc); assertEquals("Last doc", (count-1)*distance+startOffset, doc.getField(field).numericValue().intValue()); @@ -267,7 +268,7 @@ public class TestNumericRangeQuery32 extends LuceneTestCase { ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", noDocs-count, sd.length ); - Document doc=searcher.doc(sd[0].doc); + StoredDocument doc=searcher.doc(sd[0].doc); assertEquals("First doc", count*distance+startOffset, doc.getField(field).numericValue().intValue()); doc=searcher.doc(sd[sd.length-1].doc); assertEquals("Last doc", (noDocs-1)*distance+startOffset, doc.getField(field).numericValue().intValue()); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java index 82dc587a1cb..b2b2c9b6d8d 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.DoubleField; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.LongField; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; @@ -182,7 +183,7 @@ public class TestNumericRangeQuery64 extends LuceneTestCase { ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count"+type, count, sd.length ); - Document doc=searcher.doc(sd[0].doc); + StoredDocument doc=searcher.doc(sd[0].doc); assertEquals("First doc"+type, 2*distance+startOffset, doc.getField(field).numericValue().longValue() ); doc=searcher.doc(sd[sd.length-1].doc); assertEquals("Last doc"+type, (1+count)*distance+startOffset, doc.getField(field).numericValue().longValue() ); @@ -242,7 +243,7 @@ public class TestNumericRangeQuery64 extends LuceneTestCase { ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", count, sd.length ); - Document doc=searcher.doc(sd[0].doc); + StoredDocument doc=searcher.doc(sd[0].doc); assertEquals("First doc", startOffset, doc.getField(field).numericValue().longValue() ); doc=searcher.doc(sd[sd.length-1].doc); assertEquals("Last doc", (count-1)*distance+startOffset, doc.getField(field).numericValue().longValue() ); @@ -287,7 +288,7 @@ public class TestNumericRangeQuery64 extends LuceneTestCase { ScoreDoc[] sd = topDocs.scoreDocs; assertNotNull(sd); assertEquals("Score doc count", noDocs-count, sd.length ); - Document doc=searcher.doc(sd[0].doc); + StoredDocument doc=searcher.doc(sd[0].doc); assertEquals("First doc", count*distance+startOffset, doc.getField(field).numericValue().longValue() ); doc=searcher.doc(sd[sd.length-1].doc); assertEquals("Last doc", (noDocs-1)*distance+startOffset, doc.getField(field).numericValue().longValue() ); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSort.java b/lucene/core/src/test/org/apache/lucene/search/TestSort.java index cd4d90133ad..32d09edf654 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSort.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSort.java @@ -38,6 +38,7 @@ import org.apache.lucene.document.FieldType; import org.apache.lucene.document.FloatDocValuesField; import org.apache.lucene.document.PackedLongDocValuesField; import org.apache.lucene.document.SortedBytesDocValuesField; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StraightBytesDocValuesField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; @@ -50,6 +51,7 @@ import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.MultiReader; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.StorableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.FieldValueHitQueue.Entry; @@ -522,9 +524,9 @@ public class TestSort extends LuceneTestCase { boolean fail = false; final String fieldSuffix = sort.getSort()[0].getField().endsWith("_fixed") ? "_fixed" : ""; for (int x = 0; x < n; ++x) { - Document doc2 = searcher.doc(result[x].doc); - IndexableField[] v = doc2.getFields("tracer" + fieldSuffix); - IndexableField[] v2 = doc2.getFields("tracer2" + fieldSuffix); + StoredDocument doc2 = searcher.doc(result[x].doc); + StorableField[] v = doc2.getFields("tracer" + fieldSuffix); + StorableField[] v2 = doc2.getFields("tracer2" + fieldSuffix); for (int j = 0; j < v.length; ++j) { buff.append(v[j] + "(" + v2[j] + ")(" + result[x].doc+")\n"); if (last != null) { @@ -1229,8 +1231,8 @@ public class TestSort extends LuceneTestCase { StringBuilder buff = new StringBuilder(10); int n = result.length; for (int i=0; i void addDocument(final Iterable doc) throws IOException { + public void addDocument(final IndexDocument doc) throws IOException { addDocument(doc, w.getAnalyzer()); } - public void addDocument(final Iterable doc, Analyzer a) throws IOException { + public void addDocument(final IndexDocument doc, Analyzer a) throws IOException { if (doDocValues && doc instanceof Document) { randomPerDocFieldValues((Document) doc); } @@ -154,11 +154,11 @@ public class RandomIndexWriter implements Closeable { // (but we need to clone them), and only when // getReader, commit, etc. are called, we do an // addDocuments? Would be better testing. - w.addDocuments(new Iterable>() { + w.addDocuments(new Iterable() { @Override - public Iterator> iterator() { - return new Iterator>() { + public Iterator iterator() { + return new Iterator() { boolean done; @Override @@ -172,7 +172,7 @@ public class RandomIndexWriter implements Closeable { } @Override - public Iterable next() { + public IndexDocument next() { if (done) { throw new IllegalStateException(); } @@ -273,12 +273,12 @@ public class RandomIndexWriter implements Closeable { } } - public void addDocuments(Iterable> docs) throws IOException { + public void addDocuments(Iterable docs) throws IOException { w.addDocuments(docs); maybeCommit(); } - public void updateDocuments(Term delTerm, Iterable> docs) throws IOException { + public void updateDocuments(Term delTerm, Iterable docs) throws IOException { w.updateDocuments(delTerm, docs); maybeCommit(); } @@ -287,16 +287,16 @@ public class RandomIndexWriter implements Closeable { * Updates a document. * @see IndexWriter#updateDocument(Term, Iterable) */ - public void updateDocument(Term t, final Iterable doc) throws IOException { + public void updateDocument(Term t, final IndexDocument doc) throws IOException { if (doDocValues) { randomPerDocFieldValues((Document) doc); } if (r.nextInt(5) == 3) { - w.updateDocuments(t, new Iterable>() { + w.updateDocuments(t, new Iterable() { @Override - public Iterator> iterator() { - return new Iterator>() { + public Iterator iterator() { + return new Iterator() { boolean done; @Override @@ -310,7 +310,7 @@ public class RandomIndexWriter implements Closeable { } @Override - public Iterable next() { + public IndexDocument next() { if (done) { throw new IllegalStateException(); } diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java index 69f946e7891..d1c51943e11 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java @@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.Query; @@ -89,19 +90,19 @@ public abstract class ThreadedIndexingAndSearchingTestCase extends LuceneTestCas return in; } - protected void updateDocuments(Term id, List> docs) throws Exception { + protected void updateDocuments(Term id, List docs) throws Exception { writer.updateDocuments(id, docs); } - protected void addDocuments(Term id, List> docs) throws Exception { + protected void addDocuments(Term id, List docs) throws Exception { writer.addDocuments(docs); } - protected void addDocument(Term id, Iterable doc) throws Exception { + protected void addDocument(Term id, IndexDocument doc) throws Exception { writer.addDocument(doc); } - protected void updateDocument(Term term, Iterable doc) throws Exception { + protected void updateDocument(Term term, IndexDocument doc) throws Exception { writer.updateDocument(term, doc); } @@ -464,7 +465,7 @@ public abstract class ThreadedIndexingAndSearchingTestCase extends LuceneTestCas final int inc = Math.max(1, maxDoc/50); for(int docID=0;docID Date: Sat, 28 Jul 2012 10:56:46 +0000 Subject: [PATCH 04/13] LUCENE-3312: Apply patch 8 git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1366638 13f79535-47bb-0310-9956-ffa450edef68 --- .../analysis/uima/UIMABaseAnalyzerTest.java | 5 ++- .../benchmark/byTask/feeds/DocMaker.java | 1 + .../byTask/tasks/BenchmarkHighlighter.java | 3 +- .../benchmark/byTask/tasks/ReadTask.java | 16 ++++---- .../tasks/SearchTravRetHighlightTask.java | 5 ++- .../SearchTravRetLoadFieldSelectorTask.java | 3 +- .../SearchTravRetVectorHighlightTask.java | 5 ++- .../tasks/CountingHighlighterTestTask.java | 7 ++-- .../org/apache/lucene/document/Document.java | 20 +++++----- .../lucene/index/DocFieldProcessor.java | 2 +- .../lucene/index/NormsConsumerPerField.java | 2 +- .../apache/lucene/util/FilterIterator.java | 10 ++--- .../lucene/index/TestIndexableField.java | 9 +++-- .../lucene/search/highlight/TokenSources.java | 13 ++++--- .../search/highlight/HighlighterTest.java | 5 ++- .../lucene/search/join/TestBlockJoin.java | 38 +++++++++---------- .../apache/lucene/document/LazyDocument.java | 24 +++--------- .../index/TestMultiPassIndexSplitter.java | 5 ++- .../lucene/queries/mlt/MoreLikeThis.java | 8 ++-- .../complexPhrase/TestComplexPhraseQuery.java | 3 +- .../lucene/queryparser/xml/TestParser.java | 3 +- .../sandbox/queries/DuplicateFilterTest.java | 11 +++--- .../queries/FuzzyLikeThisQueryTest.java | 7 ++-- .../lucene/spatial/SpatialTestCase.java | 7 ++-- .../apache/solr/schema/ICUCollationField.java | 3 +- .../solr/handler/MoreLikeThisHandler.java | 3 +- .../handler/admin/LukeRequestHandler.java | 13 ++++--- .../component/RealTimeGetComponent.java | 18 +++++---- .../highlight/DefaultSolrHighlighter.java | 18 +++++---- .../solr/response/BinaryResponseWriter.java | 12 +++--- .../solr/response/TextResponseWriter.java | 16 ++++---- .../org/apache/solr/schema/BCDIntField.java | 8 ++-- .../org/apache/solr/schema/BCDLongField.java | 4 +- .../org/apache/solr/schema/BCDStrField.java | 4 +- .../org/apache/solr/schema/BinaryField.java | 7 ++-- .../org/apache/solr/schema/BoolField.java | 8 ++-- .../org/apache/solr/schema/ByteField.java | 5 ++- .../apache/solr/schema/CollationField.java | 3 +- .../org/apache/solr/schema/CurrencyField.java | 3 +- .../org/apache/solr/schema/DateField.java | 11 ++++-- .../org/apache/solr/schema/DoubleField.java | 5 ++- .../apache/solr/schema/ExternalFileField.java | 3 +- .../org/apache/solr/schema/FieldType.java | 10 +++-- .../org/apache/solr/schema/FloatField.java | 5 ++- .../org/apache/solr/schema/GeoHashField.java | 5 ++- .../org/apache/solr/schema/IndexSchema.java | 6 ++- .../java/org/apache/solr/schema/IntField.java | 5 ++- .../org/apache/solr/schema/LatLonType.java | 3 +- .../org/apache/solr/schema/LongField.java | 5 ++- .../org/apache/solr/schema/PointType.java | 3 +- .../apache/solr/schema/PreAnalyzedField.java | 3 +- .../apache/solr/schema/RandomSortField.java | 3 +- .../org/apache/solr/schema/ShortField.java | 5 ++- .../solr/schema/SortableDoubleField.java | 7 ++-- .../solr/schema/SortableFloatField.java | 7 ++-- .../apache/solr/schema/SortableIntField.java | 7 ++-- .../apache/solr/schema/SortableLongField.java | 7 ++-- .../java/org/apache/solr/schema/StrField.java | 3 +- .../org/apache/solr/schema/TextField.java | 3 +- .../org/apache/solr/schema/TrieDateField.java | 9 +++-- .../org/apache/solr/schema/TrieField.java | 11 +++--- .../org/apache/solr/schema/UUIDField.java | 5 ++- .../apache/solr/search/SolrIndexSearcher.java | 19 +++++----- .../TopGroupsResultTransformer.java | 7 ++-- .../org/apache/solr/util/SolrPluginUtils.java | 8 ++-- .../apache/solr/BasicFunctionalityTest.java | 5 ++- .../apache/solr/search/TestStressLucene.java | 3 +- 67 files changed, 284 insertions(+), 226 deletions(-) diff --git a/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java b/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java index ffff5f93d0e..d31dc267822 100644 --- a/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java +++ b/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java @@ -21,6 +21,7 @@ import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; @@ -80,7 +81,7 @@ public class UIMABaseAnalyzerTest extends BaseTokenStreamTestCase { IndexSearcher indexSearcher = new IndexSearcher(directoryReader); TopDocs result = indexSearcher.search(new MatchAllDocsQuery(), 10); assertTrue(result.totalHits > 0); - Document d = indexSearcher.doc(result.scoreDocs[0].doc); + StoredDocument d = indexSearcher.doc(result.scoreDocs[0].doc); assertNotNull(d); assertNotNull(d.getField("title")); assertEquals(dummyTitle, d.getField("title").stringValue()); @@ -100,7 +101,7 @@ public class UIMABaseAnalyzerTest extends BaseTokenStreamTestCase { directoryReader = DirectoryReader.open(dir); indexSearcher = new IndexSearcher(directoryReader); result = indexSearcher.search(new MatchAllDocsQuery(), 10); - Document d1 = indexSearcher.doc(result.scoreDocs[1].doc); + StoredDocument d1 = indexSearcher.doc(result.scoreDocs[1].doc); assertNotNull(d1); assertNotNull(d1.getField("title")); assertEquals(dogmasTitle, d1.getField("title").stringValue()); diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java index af434cc8dab..f593d7afaed 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java @@ -231,6 +231,7 @@ public class DocMaker implements Closeable { // Set ID_FIELD FieldType ft = new FieldType(valType); ft.setIndexed(true); + ft.setStored(true); Field idField = ds.getField(ID_FIELD, ft); int id; diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java index fd229d08964..91d59cddf38 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java @@ -19,6 +19,7 @@ package org.apache.lucene.benchmark.byTask.tasks; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Document; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexReader; /** @@ -26,5 +27,5 @@ import org.apache.lucene.index.IndexReader; */ public abstract class BenchmarkHighlighter { public abstract int doHighlight( IndexReader reader, int doc, String field, - Document document, Analyzer analyzer, String text ) throws Exception ; + StoredDocument document, Analyzer analyzer, String text ) throws Exception ; } diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java index f1cce8a8a37..075934f7c2a 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java @@ -28,10 +28,12 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.benchmark.byTask.feeds.QueryMaker; import org.apache.lucene.document.Document; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.MultiFields; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.Collector; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.MultiTermQuery; @@ -96,7 +98,7 @@ public abstract class ReadTask extends PerfTask { // optionally warm and add num docs traversed to count if (withWarm()) { - Document doc = null; + StoredDocument doc = null; Bits liveDocs = MultiFields.getLiveDocs(reader); for (int m = 0; m < reader.maxDoc(); m++) { if (null == liveDocs || liveDocs.get(m)) { @@ -142,7 +144,7 @@ public abstract class ReadTask extends PerfTask { System.out.println("numDocs() = " + reader.numDocs()); for(int i=0;irandom words for second field", result); diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java index 44555003b12..851f2f716a4 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java @@ -119,11 +119,11 @@ public class TestBlockJoin extends LuceneTestCase { assertEquals(1, group.totalHits); assertFalse(Float.isNaN(group.score)); - Document childDoc = s.doc(group.scoreDocs[0].doc); + StoredDocument childDoc = s.doc(group.scoreDocs[0].doc); //System.out.println(" doc=" + group.scoreDocs[0].doc); assertEquals("java", childDoc.get("skill")); assertNotNull(group.groupValue); - Document parentDoc = s.doc(group.groupValue); + StoredDocument parentDoc = s.doc(group.groupValue); assertEquals("Lisa", parentDoc.get("name")); @@ -247,7 +247,7 @@ public class TestBlockJoin extends LuceneTestCase { } } - private Document getParentDoc(IndexReader reader, Filter parents, int childDocID) throws IOException { + private StoredDocument getParentDoc(IndexReader reader, Filter parents, int childDocID) throws IOException { final List leaves = reader.getTopReaderContext().leaves(); final int subIndex = ReaderUtil.subIndex(childDocID, leaves); final AtomicReaderContext leaf = leaves.get(subIndex); @@ -563,7 +563,7 @@ public class TestBlockJoin extends LuceneTestCase { System.out.println("\nTEST: normal index gets " + results.totalHits + " hits"); final ScoreDoc[] hits = results.scoreDocs; for(int hitIDX=0;hitIDX group = groupDocs[joinGroupUpto++]; final ScoreDoc[] groupHits = group.scoreDocs; assertNotNull(group.groupValue); - final Document parentDoc = joinR.document(group.groupValue); + final StoredDocument parentDoc = joinR.document(group.groupValue); final String parentID = parentDoc.get("parentID"); //System.out.println("GROUP groupDoc=" + group.groupDoc + " parent=" + parentDoc); assertNotNull(parentID); assertTrue(groupHits.length > 0); for(int hitIDX=0;hitIDX group = jobResults.groups[0]; assertEquals(1, group.totalHits); - Document childJobDoc = s.doc(group.scoreDocs[0].doc); + StoredDocument childJobDoc = s.doc(group.scoreDocs[0].doc); //System.out.println(" doc=" + group.scoreDocs[0].doc); assertEquals("java", childJobDoc.get("skill")); assertNotNull(group.groupValue); - Document parentDoc = s.doc(group.groupValue); + StoredDocument parentDoc = s.doc(group.groupValue); assertEquals("Lisa", parentDoc.get("name")); } @@ -933,10 +933,10 @@ public class TestBlockJoin extends LuceneTestCase { final GroupDocs qGroup = qualificationResults.groups[0]; assertEquals(1, qGroup.totalHits); - Document childQualificationDoc = s.doc(qGroup.scoreDocs[0].doc); + StoredDocument childQualificationDoc = s.doc(qGroup.scoreDocs[0].doc); assertEquals("maths", childQualificationDoc.get("qualification")); assertNotNull(qGroup.groupValue); - Document parentDoc = s.doc(qGroup.groupValue); + StoredDocument parentDoc = s.doc(qGroup.groupValue); assertEquals("Lisa", parentDoc.get("name")); diff --git a/lucene/misc/src/java/org/apache/lucene/document/LazyDocument.java b/lucene/misc/src/java/org/apache/lucene/document/LazyDocument.java index 06563cdf3e3..b3a16af2b06 100644 --- a/lucene/misc/src/java/org/apache/lucene/document/LazyDocument.java +++ b/lucene/misc/src/java/org/apache/lucene/document/LazyDocument.java @@ -25,8 +25,8 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.IndexableFieldType; +import org.apache.lucene.index.StorableField; import org.apache.lucene.util.BytesRef; /** Defers actually loading a field's value until you ask @@ -38,7 +38,7 @@ public class LazyDocument { private final int docID; // null until first field is loaded - private Document doc; + private StoredDocument doc; private Map fields = new HashMap(); @@ -47,7 +47,7 @@ public class LazyDocument { this.docID = docID; } - public IndexableField getField(FieldInfo fieldInfo) { + public StorableField getField(FieldInfo fieldInfo) { Integer num = fields.get(fieldInfo.number); if (num == null) { num = 0; @@ -59,7 +59,7 @@ public class LazyDocument { return new LazyField(fieldInfo.name, num); } - private synchronized Document getDocument() { + private synchronized StoredDocument getDocument() { if (doc == null) { try { doc = reader.document(docID); @@ -71,7 +71,7 @@ public class LazyDocument { return doc; } - private class LazyField implements IndexableField { + private class LazyField implements StorableField { private String name; private int num; @@ -85,11 +85,6 @@ public class LazyDocument { return name; } - @Override - public float boost() { - return 1.0f; - } - @Override public BytesRef binaryValue() { if (num == 0) { @@ -134,14 +129,5 @@ public class LazyDocument { return getDocument().getFields(name)[num].fieldType(); } } - - @Override - public TokenStream tokenStream(Analyzer analyzer) throws IOException { - if (num == 0) { - return getDocument().getField(name).tokenStream(analyzer); - } else { - return getDocument().getFields(name)[num].tokenStream(analyzer); - } - } } } diff --git a/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java b/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java index 7f1535779bb..1f808e3c0a2 100644 --- a/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java +++ b/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java @@ -19,6 +19,7 @@ package org.apache.lucene.index; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; @@ -68,7 +69,7 @@ public class TestMultiPassIndexSplitter extends LuceneTestCase { IndexReader ir; ir = DirectoryReader.open(dirs[0]); assertTrue(ir.numDocs() - NUM_DOCS / 3 <= 1); // rounding error - Document doc = ir.document(0); + StoredDocument doc = ir.document(0); assertEquals("0", doc.get("id")); TermsEnum te = MultiFields.getTerms(ir, "id").iterator(null); assertEquals(TermsEnum.SeekStatus.NOT_FOUND, te.seekCeil(new BytesRef("1"))); @@ -113,7 +114,7 @@ public class TestMultiPassIndexSplitter extends LuceneTestCase { IndexReader ir; ir = DirectoryReader.open(dirs[0]); assertTrue(ir.numDocs() - NUM_DOCS / 3 <= 1); - Document doc = ir.document(0); + StoredDocument doc = ir.document(0); assertEquals("0", doc.get("id")); int start = ir.numDocs(); ir.close(); diff --git a/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java b/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java index d8b97762782..06787dbdd7b 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java @@ -22,10 +22,12 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.document.Document; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.Fields; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.MultiFields; +import org.apache.lucene.index.StorableField; import org.apache.lucene.index.Term; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; @@ -715,9 +717,9 @@ public final class MoreLikeThis { // field does not store term vector info if (vector == null) { - Document d = ir.document(docNum); - IndexableField fields[] = d.getFields(fieldName); - for (IndexableField field : fields) { + StoredDocument d = ir.document(docNum); + StorableField[] fields = d.getFields(fieldName); + for (StorableField field : fields) { final String stringValue = field.stringValue(); if (stringValue != null) { addTermFrequencies(new StringReader(stringValue), termFreqMap, fieldName); diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java index 23ec531a4f3..a86976f4bd9 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java @@ -23,6 +23,7 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; @@ -100,7 +101,7 @@ public class TestComplexPhraseQuery extends LuceneTestCase { TopDocs td = searcher.search(q, 10); ScoreDoc[] sd = td.scoreDocs; for (int i = 0; i < sd.length; i++) { - Document doc = searcher.doc(sd[i].doc); + StoredDocument doc = searcher.doc(sd[i].doc); String id = doc.get("id"); assertTrue(qString + "matched doc#" + id + " not expected", expecteds .contains(id)); diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java index e087f644a54..03f46408f41 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java @@ -24,6 +24,7 @@ import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.IntField; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; @@ -232,7 +233,7 @@ public class TestParser extends LuceneTestCase { System.out.println("=========" + qType + "============"); ScoreDoc[] scoreDocs = hits.scoreDocs; for (int i = 0; i < Math.min(numDocs, hits.totalHits); i++) { - Document ldoc = searcher.doc(scoreDocs[i].doc); + StoredDocument ldoc = searcher.doc(scoreDocs[i].doc); System.out.println("[" + ldoc.get("date") + "]" + ldoc.get("contents")); } System.out.println(); diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/DuplicateFilterTest.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/DuplicateFilterTest.java index 9b13f995b6b..a665ad28a53 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/DuplicateFilterTest.java +++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/DuplicateFilterTest.java @@ -23,6 +23,7 @@ import java.util.HashSet; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.*; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexSearcher; @@ -87,7 +88,7 @@ public class DuplicateFilterTest extends LuceneTestCase { ScoreDoc[] hits = searcher.search(tq, df, 1000).scoreDocs; for (ScoreDoc hit : hits) { - Document d = searcher.doc(hit.doc); + StoredDocument d = searcher.doc(hit.doc); String url = d.get(KEY_FIELD); assertFalse("No duplicate urls should be returned", results.contains(url)); results.add(url); @@ -101,7 +102,7 @@ public class DuplicateFilterTest extends LuceneTestCase { boolean dupsFound = false; for (ScoreDoc hit : hits) { - Document d = searcher.doc(hit.doc); + StoredDocument d = searcher.doc(hit.doc); String url = d.get(KEY_FIELD); if (!dupsFound) dupsFound = results.contains(url); @@ -118,7 +119,7 @@ public class DuplicateFilterTest extends LuceneTestCase { assertTrue("Filtered searching should have found some matches", hits.length > 0); for (ScoreDoc hit : hits) { - Document d = searcher.doc(hit.doc); + StoredDocument d = searcher.doc(hit.doc); String url = d.get(KEY_FIELD); assertFalse("No duplicate urls should be returned", results.contains(url)); results.add(url); @@ -132,7 +133,7 @@ public class DuplicateFilterTest extends LuceneTestCase { ScoreDoc[] hits = searcher.search(tq, df, 1000).scoreDocs; assertTrue("Filtered searching should have found some matches", hits.length > 0); for (ScoreDoc hit : hits) { - Document d = searcher.doc(hit.doc); + StoredDocument d = searcher.doc(hit.doc); String url = d.get(KEY_FIELD); DocsEnum td = _TestUtil.docs(random(), reader, KEY_FIELD, @@ -156,7 +157,7 @@ public class DuplicateFilterTest extends LuceneTestCase { ScoreDoc[] hits = searcher.search(tq, df, 1000).scoreDocs; assertTrue("Filtered searching should have found some matches", hits.length > 0); for (ScoreDoc hit : hits) { - Document d = searcher.doc(hit.doc); + StoredDocument d = searcher.doc(hit.doc); String url = d.get(KEY_FIELD); DocsEnum td = _TestUtil.docs(random(), reader, KEY_FIELD, diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java index dfedd8adecb..ce9bdbe28a4 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java +++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java @@ -21,6 +21,7 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; @@ -88,7 +89,7 @@ public class FuzzyLikeThisQueryTest extends LuceneTestCase { TopDocs topDocs = searcher.search(flt, 1); ScoreDoc[] sd = topDocs.scoreDocs; assertTrue("score docs must match 1 doc", (sd != null) && (sd.length > 0)); - Document doc = searcher.doc(sd[0].doc); + StoredDocument doc = searcher.doc(sd[0].doc); assertEquals("Should match most similar not most rare variant", "2", doc.get("id")); } @@ -104,7 +105,7 @@ public class FuzzyLikeThisQueryTest extends LuceneTestCase { TopDocs topDocs = searcher.search(flt, 1); ScoreDoc[] sd = topDocs.scoreDocs; assertTrue("score docs must match 1 doc", (sd != null) && (sd.length > 0)); - Document doc = searcher.doc(sd[0].doc); + StoredDocument doc = searcher.doc(sd[0].doc); assertEquals("Should match most similar when using 2 words", "2", doc.get("id")); } @@ -119,7 +120,7 @@ public class FuzzyLikeThisQueryTest extends LuceneTestCase { TopDocs topDocs = searcher.search(flt, 1); ScoreDoc[] sd = topDocs.scoreDocs; assertTrue("score docs must match 1 doc", (sd != null) && (sd.length > 0)); - Document doc = searcher.doc(sd[0].doc); + StoredDocument doc = searcher.doc(sd[0].doc); assertEquals("Should match most similar when using 2 words", "2", doc.get("id")); } diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java index 8d1741dcc90..e78b4d01673 100644 --- a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java +++ b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java @@ -18,6 +18,7 @@ package org.apache.lucene.spatial; import org.apache.lucene.document.Document; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.search.IndexSearcher; @@ -130,11 +131,11 @@ public abstract class SpatialTestCase extends LuceneTestCase { protected static class SearchResult { public float score; - public Document document; + public StoredDocument document; - public SearchResult(float score, Document document) { + public SearchResult(float score, StoredDocument storedDocument) { this.score = score; - this.document = document; + this.document = storedDocument; } @Override diff --git a/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java b/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java index 88e1ce5c675..6a7b6fc564c 100644 --- a/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java +++ b/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java @@ -27,6 +27,7 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute; import org.apache.lucene.collation.ICUCollationKeyAnalyzer; +import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.Query; import org.apache.lucene.search.SortField; @@ -210,7 +211,7 @@ public class ICUCollationField extends FieldType { } @Override - public void write(TextResponseWriter writer, String name, IndexableField f) throws IOException { + public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { writer.writeStr(name, f.stringValue(), true); } diff --git a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java index 7a5a0fadb20..59f8d3c106c 100644 --- a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.regex.Pattern; import org.apache.lucene.document.Document; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.lucene.queryparser.classic.ParseException; @@ -342,7 +343,7 @@ public class MoreLikeThisHandler extends RequestHandlerBase public DocListAndSet getMoreLikeThis( int id, int start, int rows, List filters, List terms, int flags ) throws IOException { - Document doc = reader.document(id); + StoredDocument doc = reader.document(id); rawMLTQuery = mlt.like(id); boostedMLTQuery = getBoostedQuery( rawMLTQuery ); if( terms != null ) { diff --git a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java index 16eb4cb140d..3f4c37a5f8e 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java @@ -28,6 +28,7 @@ import org.apache.lucene.analysis.util.TokenFilterFactory; import org.apache.lucene.analysis.util.TokenizerFactory; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.*; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.DocIdSetIterator; @@ -132,7 +133,7 @@ public class LukeRequestHandler extends RequestHandlerBase if( style != null && style != ShowStyle.DOC ) { throw new SolrException(ErrorCode.BAD_REQUEST, "missing doc param for doc style"); } - Document doc = null; + StoredDocument doc = null; try { doc = reader.document( docId ); } @@ -169,7 +170,7 @@ public class LukeRequestHandler extends RequestHandlerBase /** * @return a string representing a IndexableField's flags. */ - private static String getFieldFlags( IndexableField f ) + private static String getFieldFlags( StorableField f ) { IndexOptions opts = (f == null) ? null : f.fieldType().indexOptions(); @@ -238,7 +239,7 @@ public class LukeRequestHandler extends RequestHandlerBase return key; } - private static SimpleOrderedMap getDocumentFieldsInfo( Document doc, int docId, IndexReader reader, + private static SimpleOrderedMap getDocumentFieldsInfo( StoredDocument doc, int docId, IndexReader reader, IndexSchema schema ) throws IOException { final CharsRef spare = new CharsRef(); @@ -342,13 +343,13 @@ public class LukeRequestHandler extends RequestHandlerBase if(sfield != null && sfield.indexed() ) { // In the pre-4.0 days, this did a veeeery expensive range query. But we can be much faster now, // so just do this all the time. - Document doc = getFirstLiveDoc(reader, fieldName, terms); + StoredDocument doc = getFirstLiveDoc(reader, fieldName, terms); if( doc != null ) { // Found a document with this field try { - IndexableField fld = doc.getField( fieldName ); + StorableField fld = doc.getField( fieldName ); if( fld != null ) { fieldMap.add("index", getFieldFlags(fld)); } @@ -376,7 +377,7 @@ public class LukeRequestHandler extends RequestHandlerBase // Just get a document with the term in it, the first one will do! // Is there a better way to do this? Shouldn't actually be very costly // to do it this way. - private static Document getFirstLiveDoc(AtomicReader reader, String fieldName, Terms terms) throws IOException { + private static StoredDocument getFirstLiveDoc(AtomicReader reader, String fieldName, Terms terms) throws IOException { DocsEnum docsEnum = null; TermsEnum termsEnum = terms.iterator(null); BytesRef text; diff --git a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java index 5efeff52d49..9450a4e1cf6 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java @@ -18,7 +18,9 @@ package org.apache.solr.handler.component; */ import org.apache.lucene.document.Document; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.index.Term; import org.apache.lucene.util.BytesRef; import org.apache.solr.client.solrj.SolrResponse; @@ -169,7 +171,7 @@ public class RealTimeGetComponent extends SearchComponent int docid = searcher.getFirstMatch(new Term(idField.getName(), idBytes)); if (docid < 0) continue; - Document luceneDocument = searcher.doc(docid); + StoredDocument luceneDocument = searcher.doc(docid); SolrDocument doc = toSolrDoc(luceneDocument, req.getSchema()); if( transformer != null ) { transformer.transform(doc, docid); @@ -236,7 +238,7 @@ public class RealTimeGetComponent extends SearchComponent int docid = searcher.getFirstMatch(new Term(idField.getName(), idBytes)); if (docid < 0) return null; - Document luceneDocument = searcher.doc(docid); + StoredDocument luceneDocument = searcher.doc(docid); sid = toSolrInputDocument(luceneDocument, core.getSchema()); } } finally { @@ -248,9 +250,9 @@ public class RealTimeGetComponent extends SearchComponent return sid; } - private static SolrInputDocument toSolrInputDocument(Document doc, IndexSchema schema) { + private static SolrInputDocument toSolrInputDocument(StoredDocument doc, IndexSchema schema) { SolrInputDocument out = new SolrInputDocument(); - for( IndexableField f : doc.getFields() ) { + for( StorableField f : doc.getFields() ) { String fname = f.name(); SchemaField sf = schema.getFieldOrNull(f.name()); Object val = null; @@ -270,9 +272,9 @@ public class RealTimeGetComponent extends SearchComponent } - private static SolrDocument toSolrDoc(Document doc, IndexSchema schema) { + private static SolrDocument toSolrDoc(StoredDocument doc, IndexSchema schema) { SolrDocument out = new SolrDocument(); - for( IndexableField f : doc.getFields() ) { + for( StorableField f : doc.getFields() ) { // Make sure multivalued fields are represented as lists Object existing = out.get(f.name()); if (existing == null) { @@ -299,10 +301,10 @@ public class RealTimeGetComponent extends SearchComponent List fields = doc.getFields(); // copy the stored fields only - Document out = new Document(); + StoredDocument out = new StoredDocument(); for (IndexableField f : doc.getFields()) { if (f.fieldType().stored()) { - out.add(f); + out.add((StorableField) f); } } diff --git a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java index 7527f7ba896..97d6588ab77 100644 --- a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java +++ b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java @@ -33,7 +33,9 @@ import org.apache.lucene.analysis.TokenFilter; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; import org.apache.lucene.document.Document; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.Query; import org.apache.lucene.search.highlight.*; import org.apache.lucene.search.vectorhighlight.BoundaryScanner; @@ -391,7 +393,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf DocIterator iterator = docs.iterator(); for (int i = 0; i < docs.size(); i++) { int docId = iterator.nextDoc(); - Document doc = searcher.doc(docId, fset); + StoredDocument doc = searcher.doc(docId, fset); NamedList docSummaries = new SimpleOrderedMap(); for (String fieldName : fieldNames) { fieldName = fieldName.trim(); @@ -423,7 +425,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf } private void doHighlightingByHighlighter( Query query, SolrQueryRequest req, NamedList docSummaries, - int docId, Document doc, String fieldName ) throws IOException { + int docId, StoredDocument doc, String fieldName ) throws IOException { final SolrIndexSearcher searcher = req.getSearcher(); final IndexSchema schema = searcher.getSchema(); @@ -438,9 +440,9 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf // END: Hack SolrParams params = req.getParams(); - IndexableField[] docFields = doc.getFields(fieldName); + StorableField[] docFields = doc.getFields(fieldName); List listFields = new ArrayList(); - for (IndexableField field : docFields) { + for (StorableField field : docFields) { listFields.add(field.stringValue()); } @@ -545,7 +547,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf } private void doHighlightingByFastVectorHighlighter( FastVectorHighlighter highlighter, FieldQuery fieldQuery, - SolrQueryRequest req, NamedList docSummaries, int docId, Document doc, + SolrQueryRequest req, NamedList docSummaries, int docId, StoredDocument doc, String fieldName ) throws IOException { SolrParams params = req.getParams(); SolrFragmentsBuilder solrFb = getSolrFragmentsBuilder( fieldName, params ); @@ -563,12 +565,12 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf alternateField( docSummaries, params, doc, fieldName ); } - private void alternateField( NamedList docSummaries, SolrParams params, Document doc, String fieldName ){ + private void alternateField( NamedList docSummaries, SolrParams params, StoredDocument doc, String fieldName ){ String alternateField = params.getFieldParam(fieldName, HighlightParams.ALTERNATE_FIELD); if (alternateField != null && alternateField.length() > 0) { - IndexableField[] docFields = doc.getFields(alternateField); + StorableField[] docFields = doc.getFields(alternateField); List listFields = new ArrayList(); - for (IndexableField field : docFields) { + for (StorableField field : docFields) { if (field.binaryValue() == null) listFields.add(field.stringValue()); } diff --git a/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java b/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java index 253548a715e..8415387a7ec 100755 --- a/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java @@ -20,7 +20,9 @@ import java.io.*; import java.util.*; import org.apache.lucene.document.Document; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.util.BytesRef; import org.apache.solr.common.SolrDocument; import org.apache.solr.common.params.CommonParams; @@ -90,7 +92,7 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter { if( o instanceof IndexableField ) { if(schema == null) schema = solrQueryRequest.getSchema(); - IndexableField f = (IndexableField)o; + StorableField f = (StorableField)o; SchemaField sf = schema.getFieldOrNull(f.name()); try { o = getValue(sf, f); @@ -138,7 +140,7 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter { context.iterator = ids.iterator(); for (int i = 0; i < sz; i++) { int id = context.iterator.nextDoc(); - Document doc = searcher.doc(id, fnames); + StoredDocument doc = searcher.doc(id, fnames); SolrDocument sdoc = getDoc(doc); if( transformer != null ) { transformer.transform(sdoc, id); @@ -168,9 +170,9 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter { writeResultsBody( ctx, codec ); } - public SolrDocument getDoc(Document doc) { + public SolrDocument getDoc(StoredDocument doc) { SolrDocument solrDoc = new SolrDocument(); - for (IndexableField f : doc) { + for (StorableField f : doc) { String fieldName = f.name(); if( !returnFields.wantsField(fieldName) ) continue; @@ -198,7 +200,7 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter { return solrDoc; } - public Object getValue(SchemaField sf, IndexableField f) throws Exception { + public Object getValue(SchemaField sf, StorableField f) throws Exception { FieldType ft = null; if(sf != null) ft =sf.getType(); diff --git a/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java b/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java index bb64aadf8d0..1b134ed0762 100644 --- a/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java @@ -22,7 +22,9 @@ import java.io.Writer; import java.util.*; import org.apache.lucene.document.Document; +import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.util.BytesRef; import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentList; @@ -123,8 +125,8 @@ public abstract class TextResponseWriter { } else if (val instanceof String) { writeStr(name, val.toString(), true); // micro-optimization... using toString() avoids a cast first - } else if (val instanceof IndexableField) { - IndexableField f = (IndexableField)val; + } else if (val instanceof StorableField) { + StorableField f = (StorableField)val; SchemaField sf = schema.getFieldOrNull( f.name() ); if( sf != null ) { sf.getType().write(this, name, f); @@ -155,8 +157,8 @@ public abstract class TextResponseWriter { writeBool(name, val.toString()); } else if (val instanceof Date) { writeDate(name,(Date)val); - } else if (val instanceof Document) { - SolrDocument doc = toSolrDocument( (Document)val ); + } else if (val instanceof StoredDocument) { + SolrDocument doc = toSolrDocument( (StoredDocument)val ); DocTransformer transformer = returnFields.getTransformer(); if( transformer != null ) { TransformContext context = new TransformContext(); @@ -224,10 +226,10 @@ public abstract class TextResponseWriter { writeEndDocumentList(); } - public final SolrDocument toSolrDocument( Document doc ) + public final SolrDocument toSolrDocument( StoredDocument doc ) { SolrDocument out = new SolrDocument(); - for( IndexableField f : doc) { + for( StorableField f : doc.getFields()) { // Make sure multivalued fields are represented as lists Object existing = out.get(f.name()); if (existing == null) { @@ -267,7 +269,7 @@ public abstract class TextResponseWriter { Set fnames = fields.getLuceneFieldNames(); for (int i=0; i document = new NamedList(); documents.add(document); - Document doc = retrieveDocument(uniqueField, scoreDoc.doc); + StoredDocument doc = retrieveDocument(uniqueField, scoreDoc.doc); document.add("id", uniqueField.getType().toExternal(doc.getField(uniqueField.getName()))); if (rb.getGroupingSpec().isNeedScore()) { document.add("score", scoreDoc.score); @@ -265,7 +266,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer= 0); // we should have found the document, or it's tombstone - Document doc = r.document(docid); + StoredDocument doc = r.document(docid); long foundVal = Long.parseLong(doc.get(field)); if (foundVal < Math.abs(val)) { verbose("ERROR: id",id,"model_val=",val," foundVal=",foundVal,"reader=",reader); From e7811cfa6c06bbc11bb712b451e7966ed81049b5 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Thu, 9 Aug 2012 10:01:56 +0000 Subject: [PATCH 05/13] LUCENE-3312: Apply patch lucene-3312-patch-09.patch git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1371131 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/solr/response/BinaryResponseWriter.java | 2 +- solr/core/src/java/org/apache/solr/schema/DateField.java | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java b/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java index 8415387a7ec..24e9f10876f 100755 --- a/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java @@ -89,7 +89,7 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter { writeResults(ctx, codec); return null; // null means we completely handled it } - if( o instanceof IndexableField ) { + if( o instanceof StorableField ) { if(schema == null) schema = solrQueryRequest.getSchema(); StorableField f = (StorableField)o; diff --git a/solr/core/src/java/org/apache/solr/schema/DateField.java b/solr/core/src/java/org/apache/solr/schema/DateField.java index 4e36e9d513f..2dc29303d63 100644 --- a/solr/core/src/java/org/apache/solr/schema/DateField.java +++ b/solr/core/src/java/org/apache/solr/schema/DateField.java @@ -445,10 +445,6 @@ public class DateField extends PrimitiveFieldType { minInclusive, maxInclusive); } - public String storedToIndexed(GeneralField f) { - return null; - } - } From 481c6d952d219841e90c6ba08e28d571796e790b Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Mon, 13 Aug 2012 14:06:05 +0000 Subject: [PATCH 06/13] LUCENE-3312: Apply lucene-3312-patch-12a.patch git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1372427 13f79535-47bb-0310-9956-ffa450edef68 --- .../analysis/uima/UIMABaseAnalyzerTest.java | 2 +- .../benchmark/byTask/feeds/DocMaker.java | 2 +- .../byTask/tasks/BenchmarkHighlighter.java | 2 +- .../benchmark/byTask/tasks/ReadTask.java | 2 +- .../byTask/tasks/ReadTokensTask.java | 3 +- .../tasks/SearchTravRetHighlightTask.java | 2 +- .../SearchTravRetLoadFieldSelectorTask.java | 2 +- .../SearchTravRetVectorHighlightTask.java | 2 +- .../byTask/tasks/WriteLineDocTask.java | 3 +- .../tasks/CountingHighlighterTestTask.java | 2 +- .../lucene/codecs/StoredFieldsWriter.java | 18 +--- .../lucene40/Lucene40StoredFieldsWriter.java | 2 +- .../org/apache/lucene/document/Document.java | 68 ++++++++++----- .../document/DocumentStoredFieldVisitor.java | 1 + .../apache/lucene/document/StoredField.java | 1 + .../org/apache/lucene/index/CheckIndex.java | 1 - .../org/apache/lucene/index/GeneralField.java | 16 ---- .../apache/lucene/index/IndexDocument.java | 4 + .../org/apache/lucene/index/IndexReader.java | 1 - .../java/org/apache/lucene/index/Norm.java | 6 +- .../PersistentSnapshotDeletionPolicy.java | 5 +- .../apache/lucene/index/StorableField.java | 22 +++-- .../{document => index}/StoredDocument.java | 86 ++++++------------- .../apache/lucene/search/IndexSearcher.java | 2 +- .../src/test/org/apache/lucene/TestDemo.java | 2 +- .../codecs/appending/TestAppendingCodec.java | 2 +- .../lucene/document/TestBinaryDocument.java | 1 + .../apache/lucene/document/TestDocument.java | 43 ++++++++-- .../apache/lucene/index/TestAddIndexes.java | 1 - .../index/TestBackwardsCompatibility.java | 1 - .../apache/lucene/index/TestCustomNorms.java | 1 - .../lucene/index/TestDirectoryReader.java | 1 - .../index/TestDirectoryReaderReopen.java | 1 - .../index/TestDocValuesTypeCompatibility.java | 17 ++-- .../lucene/index/TestDocumentWriter.java | 1 - .../lucene/index/TestDuelingCodecs.java | 1 - .../apache/lucene/index/TestFieldsReader.java | 1 - .../apache/lucene/index/TestIndexWriter.java | 1 - .../index/TestIndexWriterExceptions.java | 74 ++++++++-------- .../lucene/index/TestIndexWriterMerging.java | 1 - .../lucene/index/TestIndexWriterReader.java | 5 +- .../lucene/index/TestIndexWriterUnicode.java | 1 - .../lucene/index/TestIndexableField.java | 1 - .../org/apache/lucene/index/TestNorms.java | 1 - .../index/TestParallelAtomicReader.java | 1 - .../index/TestParallelCompositeReader.java | 1 - .../lucene/index/TestRandomStoredFields.java | 1 - .../lucene/index/TestRollingUpdates.java | 2 +- .../lucene/index/TestSegmentMerger.java | 1 - .../lucene/index/TestSegmentReader.java | 1 - .../lucene/index/TestStressIndexing2.java | 3 +- .../apache/lucene/index/TestStressNRT.java | 1 - .../search/TestBooleanMinShouldMatch.java | 2 +- .../apache/lucene/search/TestDateSort.java | 2 +- .../search/TestDisjunctionMaxQuery.java | 2 +- .../search/TestNumericRangeQuery32.java | 2 +- .../search/TestNumericRangeQuery64.java | 2 +- .../apache/lucene/search/TestPhraseQuery.java | 2 +- .../org/apache/lucene/search/TestSort.java | 2 +- .../search/spans/TestSpansAdvanced.java | 2 +- .../apache/lucene/store/TestRAMDirectory.java | 2 +- .../org/apache/lucene/demo/SearchFiles.java | 2 +- .../demo/xmlparser/FormBasedXmlQueryDemo.java | 2 +- .../lucene/search/grouping/TestGrouping.java | 2 +- .../lucene/search/highlight/TokenSources.java | 2 +- .../search/highlight/HighlighterTest.java | 2 +- .../apache/lucene/document/LazyDocument.java | 1 + .../index/TestMultiPassIndexSplitter.java | 1 - .../lucene/queries/mlt/MoreLikeThis.java | 2 +- .../complexPhrase/TestComplexPhraseQuery.java | 2 +- .../lucene/queryparser/xml/TestParser.java | 2 +- .../sandbox/queries/DuplicateFilterTest.java | 1 - .../queries/FuzzyLikeThisQueryTest.java | 2 +- .../lucene/spatial/SpatialStrategy.java | 4 +- .../lucene/spatial/bbox/BBoxStrategy.java | 4 +- .../spatial/prefix/PrefixTreeStrategy.java | 4 +- .../spatial/vector/TwoDoublesStrategy.java | 7 +- .../lucene/spatial/PortedSolr3Test.java | 2 +- .../apache/lucene/spatial/SpatialExample.java | 2 +- .../lucene/spatial/SpatialTestCase.java | 2 +- .../lucene/spatial/StrategyTestCase.java | 2 +- .../TestRecursivePrefixTreeStrategy.java | 2 +- .../TestTermQueryPrefixGridStrategy.java | 2 +- .../lucene/analysis/CollationTestBase.java | 2 +- .../org/apache/lucene/index/DocHelper.java | 1 - .../ThreadedIndexingAndSearchingTestCase.java | 1 - .../apache/solr/schema/ICUCollationField.java | 3 +- .../solr/handler/MoreLikeThisHandler.java | 2 +- .../handler/admin/LukeRequestHandler.java | 1 - .../component/RealTimeGetComponent.java | 3 +- .../highlight/DefaultSolrHighlighter.java | 2 +- .../solr/response/BinaryResponseWriter.java | 2 +- .../solr/response/TextResponseWriter.java | 2 +- .../org/apache/solr/schema/BCDIntField.java | 7 +- .../org/apache/solr/schema/BCDLongField.java | 4 +- .../org/apache/solr/schema/BCDStrField.java | 4 +- .../org/apache/solr/schema/BinaryField.java | 9 +- .../org/apache/solr/schema/BoolField.java | 7 +- .../org/apache/solr/schema/ByteField.java | 5 +- .../apache/solr/schema/CollationField.java | 3 +- .../org/apache/solr/schema/CurrencyField.java | 11 +-- .../org/apache/solr/schema/DateField.java | 9 +- .../org/apache/solr/schema/DoubleField.java | 5 +- .../apache/solr/schema/ExternalFileField.java | 3 +- .../org/apache/solr/schema/FieldType.java | 22 ++--- .../org/apache/solr/schema/FloatField.java | 5 +- .../org/apache/solr/schema/GeoHashField.java | 5 +- .../org/apache/solr/schema/IndexSchema.java | 2 +- .../java/org/apache/solr/schema/IntField.java | 5 +- .../org/apache/solr/schema/LatLonType.java | 9 +- .../org/apache/solr/schema/LongField.java | 5 +- .../org/apache/solr/schema/PointType.java | 9 +- .../apache/solr/schema/PreAnalyzedField.java | 9 +- .../apache/solr/schema/RandomSortField.java | 3 +- .../org/apache/solr/schema/SchemaField.java | 7 +- .../org/apache/solr/schema/ShortField.java | 5 +- .../solr/schema/SortableDoubleField.java | 7 +- .../solr/schema/SortableFloatField.java | 7 +- .../apache/solr/schema/SortableIntField.java | 7 +- .../apache/solr/schema/SortableLongField.java | 7 +- .../java/org/apache/solr/schema/StrField.java | 3 +- .../org/apache/solr/schema/TextField.java | 3 +- .../org/apache/solr/schema/TrieDateField.java | 13 +-- .../org/apache/solr/schema/TrieField.java | 15 ++-- .../org/apache/solr/schema/UUIDField.java | 5 +- .../java/org/apache/solr/search/Grouping.java | 3 +- .../apache/solr/search/SolrIndexSearcher.java | 1 - .../TopGroupsResultTransformer.java | 2 +- .../apache/solr/update/DocumentBuilder.java | 23 ++--- .../org/apache/solr/util/SolrPluginUtils.java | 2 +- .../apache/solr/BasicFunctionalityTest.java | 5 +- .../apache/solr/schema/CurrencyFieldTest.java | 3 +- .../org/apache/solr/schema/DateFieldTest.java | 3 +- .../org/apache/solr/schema/PolyFieldTest.java | 3 +- .../apache/solr/search/TestStressLucene.java | 2 +- 135 files changed, 398 insertions(+), 381 deletions(-) rename lucene/core/src/java/org/apache/lucene/{document => index}/StoredDocument.java (75%) diff --git a/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java b/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java index dbcf5905506..e51e5af8080 100644 --- a/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java +++ b/lucene/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java @@ -21,11 +21,11 @@ import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.TopDocs; diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java index f593d7afaed..1d0f233bba5 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/DocMaker.java @@ -226,7 +226,7 @@ public class DocMaker implements Closeable { final DocState ds = getDocState(); final Document doc = reuseFields ? ds.doc : new Document(); - doc.getFields().clear(); + doc.clear(); // Set ID_FIELD FieldType ft = new FieldType(valType); diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java index 91d59cddf38..d1a3abf5d00 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/BenchmarkHighlighter.java @@ -19,8 +19,8 @@ package org.apache.lucene.benchmark.byTask.tasks; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; /** * Abstract class for benchmarking highlighting performance diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java index 075934f7c2a..c768b98789e 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTask.java @@ -28,12 +28,12 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.benchmark.byTask.feeds.QueryMaker; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.MultiFields; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.search.Collector; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.MultiTermQuery; diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTokensTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTokensTask.java index 62b820589fb..2bdb080fdbb 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTokensTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/ReadTokensTask.java @@ -26,6 +26,7 @@ import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute; import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.benchmark.byTask.feeds.DocMaker; import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; import org.apache.lucene.document.IntField; import org.apache.lucene.document.LongField; import org.apache.lucene.document.FloatField; @@ -68,7 +69,7 @@ public class ReadTokensTask extends PerfTask { @Override public int doLogic() throws Exception { - List fields = doc.getFields(); + List fields = doc.getFields(); Analyzer analyzer = getRunData().getAnalyzer(); int tokenCount = 0; for(final IndexableField field : fields) { diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetHighlightTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetHighlightTask.java index 7cf3ac58dd9..8e3d87e57af 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetHighlightTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetHighlightTask.java @@ -21,8 +21,8 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.search.Query; import org.apache.lucene.search.highlight.Highlighter; import org.apache.lucene.search.highlight.QueryScorer; diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetLoadFieldSelectorTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetLoadFieldSelectorTask.java index 8962b1e1a8c..406e994685b 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetLoadFieldSelectorTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetLoadFieldSelectorTask.java @@ -24,8 +24,8 @@ import java.util.StringTokenizer; import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.document.Document; import org.apache.lucene.document.DocumentStoredFieldVisitor; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; /** * Search and Traverse and Retrieve docs task using a diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetVectorHighlightTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetVectorHighlightTask.java index 17d1413c81f..4993aff7134 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetVectorHighlightTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetVectorHighlightTask.java @@ -20,8 +20,8 @@ package org.apache.lucene.benchmark.byTask.tasks; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.search.Query; import org.apache.lucene.search.vectorhighlight.FastVectorHighlighter; import org.apache.lucene.search.vectorhighlight.FieldQuery; diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java index 05188d6e437..e4e5b51316a 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java @@ -33,6 +33,7 @@ import org.apache.lucene.benchmark.byTask.utils.Config; import org.apache.lucene.benchmark.byTask.utils.StreamUtils; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; /** * A task which writes documents, one line per document. Each line is in the @@ -172,7 +173,7 @@ public class WriteLineDocTask extends PerfTask { boolean sufficient = !checkSufficientFields; for (int i=0; i0 && sufficientFields[i]; diff --git a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingHighlighterTestTask.java b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingHighlighterTestTask.java index 63b6118c93b..3d5bb8a3116 100644 --- a/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingHighlighterTestTask.java +++ b/lucene/benchmark/src/test/org/apache/lucene/benchmark/byTask/tasks/CountingHighlighterTestTask.java @@ -27,8 +27,8 @@ import org.apache.lucene.search.highlight.QueryScorer; import org.apache.lucene.search.highlight.TokenSources; import org.apache.lucene.search.Query; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; import java.io.IOException; diff --git a/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java index cb55a414fa5..2b360c80a23 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java @@ -1,17 +1,5 @@ package org.apache.lucene.codecs; -import java.io.Closeable; -import java.io.IOException; - -import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; -import org.apache.lucene.index.FieldInfo; -import org.apache.lucene.index.FieldInfos; -import org.apache.lucene.index.IndexableField; -import org.apache.lucene.index.MergeState; -import org.apache.lucene.index.StorableField; -import org.apache.lucene.util.Bits; - /** * Copyright 2004 The Apache Software Foundation * @@ -31,13 +19,13 @@ import org.apache.lucene.util.Bits; import java.io.Closeable; import java.io.IOException; -import org.apache.lucene.document.Document; -import org.apache.lucene.index.AtomicReader; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.MergeState; +import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.util.Bits; +import org.apache.lucene.index.AtomicReader; /** * Codec API for writing stored fields: diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java index 2d33fe8a0a3..27435c697ab 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40StoredFieldsWriter.java @@ -22,7 +22,6 @@ import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.codecs.StoredFieldsReader; import org.apache.lucene.codecs.StoredFieldsWriter; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.AtomicReader; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; @@ -31,6 +30,7 @@ import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.MergeState; import org.apache.lucene.index.SegmentReader; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; diff --git a/lucene/core/src/java/org/apache/lucene/document/Document.java b/lucene/core/src/java/org/apache/lucene/document/Document.java index fc42ddf7b9d..60673493840 100644 --- a/lucene/core/src/java/org/apache/lucene/document/Document.java +++ b/lucene/core/src/java/org/apache/lucene/document/Document.java @@ -23,6 +23,7 @@ import org.apache.lucene.index.IndexDocument; import org.apache.lucene.index.IndexReader; // for javadoc import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.search.IndexSearcher; // for javadoc import org.apache.lucene.search.ScoreDoc; // for javadoc import org.apache.lucene.util.BytesRef; @@ -50,6 +51,30 @@ public final class Document implements IndexDocument{ /** Constructs a new document with no fields. */ public Document() {} + + /** + * Creates a Document from StoredDocument so it that can be used e.g. for another + * round of indexing. + * + * @return a new instance of Document representation of this StoredDocument + */ + public Document(StoredDocument storedDoc) { + for (StorableField field : storedDoc.getFields()) { + Field newField = new Field(field.name(), (FieldType) field.fieldType()); + + newField.fieldsData = field.stringValue(); + if (newField.fieldsData == null) + newField.fieldsData = field.numericValue(); + if (newField.fieldsData == null) + newField.fieldsData = field.binaryValue(); + if (newField.fieldsData == null) + newField.fieldsData = field.readerValue(); + + add(newField); + } + } + + /** *

    Adds a field to a document. Several fields may be added with * the same name. In this case, if the fields are indexed, their text is @@ -64,14 +89,6 @@ public final class Document implements IndexDocument{ fields.add(field); } - public final void add(IndexableField field) { - fields.add((Field) field); - } - - public final void add(StorableField field) { - fields.add((Field) field); - } - /** *

    Removes field with the specified name from the document. * If multiple fields exist with this name, this method removes the first field that has been added. @@ -167,8 +184,8 @@ public final class Document implements IndexDocument{ * null. If multiple fields exists with this name, this method returns the * first value added. */ - public final IndexableField getField(String name) { - for (IndexableField field : fields) { + public final Field getField(String name) { + for (Field field : fields) { if (field.name().equals(name)) { return field; } @@ -184,15 +201,15 @@ public final class Document implements IndexDocument{ * @param name the name of the field * @return a Fieldable[] array */ - public IndexableField[] getFields(String name) { - List result = new ArrayList(); - for (IndexableField field : fields) { + public Field[] getFields(String name) { + List result = new ArrayList(); + for (Field field : fields) { if (field.name().equals(name)) { result.add(field); } } - return result.toArray(new IndexableField[result.size()]); + return result.toArray(new Field[result.size()]); } /** Returns a List of all the fields in a document. @@ -200,14 +217,11 @@ public final class Document implements IndexDocument{ * not available in documents retrieved from the * index, e.g. {@link IndexSearcher#doc(int)} or {@link * IndexReader#document(int)}. + * + * @return an immutable List[Field] */ - public final List getFields() { - List result = new ArrayList(); - for (IndexableField field : fields) { - result.add(field); - } - - return result; + public final List getFields() { + return Collections.unmodifiableList(fields); } private final static String[] NO_STRINGS = new String[0]; @@ -275,6 +289,7 @@ public final class Document implements IndexDocument{ return buffer.toString(); } + /** Obtains all indexed fields in document */ @Override public Iterable indexableFields() { Iterator it = indexedFieldsIterator(); @@ -287,6 +302,8 @@ public final class Document implements IndexDocument{ return result; } + + /** Obtains all stored fields in document. */ @Override public Iterable storableFields() { Iterator it = storedFieldsIterator(); @@ -299,7 +316,7 @@ public final class Document implements IndexDocument{ return result; } - public Iterator storedFieldsIterator() { + private Iterator storedFieldsIterator() { return new FilterIterator(fields.iterator()) { @Override protected boolean predicateFunction(Field field) { @@ -308,7 +325,7 @@ public final class Document implements IndexDocument{ }; } - public Iterator indexedFieldsIterator() { + private Iterator indexedFieldsIterator() { return new FilterIterator(fields.iterator()) { @Override protected boolean predicateFunction(Field field) { @@ -316,4 +333,9 @@ public final class Document implements IndexDocument{ } }; } + + /** Removes all the fields from document. */ + public void clear() { + fields.clear(); + } } 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 c7ecc4e562c..fab981190d1 100644 --- a/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java +++ b/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java @@ -23,6 +23,7 @@ import java.util.HashSet; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.StoredFieldVisitor; /** A {@link StoredFieldVisitor} that creates a {@link diff --git a/lucene/core/src/java/org/apache/lucene/document/StoredField.java b/lucene/core/src/java/org/apache/lucene/document/StoredField.java index 1da116930e9..4e340fd584f 100644 --- a/lucene/core/src/java/org/apache/lucene/document/StoredField.java +++ b/lucene/core/src/java/org/apache/lucene/document/StoredField.java @@ -1,6 +1,7 @@ package org.apache.lucene.document; import org.apache.lucene.index.IndexReader; // javadocs +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.IndexSearcher; // javadocs import org.apache.lucene.util.BytesRef; diff --git a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java index 69fbeda2673..c4dd38b5ce6 100644 --- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java +++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java @@ -32,7 +32,6 @@ import org.apache.lucene.codecs.BlockTreeTermsReader; import org.apache.lucene.codecs.Codec; import org.apache.lucene.document.Document; import org.apache.lucene.document.FieldType; // for javadocs -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DocValues.SortedSource; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.FieldInfo.IndexOptions; diff --git a/lucene/core/src/java/org/apache/lucene/index/GeneralField.java b/lucene/core/src/java/org/apache/lucene/index/GeneralField.java index e1a203d8bc6..f436c013250 100644 --- a/lucene/core/src/java/org/apache/lucene/index/GeneralField.java +++ b/lucene/core/src/java/org/apache/lucene/index/GeneralField.java @@ -1,9 +1,5 @@ package org.apache.lucene.index; -import java.io.Reader; - -import org.apache.lucene.util.BytesRef; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -29,16 +25,4 @@ public interface GeneralField { /** {@link IndexableFieldType} describing the properties * of this field. */ public IndexableFieldType fieldType(); - - /** Non-null if this field has a binary value */ - public BytesRef binaryValue(); - - /** Non-null if this field has a string value */ - public String stringValue(); - - /** Non-null if this field has a Reader value */ - public Reader readerValue(); - - /** Non-null if this field has a numeric value */ - public Number numericValue(); } diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java b/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java index 016a45706a3..8ae36aee91c 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java @@ -21,6 +21,10 @@ package org.apache.lucene.index; * @lucene.internal */ public interface IndexDocument { + + /** Obtains all indexable fields in document */ public Iterable indexableFields(); + + /** Obtains all storable fields in document */ public Iterable storableFields(); } diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexReader.java b/lucene/core/src/java/org/apache/lucene/index/IndexReader.java index 9c4624a7dbb..44e60faf8b7 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexReader.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexReader.java @@ -27,7 +27,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.document.Document; import org.apache.lucene.document.DocumentStoredFieldVisitor; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.search.SearcherManager; // javadocs import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.util.Bits; diff --git a/lucene/core/src/java/org/apache/lucene/index/Norm.java b/lucene/core/src/java/org/apache/lucene/index/Norm.java index 2e668a00eeb..8baecffa124 100644 --- a/lucene/core/src/java/org/apache/lucene/index/Norm.java +++ b/lucene/core/src/java/org/apache/lucene/index/Norm.java @@ -33,7 +33,7 @@ import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.util.BytesRef; /** - * Stores the normalization value computed in + * Stores the normalization value with {@link StorableField} computed in * {@link Similarity#computeNorm(FieldInvertState, Norm)} per field. * Normalization values must be consistent within a single field, different * value types are not permitted within a single field. All values set must be @@ -48,9 +48,9 @@ public final class Norm { private BytesRef spare; /** - * Returns the {@link IndexableField} representation for this norm + * Returns the {@link StorableField} representation for this norm */ - public StoredField field() { + public StorableField field() { return field; } diff --git a/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java b/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java index 24cdfd6a76f..6ce2d6f11c9 100644 --- a/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java +++ b/lucene/core/src/java/org/apache/lucene/index/PersistentSnapshotDeletionPolicy.java @@ -26,7 +26,6 @@ import java.util.Map.Entry; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StoredField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.store.Directory; @@ -73,9 +72,9 @@ public class PersistentSnapshotDeletionPolicy extends SnapshotDeletionPolicy { if (doc.getField(SNAPSHOTS_ID) == null) { throw new IllegalStateException("directory is not a valid snapshots store!"); } - doc.removeField(SNAPSHOTS_ID); for (StorableField f : doc) { - snapshots.put(f.name(), f.stringValue()); + if (!f.name().equals(SNAPSHOTS_ID)) + snapshots.put(f.name(), f.stringValue()); } } else if (numDocs != 0) { throw new IllegalStateException( diff --git a/lucene/core/src/java/org/apache/lucene/index/StorableField.java b/lucene/core/src/java/org/apache/lucene/index/StorableField.java index ed9621eb041..4ddb31abfb5 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StorableField.java +++ b/lucene/core/src/java/org/apache/lucene/index/StorableField.java @@ -1,10 +1,5 @@ package org.apache.lucene.index; -import java.io.Reader; - -import org.apache.lucene.document.FieldType; -import org.apache.lucene.util.BytesRef; - /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -22,6 +17,21 @@ import org.apache.lucene.util.BytesRef; * limitations under the License. */ +import java.io.Reader; + +import org.apache.lucene.util.BytesRef; + public interface StorableField extends GeneralField { - + + /** Non-null if this field has a binary value */ + public BytesRef binaryValue(); + + /** Non-null if this field has a string value */ + public String stringValue(); + + /** Non-null if this field has a Reader value */ + public Reader readerValue(); + + /** Non-null if this field has a numeric value */ + public Number numericValue(); } diff --git a/lucene/core/src/java/org/apache/lucene/document/StoredDocument.java b/lucene/core/src/java/org/apache/lucene/index/StoredDocument.java similarity index 75% rename from lucene/core/src/java/org/apache/lucene/document/StoredDocument.java rename to lucene/core/src/java/org/apache/lucene/index/StoredDocument.java index 563ea2a8219..345c5d9edbe 100644 --- a/lucene/core/src/java/org/apache/lucene/document/StoredDocument.java +++ b/lucene/core/src/java/org/apache/lucene/index/StoredDocument.java @@ -1,12 +1,4 @@ -package org.apache.lucene.document; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.lucene.index.IndexableField; -import org.apache.lucene.index.StorableField; -import org.apache.lucene.util.BytesRef; +package org.apache.lucene.index; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -25,6 +17,21 @@ import org.apache.lucene.util.BytesRef; * limitations under the License. */ +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.apache.lucene.document.Document; +import org.apache.lucene.document.DoubleField; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.FloatField; +import org.apache.lucene.document.IntField; +import org.apache.lucene.document.LongField; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.util.BytesRef; + public class StoredDocument implements Iterable{ private final List fields = new ArrayList(); @@ -45,6 +52,10 @@ public class StoredDocument implements Iterable{ return result.toArray(new StorableField[result.size()]); } + /** Returns a field with the given name if any exist in this document, or + * null. If multiple fields exists with this name, this method returns the + * first value added. + */ public final StorableField getField(String name) { for (StorableField field : fields) { if (field.name().equals(name)) { @@ -54,36 +65,15 @@ public class StoredDocument implements Iterable{ return null; } - public final void removeField(String name) { - Iterator it = fields.iterator(); - while (it.hasNext()) { - StorableField field = it.next(); - if (field.name().equals(name)) { - it.remove(); - return; - } - } - } - - /** - *

    Removes all fields with the given name from the document. - * If there is no field with the specified name, the document remains unchanged.

    - *

    Note that the removeField(s) methods like the add method only make sense - * prior to adding a document to an index. These methods cannot - * be used to change the content of an existing index! In order to achieve this, - * a document has to be deleted from an index and a new changed version of that - * document has to be added.

    + + /** Returns a List of all the fields in a document. + *

    Note that fields which are not stored are + * not available in documents retrieved from the + * index, e.g. {@link IndexSearcher#doc(int)} or {@link + * IndexReader#document(int)}. + * + * @return an immutable List[StorableField] */ - public final void removeFields(String name) { - Iterator it = fields.iterator(); - while (it.hasNext()) { - StorableField field = it.next(); - if (field.name().equals(name)) { - it.remove(); - } - } - } - public final List getFields() { return fields; } @@ -180,26 +170,6 @@ public class StoredDocument implements Iterable{ return null; } - public Document asIndexable() { - Document doc = new Document(); - - for (StorableField field : fields) { - Field newField = new Field(field.name(), (FieldType) field.fieldType()); - - newField.fieldsData = field.stringValue(); - if (newField.fieldsData == null) - newField.fieldsData = field.numericValue(); - if (newField.fieldsData == null) - newField.fieldsData = field.binaryValue(); - if (newField.fieldsData == null) - newField.fieldsData = field.readerValue(); - - doc.add(newField); - } - - return doc; - } - /** Prints the fields of a document for human consumption. */ @Override public final String toString() { diff --git a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java index 6a65a2b6ed5..57199c91cb1 100644 --- a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java +++ b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java @@ -33,13 +33,13 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.DirectoryReader; // javadocs import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.MultiFields; import org.apache.lucene.index.IndexReaderContext; import org.apache.lucene.index.ReaderUtil; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.StoredFieldVisitor; import org.apache.lucene.index.Term; import org.apache.lucene.index.TermContext; diff --git a/lucene/core/src/test/org/apache/lucene/TestDemo.java b/lucene/core/src/test/org/apache/lucene/TestDemo.java index 8d532041754..717b753618a 100644 --- a/lucene/core/src/test/org/apache/lucene/TestDemo.java +++ b/lucene/core/src/test/org/apache/lucene/TestDemo.java @@ -23,9 +23,9 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.search.*; diff --git a/lucene/core/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java b/lucene/core/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java index bd25164bcae..d5ccd2e5517 100644 --- a/lucene/core/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java +++ b/lucene/core/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java @@ -24,7 +24,6 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.codecs.appending.AppendingCodec; import org.apache.lucene.document.Document; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DocsEnum; @@ -33,6 +32,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.MultiFields; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum.SeekStatus; import org.apache.lucene.index.TermsEnum; diff --git a/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java b/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java index 6a179866b61..c001f82306b 100644 --- a/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java +++ b/lucene/core/src/test/org/apache/lucene/document/TestBinaryDocument.java @@ -3,6 +3,7 @@ package org.apache.lucene.document; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; diff --git a/lucene/core/src/test/org/apache/lucene/document/TestDocument.java b/lucene/core/src/test/org/apache/lucene/document/TestDocument.java index 672b961d82d..07d035f1221 100644 --- a/lucene/core/src/test/org/apache/lucene/document/TestDocument.java +++ b/lucene/core/src/test/org/apache/lucene/document/TestDocument.java @@ -18,6 +18,7 @@ package org.apache.lucene.document; */ import java.io.StringReader; +import java.util.List; import org.apache.lucene.analysis.EmptyTokenizer; import org.apache.lucene.analysis.MockAnalyzer; @@ -27,6 +28,8 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; @@ -124,7 +127,7 @@ public class TestDocument extends LuceneTestCase { // siltenlty ignored assertEquals(0, doc.getFields().size()); } - + public void testConstructorExceptions() { FieldType ft = new FieldType(); ft.setStored(true); @@ -147,6 +150,34 @@ public class TestDocument extends LuceneTestCase { // expected exception } } + + public void testClearDocument() { + Document doc = makeDocumentWithFields(); + assertEquals(8, doc.getFields().size()); + doc.clear(); + assertEquals(0, doc.getFields().size()); + } + + public void testGetFieldsImmutable() { + Document doc = makeDocumentWithFields(); + assertEquals(8, doc.getFields().size()); + List fields = doc.getFields(); + try { + fields.add( new StringField("name", "value", Field.Store.NO) ); + fail("Document.getFields() should return immutable List"); + } + catch (UnsupportedOperationException e) { + // OK + } + + try { + fields.clear(); + fail("Document.getFields() should return immutable List"); + } + catch (UnsupportedOperationException e) { + // OK + } + } /** * Tests {@link Document#getValues(String)} method for a brand new Document @@ -215,13 +246,13 @@ public class TestDocument extends LuceneTestCase { } private void doAssert(StoredDocument doc) { - doAssert(doc.asIndexable(), true); + doAssert(new Document(doc), true); } private void doAssert(Document doc, boolean fromIndex) { - IndexableField[] keywordFieldValues = doc.getFields("keyword"); - IndexableField[] textFieldValues = doc.getFields("text"); - IndexableField[] unindexedFieldValues = doc.getFields("unindexed"); - IndexableField[] unstoredFieldValues = doc.getFields("unstored"); + StorableField[] keywordFieldValues = doc.getFields("keyword"); + StorableField[] textFieldValues = doc.getFields("text"); + StorableField[] unindexedFieldValues = doc.getFields("unindexed"); + StorableField[] unstoredFieldValues = doc.getFields("unstored"); assertTrue(keywordFieldValues.length == 2); assertTrue(textFieldValues.length == 2); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java index a24b51c467b..c8f4e762138 100755 --- a/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestAddIndexes.java @@ -45,7 +45,6 @@ import org.apache.lucene.codecs.pulsing.Pulsing40PostingsFormat; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java index 78f96dd537c..ac246e93ac0 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java @@ -43,7 +43,6 @@ import org.apache.lucene.document.LongField; import org.apache.lucene.document.PackedLongDocValuesField; import org.apache.lucene.document.ShortDocValuesField; import org.apache.lucene.document.SortedBytesDocValuesField; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StraightBytesDocValuesField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCustomNorms.java b/lucene/core/src/test/org/apache/lucene/index/TestCustomNorms.java index 99faa5292f4..8c22a80135e 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestCustomNorms.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestCustomNorms.java @@ -22,7 +22,6 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java index 5c0f6cc57ca..db7ca3393fc 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReader.java @@ -32,7 +32,6 @@ import org.apache.lucene.codecs.lucene40.Lucene40PostingsFormat; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java index a76a0a7bbb4..259f316a524 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDirectoryReaderReopen.java @@ -32,7 +32,6 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.search.IndexSearcher; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesTypeCompatibility.java b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesTypeCompatibility.java index 618e05780f8..cdba1c2da4f 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesTypeCompatibility.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesTypeCompatibility.java @@ -24,6 +24,7 @@ import org.apache.lucene.document.ByteDocValuesField; import org.apache.lucene.document.DerefBytesDocValuesField; import org.apache.lucene.document.Document; import org.apache.lucene.document.DoubleDocValuesField; +import org.apache.lucene.document.Field; import org.apache.lucene.document.FloatDocValuesField; import org.apache.lucene.document.IntDocValuesField; import org.apache.lucene.document.LongDocValuesField; @@ -67,7 +68,7 @@ public class TestDocValuesTypeCompatibility extends LuceneTestCase { } @SuppressWarnings("fallthrough") - public IndexableField getRandomIntsField(Type maxType, boolean force) { + public Field getRandomIntsField(Type maxType, boolean force) { switch (maxType) { case VAR_INTS: @@ -120,7 +121,7 @@ public class TestDocValuesTypeCompatibility extends LuceneTestCase { } @SuppressWarnings("fallthrough") - public IndexableField getRandomFloatField(Type maxType, boolean force) { + public Field getRandomFloatField(Type maxType, boolean force) { switch (maxType) { case FLOAT_64: @@ -161,7 +162,7 @@ public class TestDocValuesTypeCompatibility extends LuceneTestCase { iwc.setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH); iwc.setRAMPerThreadHardLimitMB(2000); IndexWriter writer = new IndexWriter(dir, iwc); - IndexableField[] fields = new IndexableField[] { + Field[] fields = new Field[] { new DoubleDocValuesField("f", 1.0), new IntDocValuesField("f", 1), new ShortDocValuesField("f", (short) 1), new ByteDocValuesField("f", (byte) 1)}; @@ -194,7 +195,7 @@ public class TestDocValuesTypeCompatibility extends LuceneTestCase { IndexWriter writer = new IndexWriter(dir, iwc); boolean mustBeFixed = random().nextBoolean(); int maxSize = 2 + random().nextInt(15); - IndexableField bytesField = getRandomBytesField(mustBeFixed, maxSize, + Field bytesField = getRandomBytesField(mustBeFixed, maxSize, true); addDoc(writer, bytesField); for (int j = 0; j < numDocs; j++) { @@ -207,7 +208,7 @@ public class TestDocValuesTypeCompatibility extends LuceneTestCase { } } - public IndexableField getRandomBytesField(boolean mustBeFixed, int maxSize, + public Field getRandomBytesField(boolean mustBeFixed, int maxSize, boolean mustBeVariableIfNotFixed) { int size = mustBeFixed ? maxSize : random().nextInt(maxSize) + 1; StringBuilder s = new StringBuilder(); @@ -256,16 +257,16 @@ public class TestDocValuesTypeCompatibility extends LuceneTestCase { dir.close(); } - private void addDoc(IndexWriter writer, IndexableField... fields) + private void addDoc(IndexWriter writer, Field... fields) throws IOException { Document doc = new Document(); - for (IndexableField indexableField : fields) { + for (Field indexableField : fields) { doc.add(indexableField); } writer.addDocument(doc); } - public IndexableField getRandomIndexableDVField() { + public Field getRandomIndexableDVField() { int size = random().nextInt(100) + 1; StringBuilder s = new StringBuilder(); for (int i = 0; i < size; i++) { diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java index c6ae00af85d..4d947c6bf3b 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java @@ -27,7 +27,6 @@ import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.FieldInfo.IndexOptions; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java b/lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java index 4e35aac6e9c..41e031c86af 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java @@ -31,7 +31,6 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.codecs.Codec; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.TermsEnum.SeekStatus; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.store.Directory; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java b/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java index cc0956bd9dd..318e95cd76c 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestFieldsReader.java @@ -31,7 +31,6 @@ import org.apache.lucene.document.FieldType; import org.apache.lucene.document.FloatField; import org.apache.lucene.document.IntField; import org.apache.lucene.document.LongField; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StringField; import org.apache.lucene.index.FieldInfo.IndexOptions; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java index de4beb42b3a..44faf807d89 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -34,7 +34,6 @@ import org.apache.lucene.codecs.simpletext.SimpleTextCodec; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java index 8e2836047ce..949efc29955 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java @@ -1556,50 +1556,46 @@ public class TestIndexWriterExceptions extends LuceneTestCase { try { doc = new Document(); // try to boost with norms omitted - List list = new ArrayList(); - list.add(new IndexableField() { - + IndexDocument docList = new IndexDocument() { + + List list = new ArrayList(); + List storedList = new ArrayList(); + @Override - public String name() { - return "foo"; + public Iterable indexableFields() { + if (list.size() == 0) { + list.add(new IndexableField() { + @Override + public String name() { + return "foo"; + } + + @Override + public IndexableFieldType fieldType() { + return StringField.TYPE_NOT_STORED; + } + + @Override + public float boost() { + return 5f; + } + + @Override + public TokenStream tokenStream(Analyzer analyzer) throws IOException { + return null; + } + }); + } + return list; } @Override - public IndexableFieldType fieldType() { - return StringField.TYPE_NOT_STORED; + public Iterable storableFields() { + return storedList; } - - @Override - public float boost() { - return 5f; - } - - @Override - public BytesRef binaryValue() { - return null; - } - - @Override - public String stringValue() { - return "baz"; - } - - @Override - public Reader readerValue() { - return null; - } - - @Override - public Number numericValue() { - return null; - } - - @Override - public TokenStream tokenStream(Analyzer analyzer) throws IOException { - return null; - } - }); - iw.addDocument(list); + + }; + iw.addDocument(docList); fail("didn't get any exception, boost silently discarded"); } catch (UnsupportedOperationException expected) { // expected diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMerging.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMerging.java index 1ab0190f2c0..5e87625ad39 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMerging.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMerging.java @@ -21,7 +21,6 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.util.LuceneTestCase; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java index c1f675a10bd..43c31f4bef4 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java @@ -28,7 +28,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexSearcher; @@ -142,10 +141,10 @@ public class TestIndexWriterReader extends LuceneTestCase { String id10 = r1.document(10).getField("id").stringValue(); - StoredDocument newDoc = r1.document(10); + Document newDoc = new Document(r1.document(10)); newDoc.removeField("id"); newDoc.add(newStringField("id", Integer.toString(8000), Field.Store.YES)); - writer.updateDocument(new Term("id", id10), newDoc.asIndexable()); + writer.updateDocument(new Term("id", id10), newDoc); assertFalse(r1.isCurrent()); DirectoryReader r2 = writer.getReader(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java index 6ff458190f3..68b52a533b1 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterUnicode.java @@ -26,7 +26,6 @@ import java.util.Set; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRef; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexableField.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexableField.java index 1e52c8d4d7c..420f23bb90d 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexableField.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexableField.java @@ -25,7 +25,6 @@ import java.util.Iterator; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestNorms.java b/lucene/core/src/test/org/apache/lucene/index/TestNorms.java index 3a28bf0cdaa..368f5c2c8cd 100755 --- a/lucene/core/src/test/org/apache/lucene/index/TestNorms.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestNorms.java @@ -23,7 +23,6 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestParallelAtomicReader.java b/lucene/core/src/test/org/apache/lucene/index/TestParallelAtomicReader.java index 58d061b29a9..bfeb3321d0f 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestParallelAtomicReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestParallelAtomicReader.java @@ -23,7 +23,6 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestParallelCompositeReader.java b/lucene/core/src/test/org/apache/lucene/index/TestParallelCompositeReader.java index 994fd2a7560..aa29f6dd09c 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestParallelCompositeReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestParallelCompositeReader.java @@ -23,7 +23,6 @@ import java.util.Random; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestRandomStoredFields.java b/lucene/core/src/test/org/apache/lucene/index/TestRandomStoredFields.java index af3a0f5c36e..9247d413650 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestRandomStoredFields.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestRandomStoredFields.java @@ -29,7 +29,6 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.TermQuery; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java b/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java index 4376db45d57..d4607dd0a7d 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestRollingUpdates.java @@ -69,7 +69,7 @@ public class TestRollingUpdates extends LuceneTestCase { if (VERBOSE) { System.out.println(" docIter=" + docIter + " id=" + id); } - ((Field) doc.getField("docid")).setStringValue(myID); + doc.getField("docid").setStringValue(myID); Term idTerm = new Term("docid", myID); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java b/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java index f78b4eae481..63d8219901f 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java @@ -21,7 +21,6 @@ import java.io.IOException; import org.apache.lucene.codecs.Codec; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSegmentReader.java b/lucene/core/src/test/org/apache/lucene/index/TestSegmentReader.java index 03ec8699c2f..96b7084c5bb 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestSegmentReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestSegmentReader.java @@ -23,7 +23,6 @@ import java.util.HashSet; import java.util.List; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; diff --git a/lucene/core/src/test/org/apache/lucene/index/TestStressIndexing2.java b/lucene/core/src/test/org/apache/lucene/index/TestStressIndexing2.java index 291ed55f3a8..1585e995eb2 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestStressIndexing2.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestStressIndexing2.java @@ -32,7 +32,6 @@ import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.search.DocIdSetIterator; @@ -251,7 +250,7 @@ public class TestStressIndexing2 extends LuceneTestCase { Iterator iter = docs.values().iterator(); while (iter.hasNext()) { Document d = iter.next(); - ArrayList fields = new ArrayList(); + ArrayList fields = new ArrayList(); fields.addAll(d.getFields()); // put fields in same order each time Collections.sort(fields, fieldNameComparator); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestStressNRT.java b/lucene/core/src/test/org/apache/lucene/index/TestStressNRT.java index 94d12e2c56f..2441dfa4bd4 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestStressNRT.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestStressNRT.java @@ -30,7 +30,6 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java index 8c9f97ecda8..7d8a5edf6aa 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanMinShouldMatch.java @@ -18,11 +18,11 @@ package org.apache.lucene.search; */ import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.junit.AfterClass; diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDateSort.java b/lucene/core/src/test/org/apache/lucene/search/TestDateSort.java index 89f0a1df338..42d08c0045f 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestDateSort.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestDateSort.java @@ -25,9 +25,9 @@ import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.document.DateTools; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.store.Directory; /** diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java index 45e4ba08d78..0a29c6e3436 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java @@ -22,7 +22,6 @@ import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.IndexReader; @@ -30,6 +29,7 @@ import org.apache.lucene.index.Norm; import org.apache.lucene.index.SlowCompositeReaderWrapper; import org.apache.lucene.index.FieldInvertState; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.search.similarities.DefaultSimilarity; import org.apache.lucene.search.similarities.Similarity; diff --git a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java index 93e655d241f..663208b04f6 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java @@ -23,13 +23,13 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.FloatField; import org.apache.lucene.document.IntField; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.MultiFields; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.SlowCompositeReaderWrapper; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.store.Directory; diff --git a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java index 59245fa43ee..1db2f80e5c2 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java @@ -23,13 +23,13 @@ import org.apache.lucene.document.DoubleField; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.LongField; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.MultiFields; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.SlowCompositeReaderWrapper; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.store.Directory; diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java index f59e3dee570..c40e99d4d46 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestPhraseQuery.java @@ -74,7 +74,7 @@ public class TestPhraseQuery extends LuceneTestCase { Document doc = new Document(); doc.add(newTextField("field", "one two three four five", Field.Store.YES)); doc.add(newTextField("repeated", "this is a repeated field - first part", Field.Store.YES)); - IndexableField repeatedField = newTextField("repeated", "second part of a repeated field", Field.Store.YES); + Field repeatedField = newTextField("repeated", "second part of a repeated field", Field.Store.YES); doc.add(repeatedField); doc.add(newTextField("palindrome", "one two three two one", Field.Store.YES)); writer.addDocument(doc); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSort.java b/lucene/core/src/test/org/apache/lucene/search/TestSort.java index 392ccedc8c7..ddfd093b370 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSort.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSort.java @@ -38,7 +38,6 @@ import org.apache.lucene.document.FieldType; import org.apache.lucene.document.FloatDocValuesField; import org.apache.lucene.document.PackedLongDocValuesField; import org.apache.lucene.document.SortedBytesDocValuesField; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StraightBytesDocValuesField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; @@ -52,6 +51,7 @@ import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.MultiReader; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.FieldValueHitQueue.Entry; diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java index 5dc0bb968ac..1431422c3af 100644 --- a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java +++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpansAdvanced.java @@ -20,7 +20,6 @@ package org.apache.lucene.search.spans; import java.io.IOException; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.analysis.MockAnalyzer; @@ -29,6 +28,7 @@ import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.search.*; import org.apache.lucene.search.similarities.DefaultSimilarity; diff --git a/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java index 1fd9a6e194f..82cd9eebf46 100644 --- a/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java +++ b/lucene/core/src/test/org/apache/lucene/store/TestRAMDirectory.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.IOException; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util._TestUtil; import org.apache.lucene.analysis.MockAnalyzer; @@ -30,6 +29,7 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.util.English; diff --git a/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.java b/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.java index b2e5dad293b..6d85687fb56 100644 --- a/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.java +++ b/lucene/demo/src/java/org/apache/lucene/demo/SearchFiles.java @@ -27,9 +27,9 @@ import java.util.Date; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; diff --git a/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.java b/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.java index fa8fd935a0a..9f437b3ff18 100644 --- a/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.java +++ b/lucene/demo/src/java/org/apache/lucene/demo/xmlparser/FormBasedXmlQueryDemo.java @@ -36,12 +36,12 @@ import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.queryparser.xml.CorePlusExtensionsParser; import org.apache.lucene.queryparser.xml.QueryTemplateManager; import org.apache.lucene.search.IndexSearcher; diff --git a/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java b/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java index 9a41ff3f89e..495f30ced00 100644 --- a/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java +++ b/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java @@ -594,7 +594,7 @@ public class TestGrouping extends LuceneTestCase { Document doc = new Document(); docs.add(doc); if (groupValue.group != null) { - doc.add(newStringField("group", groupValue.group.utf8ToString(), Field.Store.NO)); + doc.add(newStringField("group", groupValue.group.utf8ToString(), Field.Store.YES)); } doc.add(newStringField("sort1", groupValue.sort1.utf8ToString(), Field.Store.NO)); doc.add(newStringField("sort2", groupValue.sort2.utf8ToString(), Field.Store.NO)); diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java b/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java index 05b4716934b..ddb6b92225d 100644 --- a/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java +++ b/lucene/highlighter/src/java/org/apache/lucene/search/highlight/TokenSources.java @@ -32,10 +32,10 @@ import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DocsAndPositionsEnum; import org.apache.lucene.index.Fields; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.search.DocIdSetIterator; diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java index 78057db2a55..3677573a92a 100644 --- a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java +++ b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java @@ -37,12 +37,12 @@ import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.IntField; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StoredField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.Term; diff --git a/lucene/misc/src/java/org/apache/lucene/document/LazyDocument.java b/lucene/misc/src/java/org/apache/lucene/document/LazyDocument.java index b3a16af2b06..b99c1bd5547 100644 --- a/lucene/misc/src/java/org/apache/lucene/document/LazyDocument.java +++ b/lucene/misc/src/java/org/apache/lucene/document/LazyDocument.java @@ -27,6 +27,7 @@ import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexableFieldType; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.util.BytesRef; /** Defers actually loading a field's value until you ask diff --git a/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java b/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java index 1f808e3c0a2..9dd6e76fca8 100644 --- a/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java +++ b/lucene/misc/src/test/org/apache/lucene/index/TestMultiPassIndexSplitter.java @@ -19,7 +19,6 @@ package org.apache.lucene.index; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java b/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java index 06787dbdd7b..62b96a9dfc8 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/mlt/MoreLikeThis.java @@ -22,12 +22,12 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.Fields; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.MultiFields; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java index a86976f4bd9..69473a40b6c 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/complexPhrase/TestComplexPhraseQuery.java @@ -23,10 +23,10 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; diff --git a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java index 03f46408f41..c60f1944f62 100644 --- a/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java +++ b/lucene/queryparser/src/test/org/apache/lucene/queryparser/xml/TestParser.java @@ -24,11 +24,11 @@ import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.IntField; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.search.DisjunctionMaxQuery; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/DuplicateFilterTest.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/DuplicateFilterTest.java index b21d455271d..2d9040b4ba7 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/DuplicateFilterTest.java +++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/DuplicateFilterTest.java @@ -23,7 +23,6 @@ import java.util.HashSet; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.*; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexSearcher; diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java index ce9bdbe28a4..401dc0d967e 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java +++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/FuzzyLikeThisQueryTest.java @@ -21,9 +21,9 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java index 81eadf8083e..624cd4ce345 100644 --- a/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java +++ b/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java @@ -19,6 +19,8 @@ package org.apache.lucene.spatial; import com.spatial4j.core.context.SpatialContext; import com.spatial4j.core.shape.Shape; + +import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexableField; import org.apache.lucene.queries.function.FunctionQuery; import org.apache.lucene.queries.function.ValueSource; @@ -97,7 +99,7 @@ public abstract class SpatialStrategy { * * @return Not null nor will it have null elements. */ - public abstract IndexableField[] createIndexableFields(Shape shape); + public abstract Field[] createIndexableFields(Shape shape); /** * The value source yields a number that is proportional to the distance between the query shape and indexed data. diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java index 5c74d197765..91af948c1b3 100644 --- a/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java +++ b/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java @@ -92,11 +92,11 @@ public class BBoxStrategy extends SpatialStrategy { //--------------------------------- @Override - public IndexableField[] createIndexableFields(Shape shape) { + public Field[] createIndexableFields(Shape shape) { Rectangle bbox = shape.getBoundingBox(); FieldType doubleFieldType = new FieldType(DoubleField.TYPE_NOT_STORED); doubleFieldType.setNumericPrecisionStep(precisionStep); - IndexableField[] fields = new IndexableField[5]; + Field[] fields = new Field[5]; fields[0] = new DoubleField(field_minX, bbox.getMinX(), doubleFieldType); fields[1] = new DoubleField(field_maxX, bbox.getMaxX(), doubleFieldType); fields[2] = new DoubleField(field_minY, bbox.getMinY(), doubleFieldType); diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java index fdd53d41440..70d0eec10a1 100644 --- a/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java +++ b/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/PrefixTreeStrategy.java @@ -63,7 +63,7 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy { } @Override - public IndexableField[] createIndexableFields(Shape shape) { + public Field[] createIndexableFields(Shape shape) { int detailLevel = grid.getMaxLevelForPrecision(shape,distErrPct); List cells = grid.getNodes(shape, detailLevel, true);//true=intermediates cells //If shape isn't a point, add a full-resolution center-point so that @@ -79,7 +79,7 @@ public abstract class PrefixTreeStrategy extends SpatialStrategy { // http://code.google.com/p/lucene-spatial-playground/issues/detail?id=4 Field field = new Field(getFieldName(), new CellTokenStream(cells.iterator()), FIELD_TYPE); - return new IndexableField[]{field}; + return new Field[]{field}; } /* Indexed, tokenized, not stored. */ diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java index 7f420d562f6..a5e6e804f30 100644 --- a/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java +++ b/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java @@ -24,6 +24,7 @@ import com.spatial4j.core.shape.Point; import com.spatial4j.core.shape.Rectangle; import com.spatial4j.core.shape.Shape; import org.apache.lucene.document.DoubleField; +import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.index.IndexableField; import org.apache.lucene.queries.function.FunctionQuery; @@ -77,12 +78,12 @@ public class TwoDoublesStrategy extends SpatialStrategy { } @Override - public IndexableField[] createIndexableFields(Shape shape) { + public Field[] createIndexableFields(Shape shape) { if( shape instanceof Point ) { Point point = (Point)shape; FieldType doubleFieldType = new FieldType(DoubleField.TYPE_NOT_STORED); doubleFieldType.setNumericPrecisionStep(precisionStep); - IndexableField[] f = new IndexableField[2]; + Field[] f = new Field[2]; f[0] = new DoubleField(fieldNameX, point.getX(), doubleFieldType); f[1] = new DoubleField(fieldNameY, point.getY(), doubleFieldType); return f; @@ -90,7 +91,7 @@ public class TwoDoublesStrategy extends SpatialStrategy { if( !ignoreIncompatibleGeometry ) { throw new IllegalArgumentException( "TwoDoublesStrategy can not index: "+shape ); } - return new IndexableField[0]; // nothing (solr does not support null) + return new Field[0]; // nothing (solr does not support null) } @Override diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java b/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java index 42d16850e16..750183e0383 100644 --- a/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java +++ b/lucene/spatial/src/test/org/apache/lucene/spatial/PortedSolr3Test.java @@ -194,7 +194,7 @@ public class PortedSolr3Test extends StrategyTestCase { private Document newDoc(String id, Shape shape) { Document doc = new Document(); doc.add(new StringField("id", id, Field.Store.YES)); - for (IndexableField f : strategy.createIndexableFields(shape)) { + for (Field f : strategy.createIndexableFields(shape)) { doc.add(f); } if (storeShape) diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java index 64392d3783c..3e578f25f4d 100644 --- a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java +++ b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java @@ -124,7 +124,7 @@ public class SpatialExample extends LuceneTestCase { //Potentially more than one shape in this field is supported by some // strategies; see the javadocs of the SpatialStrategy impl to see. for (Shape shape : shapes) { - for (IndexableField f : strategy.createIndexableFields(shape)) { + for (Field f : strategy.createIndexableFields(shape)) { doc.add(f); } //store it too; the format is up to you diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java index e78b4d01673..5909cb109b7 100644 --- a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java +++ b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java @@ -18,9 +18,9 @@ package org.apache.lucene.spatial; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java index 1e30cbbf5d0..5460b99253e 100644 --- a/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java +++ b/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java @@ -85,7 +85,7 @@ public abstract class StrategyTestCase extends SpatialTestCase { document.add(new StringField("id", data.id, Field.Store.YES)); document.add(new StringField("name", data.name, Field.Store.YES)); Shape shape = ctx.readShape(data.shape); - for (IndexableField f : strategy.createIndexableFields(shape)) { + for (Field f : strategy.createIndexableFields(shape)) { document.add(f); } if (storeShape) diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java index 4131d7f58b0..3aeb0af3cca 100644 --- a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java +++ b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestRecursivePrefixTreeStrategy.java @@ -154,7 +154,7 @@ public class TestRecursivePrefixTreeStrategy extends StrategyTestCase { private Document newDoc(String id, Shape shape) { Document doc = new Document(); doc.add(new StringField("id", id, Field.Store.YES)); - for (IndexableField f : strategy.createIndexableFields(shape)) { + for (Field f : strategy.createIndexableFields(shape)) { doc.add(f); } if (storeShape) diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java index d63cf7ea608..389d471e75e 100644 --- a/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java +++ b/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/TestTermQueryPrefixGridStrategy.java @@ -46,7 +46,7 @@ public class TestTermQueryPrefixGridStrategy extends SpatialTestCase { Document losAngeles = new Document(); losAngeles.add(new StringField("name", "Los Angeles", Field.Store.YES)); - for (IndexableField field : prefixGridStrategy.createIndexableFields(point)) { + for (Field field : prefixGridStrategy.createIndexableFields(point)) { losAngeles.add(field); } losAngeles.add(new StoredField(prefixGridStrategy.getFieldName(), ctx.toString(point))); diff --git a/lucene/test-framework/src/java/org/apache/lucene/analysis/CollationTestBase.java b/lucene/test-framework/src/java/org/apache/lucene/analysis/CollationTestBase.java index 8752782e24a..716303e8d0b 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/analysis/CollationTestBase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/CollationTestBase.java @@ -27,7 +27,6 @@ import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.DirectoryReader; @@ -36,6 +35,7 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/DocHelper.java b/lucene/test-framework/src/java/org/apache/lucene/index/DocHelper.java index ffc0dbb8e86..da4627da216 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/index/DocHelper.java +++ b/lucene/test-framework/src/java/org/apache/lucene/index/DocHelper.java @@ -29,7 +29,6 @@ import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java index fc313db428e..8ecc3d78b09 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java @@ -29,7 +29,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.Query; diff --git a/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java b/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java index 6a7b6fc564c..b8ed1957a47 100644 --- a/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java +++ b/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java @@ -29,6 +29,7 @@ import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute; import org.apache.lucene.collation.ICUCollationKeyAnalyzer; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.Query; import org.apache.lucene.search.SortField; import org.apache.lucene.search.TermRangeQuery; @@ -211,7 +212,7 @@ public class ICUCollationField extends FieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { writer.writeStr(name, f.stringValue(), true); } diff --git a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java index 59f8d3c106c..b8411ea188f 100644 --- a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java @@ -30,8 +30,8 @@ import java.util.Map; import java.util.regex.Pattern; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.search.*; diff --git a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java index a39e6c87968..2f04c93cc7b 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java @@ -28,7 +28,6 @@ import org.apache.lucene.analysis.util.TokenFilterFactory; import org.apache.lucene.analysis.util.TokenizerFactory; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.*; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.search.DocIdSetIterator; diff --git a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java index 921c4e81d82..0b152783d4f 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java @@ -18,9 +18,9 @@ package org.apache.solr.handler.component; */ import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.util.BytesRef; import org.apache.solr.client.solrj.SolrResponse; @@ -298,7 +298,6 @@ public class RealTimeGetComponent extends SearchComponent private static SolrDocument toSolrDoc(SolrInputDocument sdoc, IndexSchema schema) { // TODO: do something more performant than this double conversion Document doc = DocumentBuilder.toDocument(sdoc, schema); - List fields = doc.getFields(); // copy the stored fields only StoredDocument out = new StoredDocument(); diff --git a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java index 97d6588ab77..e4d9fc34f34 100644 --- a/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java +++ b/solr/core/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java @@ -33,9 +33,9 @@ import org.apache.lucene.analysis.TokenFilter; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.search.Query; import org.apache.lucene.search.highlight.*; import org.apache.lucene.search.vectorhighlight.BoundaryScanner; diff --git a/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java b/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java index 24e9f10876f..f38a2bdd14c 100755 --- a/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java @@ -20,9 +20,9 @@ import java.io.*; import java.util.*; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.util.BytesRef; import org.apache.solr.common.SolrDocument; import org.apache.solr.common.params.CommonParams; diff --git a/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java b/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java index 1b134ed0762..08630c6a135 100644 --- a/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java @@ -22,9 +22,9 @@ import java.io.Writer; import java.util.*; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.util.BytesRef; import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentList; diff --git a/solr/core/src/java/org/apache/solr/schema/BCDIntField.java b/solr/core/src/java/org/apache/solr/schema/BCDIntField.java index 8b24643935e..86efdf11889 100644 --- a/solr/core/src/java/org/apache/solr/schema/BCDIntField.java +++ b/solr/core/src/java/org/apache/solr/schema/BCDIntField.java @@ -21,6 +21,7 @@ import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.search.SortField; import org.apache.solr.search.QParser; import org.apache.lucene.index.GeneralField; +import org.apache.lucene.index.StorableField; import org.apache.solr.util.BCDUtils; import org.apache.solr.response.TextResponseWriter; @@ -46,13 +47,13 @@ public class BCDIntField extends PrimitiveFieldType { } @Override - public String toExternal(GeneralField f) { + public String toExternal(StorableField f) { return indexedToReadable(f.stringValue()); } // Note, this can't return type 'Integer' because BCDStrField and BCDLong extend it @Override - public Object toObject(GeneralField f) { + public Object toObject(StorableField f) { return Integer.valueOf( toExternal(f) ); } @@ -62,7 +63,7 @@ public class BCDIntField extends PrimitiveFieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { writer.writeInt(name,toExternal(f)); } } diff --git a/solr/core/src/java/org/apache/solr/schema/BCDLongField.java b/solr/core/src/java/org/apache/solr/schema/BCDLongField.java index e3261229a63..4945be26849 100644 --- a/solr/core/src/java/org/apache/solr/schema/BCDLongField.java +++ b/solr/core/src/java/org/apache/solr/schema/BCDLongField.java @@ -17,13 +17,13 @@ package org.apache.solr.schema; -import org.apache.lucene.index.GeneralField; +import org.apache.lucene.index.StorableField; /** * */ public class BCDLongField extends BCDIntField { @Override - public Long toObject(GeneralField f) { + public Long toObject(StorableField f) { return Long.valueOf( toExternal(f) ); } } diff --git a/solr/core/src/java/org/apache/solr/schema/BCDStrField.java b/solr/core/src/java/org/apache/solr/schema/BCDStrField.java index 8a3d4be670e..ab5afd2b031 100644 --- a/solr/core/src/java/org/apache/solr/schema/BCDStrField.java +++ b/solr/core/src/java/org/apache/solr/schema/BCDStrField.java @@ -17,7 +17,7 @@ package org.apache.solr.schema; -import org.apache.lucene.index.GeneralField; +import org.apache.lucene.index.StorableField; /** * */ @@ -27,7 +27,7 @@ public class BCDStrField extends BCDIntField { * is not an integer, it will not survive the base10k conversion! */ @Override - public String toObject(GeneralField f) { + public String toObject(StorableField f) { return toExternal(f); } } diff --git a/solr/core/src/java/org/apache/solr/schema/BinaryField.java b/solr/core/src/java/org/apache/solr/schema/BinaryField.java index 5c969eb310b..528586686e7 100644 --- a/solr/core/src/java/org/apache/solr/schema/BinaryField.java +++ b/solr/core/src/java/org/apache/solr/schema/BinaryField.java @@ -23,6 +23,7 @@ import java.nio.ByteBuffer; import org.apache.lucene.document.Field; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.SortField; import org.apache.lucene.util.BytesRef; import org.apache.solr.common.util.Base64; @@ -36,7 +37,7 @@ public class BinaryField extends FieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { writer.writeStr(name, toBase64String(toObject(f)), false); } @@ -47,18 +48,18 @@ public class BinaryField extends FieldType { @Override - public String toExternal(GeneralField f) { + public String toExternal(StorableField f) { return toBase64String(toObject(f)); } @Override - public ByteBuffer toObject(GeneralField f) { + public ByteBuffer toObject(StorableField f) { BytesRef bytes = f.binaryValue(); return ByteBuffer.wrap(bytes.bytes, bytes.offset, bytes.length); } @Override - public IndexableField createField(SchemaField field, Object val, float boost) { + public StorableField createField(SchemaField field, Object val, float boost) { if (val == null) return null; if (!field.stored()) { log.trace("Ignoring unstored binary field: " + field); diff --git a/solr/core/src/java/org/apache/solr/schema/BoolField.java b/solr/core/src/java/org/apache/solr/schema/BoolField.java index a7815e10ad5..abf488ff598 100644 --- a/solr/core/src/java/org/apache/solr/schema/BoolField.java +++ b/solr/core/src/java/org/apache/solr/schema/BoolField.java @@ -19,6 +19,7 @@ package org.apache.solr.schema; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.GeneralField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.FieldCache; import org.apache.lucene.search.SortField; import org.apache.lucene.util.BytesRef; @@ -112,12 +113,12 @@ public class BoolField extends PrimitiveFieldType { } @Override - public String toExternal(GeneralField f) { + public String toExternal(StorableField f) { return indexedToReadable(f.stringValue()); } @Override - public Boolean toObject(GeneralField f) { + public Boolean toObject(StorableField f) { return Boolean.valueOf( toExternal(f) ); } @@ -146,7 +147,7 @@ public class BoolField extends PrimitiveFieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { writer.writeBool(name, f.stringValue().charAt(0) == 'T'); } } diff --git a/solr/core/src/java/org/apache/solr/schema/ByteField.java b/solr/core/src/java/org/apache/solr/schema/ByteField.java index 310f7147f32..873ce7d09a4 100644 --- a/solr/core/src/java/org/apache/solr/schema/ByteField.java +++ b/solr/core/src/java/org/apache/solr/schema/ByteField.java @@ -20,6 +20,7 @@ import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.valuesource.ByteFieldSource; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.SortField; import org.apache.solr.response.TextResponseWriter; @@ -66,7 +67,7 @@ public class ByteField extends PrimitiveFieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { String s = f.stringValue(); // these values may be from a legacy lucene index, which may @@ -91,7 +92,7 @@ public class ByteField extends PrimitiveFieldType { } @Override - public Byte toObject(GeneralField f) { + public Byte toObject(StorableField f) { return Byte.valueOf(toExternal(f)); } } diff --git a/solr/core/src/java/org/apache/solr/schema/CollationField.java b/solr/core/src/java/org/apache/solr/schema/CollationField.java index 839ea2be713..77c72f0ce3d 100644 --- a/solr/core/src/java/org/apache/solr/schema/CollationField.java +++ b/solr/core/src/java/org/apache/solr/schema/CollationField.java @@ -33,6 +33,7 @@ import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute; import org.apache.lucene.collation.CollationKeyAnalyzer; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.Query; import org.apache.lucene.search.SortField; import org.apache.lucene.search.TermRangeQuery; @@ -186,7 +187,7 @@ public class CollationField extends FieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { writer.writeStr(name, f.stringValue(), true); } diff --git a/solr/core/src/java/org/apache/solr/schema/CurrencyField.java b/solr/core/src/java/org/apache/solr/schema/CurrencyField.java index c7e52772c89..0a1b94f2bcd 100644 --- a/solr/core/src/java/org/apache/solr/schema/CurrencyField.java +++ b/solr/core/src/java/org/apache/solr/schema/CurrencyField.java @@ -19,6 +19,7 @@ package org.apache.solr.schema; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.search.Query; @@ -132,10 +133,10 @@ public class CurrencyField extends FieldType implements SchemaAware, ResourceLoa } @Override - public IndexableField[] createFields(SchemaField field, Object externalVal, float boost) { + public StorableField[] createFields(SchemaField field, Object externalVal, float boost) { CurrencyValue value = CurrencyValue.parse(externalVal.toString(), defaultCurrency); - IndexableField[] f = new IndexableField[field.stored() ? 3 : 2]; + StorableField[] f = new StorableField[field.stored() ? 3 : 2]; SchemaField amountField = getAmountField(field); f[0] = amountField.createField(String.valueOf(value.getAmount()), amountField.indexed() && !amountField.omitNorms() ? boost : 1F); SchemaField currencyField = getCurrencyField(field); @@ -238,12 +239,8 @@ public class CurrencyField extends FieldType implements SchemaAware, ResourceLoa } } - public void write(XMLWriter xmlWriter, String name, IndexableField field) throws IOException { - xmlWriter.writeStr(name, field.stringValue(), false); - } - @Override - public void write(TextResponseWriter writer, String name, GeneralField field) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField field) throws IOException { writer.writeStr(name, field.stringValue(), false); } diff --git a/solr/core/src/java/org/apache/solr/schema/DateField.java b/solr/core/src/java/org/apache/solr/schema/DateField.java index 2dc29303d63..c46c46cc008 100644 --- a/solr/core/src/java/org/apache/solr/schema/DateField.java +++ b/solr/core/src/java/org/apache/solr/schema/DateField.java @@ -20,6 +20,7 @@ package org.apache.solr.schema; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.queries.function.docvalues.DocTermsIndexDocValues; import org.apache.lucene.search.Query; import org.apache.lucene.search.SortField; @@ -189,7 +190,7 @@ public class DateField extends PrimitiveFieldType { } } - public IndexableField createField(SchemaField field, Object value, float boost) { + public StorableField createField(SchemaField field, Object value, float boost) { // Convert to a string before indexing if(value instanceof Date) { value = toInternal( (Date)value ) + Z; @@ -214,7 +215,7 @@ public class DateField extends PrimitiveFieldType { } @Override - public String toExternal(GeneralField f) { + public String toExternal(StorableField f) { return indexedToReadable(f.stringValue()); } @@ -223,7 +224,7 @@ public class DateField extends PrimitiveFieldType { } @Override - public Date toObject(GeneralField f) { + public Date toObject(StorableField f) { try { return parseDate( toExternal(f) ); } @@ -238,7 +239,7 @@ public class DateField extends PrimitiveFieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { writer.writeDate(name, toExternal(f)); } diff --git a/solr/core/src/java/org/apache/solr/schema/DoubleField.java b/solr/core/src/java/org/apache/solr/schema/DoubleField.java index 95473b9868c..5d2968fa139 100644 --- a/solr/core/src/java/org/apache/solr/schema/DoubleField.java +++ b/solr/core/src/java/org/apache/solr/schema/DoubleField.java @@ -21,6 +21,7 @@ import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.valuesource.DoubleFieldSource; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.SortField; import org.apache.solr.response.TextResponseWriter; import org.apache.solr.search.QParser; @@ -63,7 +64,7 @@ public class DoubleField extends PrimitiveFieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { String s = f.stringValue(); // these values may be from a legacy lucene index, which may @@ -89,7 +90,7 @@ public class DoubleField extends PrimitiveFieldType { @Override - public Double toObject(GeneralField f) { + public Double toObject(StorableField f) { return Double.valueOf(toExternal(f)); } } diff --git a/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java b/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java index 80f678c2142..f8dac311a0b 100755 --- a/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java +++ b/solr/core/src/java/org/apache/solr/schema/ExternalFileField.java @@ -20,6 +20,7 @@ import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.search.SortField; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.solr.search.function.FileFloatSource; import org.apache.solr.search.QParser; import org.apache.solr.response.TextResponseWriter; @@ -82,7 +83,7 @@ public class ExternalFileField extends FieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { throw new UnsupportedOperationException(); } diff --git a/solr/core/src/java/org/apache/solr/schema/FieldType.java b/solr/core/src/java/org/apache/solr/schema/FieldType.java index 3cfa362edc7..ced6220f3a3 100644 --- a/solr/core/src/java/org/apache/solr/schema/FieldType.java +++ b/solr/core/src/java/org/apache/solr/schema/FieldType.java @@ -237,7 +237,7 @@ public abstract class FieldType extends FieldProperties { * * */ - public IndexableField createField(SchemaField field, Object value, float boost) { + public StorableField createField(SchemaField field, Object value, float boost) { if (!field.indexed() && !field.stored()) { if (log.isTraceEnabled()) log.trace("Ignoring unindexed/unstored field: " + field); @@ -274,7 +274,7 @@ public abstract class FieldType extends FieldProperties { * @param boost The boost value * @return the {@link org.apache.lucene.index.IndexableField}. */ - protected IndexableField createField(String name, String val, org.apache.lucene.document.FieldType type, float boost){ + protected StorableField createField(String name, String val, org.apache.lucene.document.FieldType type, float boost){ Field f = new Field(name, val, type); f.setBoost(boost); return f; @@ -290,9 +290,9 @@ public abstract class FieldType extends FieldProperties { * @see #createField(SchemaField, Object, float) * @see #isPolyField() */ - public IndexableField[] createFields(SchemaField field, Object value, float boost) { - IndexableField f = createField( field, value, boost); - return f==null ? new IndexableField[]{} : new IndexableField[]{f}; + public StorableField[] createFields(SchemaField field, Object value, float boost) { + StorableField f = createField( field, value, boost); + return f==null ? new StorableField[]{} : new StorableField[]{f}; } protected IndexOptions getIndexOptions(SchemaField field, String internalVal) { @@ -321,7 +321,7 @@ public abstract class FieldType extends FieldProperties { * value * @see #toInternal */ - public String toExternal(GeneralField f) { + public String toExternal(StorableField f) { // currently used in writing XML of the search result (but perhaps // a more efficient toXML(IndexableField f, Writer w) should be used // in the future. @@ -333,14 +333,14 @@ public abstract class FieldType extends FieldProperties { * @see #toInternal * @since solr 1.3 */ - public Object toObject(GeneralField f) { + public Object toObject(StorableField f) { return toExternal(f); // by default use the string } public Object toObject(SchemaField sf, BytesRef term) { final CharsRef ref = new CharsRef(term.length); indexedToReadable(term, ref); - final IndexableField f = createField(sf, ref.toString(), 1.0f); + final StorableField f = createField(sf, ref.toString(), 1.0f); return toObject(f); } @@ -356,12 +356,12 @@ public abstract class FieldType extends FieldProperties { } /** Given the stored field, return the human readable representation */ - public String storedToReadable(IndexableField f) { + public String storedToReadable(StorableField f) { return toExternal(f); } /** Given the stored field, return the indexed form */ - public String storedToIndexed(GeneralField f) { + public String storedToIndexed(StorableField f) { // right now, the transformation of single valued fields like SortableInt // is done when the Field is created, not at analysis time... this means // that the indexed form is the same as the stored field form. @@ -530,7 +530,7 @@ public abstract class FieldType extends FieldProperties { /** * calls back to TextResponseWriter to write the field value */ - public abstract void write(TextResponseWriter writer, String name, GeneralField f) throws IOException; + public abstract void write(TextResponseWriter writer, String name, StorableField f) throws IOException; /** diff --git a/solr/core/src/java/org/apache/solr/schema/FloatField.java b/solr/core/src/java/org/apache/solr/schema/FloatField.java index f410590007f..75cf0873dd0 100644 --- a/solr/core/src/java/org/apache/solr/schema/FloatField.java +++ b/solr/core/src/java/org/apache/solr/schema/FloatField.java @@ -23,6 +23,7 @@ import org.apache.lucene.search.SortField; import org.apache.solr.search.QParser; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.solr.response.TextResponseWriter; import java.util.Map; @@ -61,7 +62,7 @@ public class FloatField extends PrimitiveFieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { String s = f.stringValue(); // these values may be from a legacy lucene index, which may @@ -86,7 +87,7 @@ public class FloatField extends PrimitiveFieldType { } @Override - public Float toObject(GeneralField f) { + public Float toObject(StorableField f) { return Float.valueOf( toExternal(f) ); } } diff --git a/solr/core/src/java/org/apache/solr/schema/GeoHashField.java b/solr/core/src/java/org/apache/solr/schema/GeoHashField.java index 90f52c497c1..7dd7d53c32f 100644 --- a/solr/core/src/java/org/apache/solr/schema/GeoHashField.java +++ b/solr/core/src/java/org/apache/solr/schema/GeoHashField.java @@ -21,6 +21,7 @@ import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.valuesource.LiteralValueSource; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.Query; import org.apache.lucene.search.SortField; import com.spatial4j.core.context.ParseUtils; @@ -74,14 +75,14 @@ public class GeoHashField extends FieldType implements SpatialQueryable { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { writer.writeStr(name, toExternal(f), false); } @Override - public String toExternal(GeneralField f) { + public String toExternal(StorableField f) { Point p = GeohashUtils.decode(f.stringValue(),ctx); return p.getY() + "," + p.getX(); } diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java index 32dd8fd07e0..db6f8a56f82 100644 --- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java +++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java @@ -21,10 +21,10 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.AnalyzerWrapper; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.util.Version; import org.apache.lucene.analysis.util.ResourceLoader; -import org.apache.lucene.document.StoredDocument; import org.apache.solr.common.SolrException; import org.apache.solr.common.params.SolrParams; import org.apache.solr.util.DOMUtil; diff --git a/solr/core/src/java/org/apache/solr/schema/IntField.java b/solr/core/src/java/org/apache/solr/schema/IntField.java index a47e74202bc..3c9320c40f0 100644 --- a/solr/core/src/java/org/apache/solr/schema/IntField.java +++ b/solr/core/src/java/org/apache/solr/schema/IntField.java @@ -23,6 +23,7 @@ import org.apache.lucene.search.SortField; import org.apache.solr.search.QParser; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.solr.response.TextResponseWriter; import java.util.Map; @@ -61,7 +62,7 @@ public class IntField extends PrimitiveFieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { String s = f.stringValue(); // these values may be from a legacy lucene index, which may @@ -86,7 +87,7 @@ public class IntField extends PrimitiveFieldType { } @Override - public Integer toObject(GeneralField f) { + public Integer toObject(StorableField f) { return Integer.valueOf( toExternal(f) ); } } diff --git a/solr/core/src/java/org/apache/solr/schema/LatLonType.java b/solr/core/src/java/org/apache/solr/schema/LatLonType.java index 77e02bac55f..0bf8032e161 100644 --- a/solr/core/src/java/org/apache/solr/schema/LatLonType.java +++ b/solr/core/src/java/org/apache/solr/schema/LatLonType.java @@ -21,6 +21,7 @@ import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.AtomicReaderContext; +import org.apache.lucene.index.StorableField; import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.valuesource.VectorValueSource; @@ -61,10 +62,10 @@ public class LatLonType extends AbstractSubTypeFieldType implements SpatialQuery } @Override - public IndexableField[] createFields(SchemaField field, Object value, float boost) { + public StorableField[] createFields(SchemaField field, Object value, float boost) { String externalVal = value.toString(); //we could have tileDiff + 3 fields (two for the lat/lon, one for storage) - IndexableField[] f = new IndexableField[(field.indexed() ? 2 : 0) + (field.stored() ? 1 : 0)]; + StorableField[] f = new StorableField[(field.indexed() ? 2 : 0) + (field.stored() ? 1 : 0)]; if (field.indexed()) { int i = 0; double[] latLon; @@ -245,7 +246,7 @@ public class LatLonType extends AbstractSubTypeFieldType implements SpatialQuery } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { writer.writeStr(name, f.stringValue(), false); } @@ -259,7 +260,7 @@ public class LatLonType extends AbstractSubTypeFieldType implements SpatialQuery //It never makes sense to create a single field, so make it impossible to happen @Override - public IndexableField createField(SchemaField field, Object value, float boost) { + public StorableField createField(SchemaField field, Object value, float boost) { throw new UnsupportedOperationException("LatLonType uses multiple fields. field=" + field.getName()); } diff --git a/solr/core/src/java/org/apache/solr/schema/LongField.java b/solr/core/src/java/org/apache/solr/schema/LongField.java index 343aa6c0bc1..9f795a7a083 100644 --- a/solr/core/src/java/org/apache/solr/schema/LongField.java +++ b/solr/core/src/java/org/apache/solr/schema/LongField.java @@ -21,6 +21,7 @@ import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.valuesource.LongFieldSource; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.SortField; import org.apache.solr.response.TextResponseWriter; import org.apache.solr.search.QParser; @@ -63,7 +64,7 @@ public class LongField extends PrimitiveFieldType { } @Override - public void write(TextResponseWriter writer, String name, GeneralField f) throws IOException { + public void write(TextResponseWriter writer, String name, StorableField f) throws IOException { String s = f.stringValue(); // these values may be from a legacy lucene index, which may @@ -88,7 +89,7 @@ public class LongField extends PrimitiveFieldType { } @Override - public Long toObject(GeneralField f) { + public Long toObject(StorableField f) { return Long.valueOf( toExternal(f) ); } } diff --git a/solr/core/src/java/org/apache/solr/schema/PointType.java b/solr/core/src/java/org/apache/solr/schema/PointType.java index a19054e7470..7907ee8e323 100644 --- a/solr/core/src/java/org/apache/solr/schema/PointType.java +++ b/solr/core/src/java/org/apache/solr/schema/PointType.java @@ -22,6 +22,7 @@ import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.valuesource.VectorValueSource; import org.apache.lucene.index.GeneralField; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; @@ -70,7 +71,7 @@ public class PointType extends CoordinateFieldType implements SpatialQueryable { } @Override - public IndexableField[] createFields(SchemaField field, Object value, float boost) { + public StorableField[] createFields(SchemaField field, Object value, float boost) { String externalVal = value.toString(); String[] point = new String[0]; try { @@ -80,7 +81,7 @@ public class PointType extends CoordinateFieldType implements SpatialQueryable { } // TODO: this doesn't currently support polyFields as sub-field types - IndexableField[] f = new IndexableField[ (field.indexed() ? dimension : 0) + (field.stored() ? 1 : 0) ]; + StorableField[] f = new StorableField[ (field.indexed() ? dimension : 0) + (field.stored() ? 1 : 0) ]; if (field.indexed()) { for (int i=0; i 0) { if (!sfield.multiValued()) { String oldValue = map.put(sfield.getName(), val); @@ -66,12 +69,12 @@ public class DocumentBuilder { } } // Add each field - for (IndexableField field : fields) { - doc.add(field); + for (StorableField field : fields) { + doc.add((Field) field); } } } else { - IndexableField field = sfield.createField(val, boost); + StorableField field = sfield.createField(val, boost); if (field != null) { if (!sfield.multiValued()) { String oldValue = map.put(sfield.getName(), val); @@ -81,7 +84,7 @@ public class DocumentBuilder { } } } - doc.add(field); + doc.add((Field) field); } } @@ -190,13 +193,13 @@ public class DocumentBuilder { private static void addField(Document doc, SchemaField field, Object val, float boost) { if (field.isPolyField()) { - IndexableField[] farr = field.getType().createFields(field, val, boost); - for (IndexableField f : farr) { - if (f != null) doc.add(f); // null fields are not added + StorableField[] farr = field.getType().createFields(field, val, boost); + for (StorableField f : farr) { + if (f != null) doc.add((Field) f); // null fields are not added } } else { - IndexableField f = field.createField(val, boost); - if (f != null) doc.add(f); // null fields are not added + StorableField f = field.createField(val, boost); + if (f != null) doc.add((Field) f); // null fields are not added } } diff --git a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java index ad176dc19f3..5053124f654 100644 --- a/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java +++ b/solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java @@ -18,9 +18,9 @@ package org.apache.solr.util; import org.apache.lucene.document.Document; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.*; diff --git a/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java b/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java index e0702267739..9e4964d5803 100644 --- a/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java +++ b/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java @@ -30,10 +30,11 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.LogMergePolicy; +import org.apache.lucene.index.StorableField; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.util.English; import org.apache.solr.common.SolrException; import org.apache.solr.common.params.CommonParams; @@ -420,7 +421,7 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 { IndexSchema ischema = new IndexSchema(solrConfig, getSchemaFile(), null); SchemaField f; // Solr field type - IndexableField luf; // Lucene field + StorableField luf; // Lucene field f = ischema.getField("test_basictv"); luf = f.createField("test", 0f); diff --git a/solr/core/src/test/org/apache/solr/schema/CurrencyFieldTest.java b/solr/core/src/test/org/apache/solr/schema/CurrencyFieldTest.java index d698e70ec14..9c34edb615b 100644 --- a/solr/core/src/test/org/apache/solr/schema/CurrencyFieldTest.java +++ b/solr/core/src/test/org/apache/solr/schema/CurrencyFieldTest.java @@ -17,6 +17,7 @@ package org.apache.solr.schema; */ import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.core.SolrCore; import org.junit.BeforeClass; @@ -71,7 +72,7 @@ public class CurrencyFieldTest extends SolrTestCaseJ4 { FieldType tmp = amount.getType(); assertTrue(tmp instanceof CurrencyField); String currencyValue = "1.50,EUR"; - IndexableField[] fields = amount.createFields(currencyValue, 2); + StorableField[] fields = amount.createFields(currencyValue, 2); assertEquals(fields.length, 3); // First field is currency code, second is value, third is stored. diff --git a/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java b/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java index 847dae12d04..4f8a5341b69 100644 --- a/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java +++ b/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java @@ -19,6 +19,7 @@ package org.apache.solr.schema; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.util.LuceneTestCase; import org.apache.solr.util.DateMathParser; @@ -207,7 +208,7 @@ public class DateFieldTest extends LuceneTestCase { public void testCreateField() { int props = FieldProperties.INDEXED ^ FieldProperties.STORED; SchemaField sf = new SchemaField( "test", f, props, null ); - IndexableField out = f.createField(sf, "1995-12-31T23:59:59Z", 1.0f ); + StorableField out = f.createField(sf, "1995-12-31T23:59:59Z", 1.0f ); assertEquals(820454399000l, f.toObject( out ).getTime() ); out = f.createField(sf, new Date(820454399000l), 1.0f ); diff --git a/solr/core/src/test/org/apache/solr/schema/PolyFieldTest.java b/solr/core/src/test/org/apache/solr/schema/PolyFieldTest.java index ee023889913..87973e36293 100644 --- a/solr/core/src/test/org/apache/solr/schema/PolyFieldTest.java +++ b/solr/core/src/test/org/apache/solr/schema/PolyFieldTest.java @@ -18,6 +18,7 @@ package org.apache.solr.schema; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.index.IndexableField; +import org.apache.lucene.index.StorableField; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; @@ -83,7 +84,7 @@ public class PolyFieldTest extends SolrTestCaseJ4 { assertEquals(pt.getDimension(), 2); double[] xy = new double[]{35.0, -79.34}; String point = xy[0] + "," + xy[1]; - IndexableField[] fields = home.createFields(point, 2); + StorableField[] fields = home.createFields(point, 2); assertEquals(fields.length, 3);//should be 3, we have a stored field //first two fields contain the values, third is just stored and contains the original for (int i = 0; i < 3; i++) { diff --git a/solr/core/src/test/org/apache/solr/search/TestStressLucene.java b/solr/core/src/test/org/apache/solr/search/TestStressLucene.java index 6bb49ce87ef..38809f567c6 100644 --- a/solr/core/src/test/org/apache/solr/search/TestStressLucene.java +++ b/solr/core/src/test/org/apache/solr/search/TestStressLucene.java @@ -21,11 +21,11 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredDocument; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.Term; import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.Directory; From 36014af614c82fb5692e9d5df11bd91f2e0ac4d4 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Thu, 16 Aug 2012 17:38:02 +0000 Subject: [PATCH 07/13] LUCENE-3312: Apply patch lucene-3312-patch-13.patch git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1373940 13f79535-47bb-0310-9956-ffa450edef68 --- .../core/src/java/org/apache/lucene/analysis/package.html | 4 ++-- .../java/org/apache/lucene/codecs/StoredFieldsWriter.java | 2 +- .../src/java/org/apache/lucene/document/Document.java | 1 - .../src/java/org/apache/lucene/index/IndexWriter.java | 8 ++++---- lucene/core/src/java/overview.html | 2 +- .../java/org/apache/lucene/index/RandomIndexWriter.java | 4 ++-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/analysis/package.html b/lucene/core/src/java/org/apache/lucene/analysis/package.html index 0495e488486..2bc7d229700 100644 --- a/lucene/core/src/java/org/apache/lucene/analysis/package.html +++ b/lucene/core/src/java/org/apache/lucene/analysis/package.html @@ -168,7 +168,7 @@ and proximity searches (though sentence identification is not provided by Lucene

    • At indexing, as a consequence of - {@link org.apache.lucene.index.IndexWriter#addDocument(Iterable) addDocument(doc)}, + {@link org.apache.lucene.index.IndexWriter#addDocument(IndexDocument) addDocument(doc)}, the Analyzer in effect for indexing is invoked for each indexed field of the added document.
    • @@ -241,7 +241,7 @@ and proximity searches (though sentence identification is not provided by Lucene

      Field Section Boundaries

      - When {@link org.apache.lucene.document.Document#add(org.apache.lucene.index.IndexableField) document.add(field)} + When {@link org.apache.lucene.document.Document#add(org.apache.lucene.document.Field) document.add(field)} is called multiple times for the same field name, we could say that each such call creates a new section for that field in that document. In fact, a separate call to diff --git a/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java index 2b360c80a23..3541da80e5b 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java @@ -69,7 +69,7 @@ public abstract class StoredFieldsWriter implements Closeable { /** Merges in the stored fields from the readers in * mergeState. The default implementation skips * over deleted documents, and uses {@link #startDocument(int)}, - * {@link #writeField(FieldInfo, StorableField)}, and {@link #finish(int)}, + * {@link #writeField(FieldInfo, StorableField)}, and {@link #finish(FieldInfos, int)}, * returning the number of documents that were written. * Implementations can override this method for more sophisticated * merging (bulk-byte copying, etc). */ diff --git a/lucene/core/src/java/org/apache/lucene/document/Document.java b/lucene/core/src/java/org/apache/lucene/document/Document.java index 60673493840..95cf80598ac 100644 --- a/lucene/core/src/java/org/apache/lucene/document/Document.java +++ b/lucene/core/src/java/org/apache/lucene/document/Document.java @@ -56,7 +56,6 @@ public final class Document implements IndexDocument{ * Creates a Document from StoredDocument so it that can be used e.g. for another * round of indexing. * - * @return a new instance of Document representation of this StoredDocument */ public Document(StoredDocument storedDoc) { for (StorableField field : storedDoc.getFields()) { diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java index 0ddb3acc2f5..d371c3829b2 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -69,10 +69,10 @@ import org.apache.lucene.util.ThreadInterruptedException; new index if there is not already an index at the provided path and otherwise open the existing index.

      -

      In either case, documents are added with {@link #addDocument(Iterable) +

      In either case, documents are added with {@link #addDocument(IndexDocument) addDocument} and removed with {@link #deleteDocuments(Term)} or {@link #deleteDocuments(Query)}. A document can be updated with {@link - #updateDocument(Term, Iterable) updateDocument} (which just deletes + #updateDocument(Term, IndexDocument) updateDocument} (which just deletes and then adds the entire document). When finished adding, deleting and updating documents, {@link #close() close} should be called.

      @@ -1096,7 +1096,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * Adds a document to this index, using the provided analyzer instead of the * value of {@link #getAnalyzer()}. * - *

      See {@link #addDocument(Iterable)} for details on + *

      See {@link #addDocument(IndexDocument)} for details on * index and IndexWriter state after an Exception, and * flushing/merging temporary free space requirements.

      * @@ -1132,7 +1132,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * perhaps to obtain better index compression), in which case * you may need to fully re-index your documents at that time. * - *

      See {@link #addDocument(Iterable)} for details on + *

      See {@link #addDocument(IndexDocument)} for details on * index and IndexWriter state after an Exception, and * flushing/merging temporary free space requirements.

      * diff --git a/lucene/core/src/java/overview.html b/lucene/core/src/java/overview.html index 14929b9c49f..ac0419255e5 100644 --- a/lucene/core/src/java/overview.html +++ b/lucene/core/src/java/overview.html @@ -130,7 +130,7 @@ adding
    • Create an {@link org.apache.lucene.index.IndexWriter IndexWriter} -and add documents to it with {@link org.apache.lucene.index.IndexWriter#addDocument(Iterable) addDocument()};
    • +and add documents to it with {@link org.apache.lucene.index.IndexWriter#addDocument(org.apache.lucene.index.IndexDocument) addDocument()};
    • Call QueryParser.parse() diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java b/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java index 0318003f5cf..b038fbac62a 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java +++ b/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java @@ -139,7 +139,7 @@ public class RandomIndexWriter implements Closeable { /** * Adds a Document. - * @see IndexWriter#addDocument(Iterable) + * @see IndexWriter#addDocument(org.apache.lucene.index.IndexDocument) */ public void addDocument(final IndexDocument doc) throws IOException { addDocument(doc, w.getAnalyzer()); @@ -285,7 +285,7 @@ public class RandomIndexWriter implements Closeable { /** * Updates a document. - * @see IndexWriter#updateDocument(Term, Iterable) + * @see IndexWriter#updateDocument(Term, org.apache.lucene.index.IndexDocument) */ public void updateDocument(Term t, final IndexDocument doc) throws IOException { if (doDocValues) { From ca1059f194f5492b6b4200ab98219baf7c080e34 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sun, 19 Aug 2012 08:45:25 +0000 Subject: [PATCH 08/13] LUCENE-3312: Small refctoring and final field git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1374710 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/util/FilterIterator.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java b/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java index 8e9b5a9b232..d67a2ff7888 100644 --- a/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java +++ b/lucene/core/src/java/org/apache/lucene/util/FilterIterator.java @@ -22,41 +22,40 @@ import java.util.NoSuchElementException; public abstract class FilterIterator implements Iterator { - private Iterator iterator; + private final Iterator iterator; private T next = null; private boolean nextIsSet = false; - protected abstract boolean predicateFunction(T field); + protected abstract boolean predicateFunction(T object); public FilterIterator(Iterator baseIterator) { this.iterator = baseIterator; } - public boolean hasNext() { - if (nextIsSet) { - return true; - } else { - return setNext(); + public final boolean hasNext() { + return nextIsSet || setNext(); + } + + public final T next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + assert nextIsSet; + try { + return next; + } finally { + nextIsSet = false; + next = null; } } - public T next() { - if (!nextIsSet) { - if (!setNext()) { - throw new NoSuchElementException(); - } - } - nextIsSet = false; - return next; - } - - public void remove() { + public final void remove() { throw new UnsupportedOperationException(); } private boolean setNext() { while (iterator.hasNext()) { - T object = iterator.next(); + final T object = iterator.next(); if (predicateFunction(object)) { next = object; nextIsSet = true; From 1c9398be8aeece3c5f6e8a280b8456b43acd0112 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sun, 19 Aug 2012 20:37:41 +0000 Subject: [PATCH 09/13] LUCENE-3312: Fix incorrect License headers git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1374842 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/core/src/java/org/apache/lucene/index/IndexDocument.java | 2 +- lucene/core/src/java/org/apache/lucene/index/StorableField.java | 2 +- .../src/java/org/apache/lucene/index/StorableFieldType.java | 2 +- .../core/src/java/org/apache/lucene/index/StoredDocument.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java b/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java index 8ae36aee91c..fa3a0a4168b 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java @@ -1,6 +1,6 @@ package org.apache.lucene.index; -/** +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. diff --git a/lucene/core/src/java/org/apache/lucene/index/StorableField.java b/lucene/core/src/java/org/apache/lucene/index/StorableField.java index 4ddb31abfb5..27dda40b515 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StorableField.java +++ b/lucene/core/src/java/org/apache/lucene/index/StorableField.java @@ -1,6 +1,6 @@ package org.apache.lucene.index; -/** +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. diff --git a/lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java b/lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java index 38f65ed523f..9aa7eac0127 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java +++ b/lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java @@ -1,6 +1,6 @@ package org.apache.lucene.index; -/** +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. diff --git a/lucene/core/src/java/org/apache/lucene/index/StoredDocument.java b/lucene/core/src/java/org/apache/lucene/index/StoredDocument.java index 345c5d9edbe..2ff6970e11b 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StoredDocument.java +++ b/lucene/core/src/java/org/apache/lucene/index/StoredDocument.java @@ -1,6 +1,6 @@ package org.apache.lucene.index; -/** +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. From a699f3c338d9aab86a478136ef2863670f2c905c Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Mon, 20 Aug 2012 14:39:44 +0000 Subject: [PATCH 10/13] LUCENE-3312: Applied Javadocs fix from lucene-3312-patch-14.patch git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1375040 13f79535-47bb-0310-9956-ffa450edef68 --- .../core/src/java/org/apache/lucene/index/GeneralField.java | 5 +++++ .../src/java/org/apache/lucene/index/IndexDocument.java | 1 + .../src/java/org/apache/lucene/index/StorableField.java | 5 +++++ .../src/java/org/apache/lucene/index/StorableFieldType.java | 6 ++++++ .../src/java/org/apache/lucene/index/StoredDocument.java | 4 ++++ 5 files changed, 21 insertions(+) diff --git a/lucene/core/src/java/org/apache/lucene/index/GeneralField.java b/lucene/core/src/java/org/apache/lucene/index/GeneralField.java index f436c013250..cb07f037ba8 100644 --- a/lucene/core/src/java/org/apache/lucene/index/GeneralField.java +++ b/lucene/core/src/java/org/apache/lucene/index/GeneralField.java @@ -17,6 +17,11 @@ package org.apache.lucene.index; * limitations under the License. */ +/** Represents a single field in lucene document. Further generalizations + * are {@link IndexableField} and {@link StorableField} interfaces. + * + * @lucene.experimental */ + public interface GeneralField { /** Field name */ diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java b/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java index fa3a0a4168b..b8bde65a457 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexDocument.java @@ -18,6 +18,7 @@ package org.apache.lucene.index; */ /** + * Elementary interface used for indexing an document. * @lucene.internal */ public interface IndexDocument { diff --git a/lucene/core/src/java/org/apache/lucene/index/StorableField.java b/lucene/core/src/java/org/apache/lucene/index/StorableField.java index 27dda40b515..136fd171d0a 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StorableField.java +++ b/lucene/core/src/java/org/apache/lucene/index/StorableField.java @@ -21,6 +21,11 @@ import java.io.Reader; import org.apache.lucene.util.BytesRef; +/** Represents a single stored field in lucene document. These fields + * are contained in document retrieved from IndexReader. + * + * @lucene.experimental */ + public interface StorableField extends GeneralField { /** Non-null if this field has a binary value */ diff --git a/lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java b/lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java index 9aa7eac0127..a9483879cbe 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java +++ b/lucene/core/src/java/org/apache/lucene/index/StorableFieldType.java @@ -17,6 +17,12 @@ package org.apache.lucene.index; * limitations under the License. */ +// TODO: Move some properties from IndexableFieldType here, those regarding stored fields. + +/** + * Describes the properties of a stored field. + * @lucene.experimental + */ public interface StorableFieldType { /** DocValues type; if non-null then the field's value diff --git a/lucene/core/src/java/org/apache/lucene/index/StoredDocument.java b/lucene/core/src/java/org/apache/lucene/index/StoredDocument.java index 2ff6970e11b..50b06e79b62 100644 --- a/lucene/core/src/java/org/apache/lucene/index/StoredDocument.java +++ b/lucene/core/src/java/org/apache/lucene/index/StoredDocument.java @@ -30,8 +30,12 @@ import org.apache.lucene.document.FloatField; import org.apache.lucene.document.IntField; import org.apache.lucene.document.LongField; import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.util.BytesRef; +/** +* StoredDocument is retrieved from IndexReader containing only stored fields from indexed {@link IndexDocument}. +*/ public class StoredDocument implements Iterable{ private final List fields = new ArrayList(); From c58c87b7438a68985c2c4716b20137d3335530d9 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sat, 25 Aug 2012 11:06:09 +0000 Subject: [PATCH 11/13] LUCENE-3312: inline Iterator and don't clone into ArrayList. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1377263 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/document/Document.java | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/document/Document.java b/lucene/core/src/java/org/apache/lucene/document/Document.java index 95cf80598ac..f9ec493cd3c 100644 --- a/lucene/core/src/java/org/apache/lucene/document/Document.java +++ b/lucene/core/src/java/org/apache/lucene/document/Document.java @@ -45,8 +45,6 @@ import org.apache.lucene.util.FilterIterator; public final class Document implements IndexDocument{ private final List fields = new ArrayList(); - - //private final List fields /** Constructs a new document with no fields. */ public Document() {} @@ -291,28 +289,24 @@ public final class Document implements IndexDocument{ /** Obtains all indexed fields in document */ @Override public Iterable indexableFields() { - Iterator it = indexedFieldsIterator(); - - List result = new ArrayList(); - while(it.hasNext()) { - result.add(it.next()); - } - - return result; + return new Iterable() { + @Override + public Iterator iterator() { + return Document.this.indexedFieldsIterator(); + } + }; } /** Obtains all stored fields in document. */ @Override public Iterable storableFields() { - Iterator it = storedFieldsIterator(); - - List result = new ArrayList(); - while(it.hasNext()) { - result.add(it.next()); - } - - return result; + return new Iterable() { + @Override + public Iterator iterator() { + return Document.this.storedFieldsIterator(); + } + }; } private Iterator storedFieldsIterator() { From 9e19c170943c9d088148871f2e23c07d8ea777b8 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Thu, 30 Aug 2012 22:58:33 +0000 Subject: [PATCH 12/13] LUCENE-3312: Fix incorrect JavaDocs git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1379207 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/document/StoredField.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/document/StoredField.java b/lucene/core/src/java/org/apache/lucene/document/StoredField.java index 95e536a13af..d0fc08d15cc 100644 --- a/lucene/core/src/java/org/apache/lucene/document/StoredField.java +++ b/lucene/core/src/java/org/apache/lucene/document/StoredField.java @@ -38,11 +38,10 @@ public class StoredField extends Field { } /** - * Create a stored-only field with the given binary value. - *

      NOTE: the provided byte[] is not copied so be sure - * not to change it until you're done with this field. + * Expert: allows you to customize the {@link + * FieldType}. * @param name field name - * @param value byte array pointing to binary content (not copied) + * @param type custom {@link FieldType} for this field * @throws IllegalArgumentException if the field name is null. */ protected StoredField(String name, FieldType type) { @@ -55,7 +54,7 @@ public class StoredField extends Field { *

      NOTE: the provided byte[] is not copied so be sure * not to change it until you're done with this field. * @param name field name - * @param value byte array pointing to binary content (not copied) + * @param bytes byte array pointing to binary content (not copied) * @param type custom {@link FieldType} for this field * @throws IllegalArgumentException if the field name is null. */ @@ -63,6 +62,14 @@ public class StoredField extends Field { super(name, bytes, type); } + /** + * Create a stored-only field with the given binary value. + *

      NOTE: the provided byte[] is not copied so be sure + * not to change it until you're done with this field. + * @param name field name + * @param value byte array pointing to binary content (not copied) + * @throws IllegalArgumentException if the field name is null. + */ public StoredField(String name, byte[] value) { super(name, value, TYPE); } @@ -103,6 +110,14 @@ public class StoredField extends Field { super(name, value, TYPE); } + /** + * Expert: allows you to customize the {@link + * FieldType}. + * @param name field name + * @param value string value + * @param type custom {@link FieldType} for this field + * @throws IllegalArgumentException if the field name or value is null. + */ public StoredField(String name, String value, FieldType type) { super(name, value, type); } From 0b3b1fa69ee8a2ec866176446aee5c42397dd2b5 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sun, 2 Sep 2012 11:26:32 +0000 Subject: [PATCH 13/13] LUCENE-3312: Add Robert's warning back. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3312@1379945 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/document/DocumentStoredFieldVisitor.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 111fd258abe..5f566c58be6 100644 --- a/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java +++ b/lucene/core/src/java/org/apache/lucene/document/DocumentStoredFieldVisitor.java @@ -99,7 +99,10 @@ public class DocumentStoredFieldVisitor extends StoredFieldVisitor { /** * Retrieve the visited document. - * @return StoredDocument populated with stored fields. + * @return {@link StoredDocument} populated with stored fields. Note that only + * the stored information in the field instances is valid, + * data such as indexing options, term vector options, + * etc is not set. */ public StoredDocument getDocument() { return doc;