diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 51b98ee1511..686cbfceeb1 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -6,6 +6,16 @@ http://s.apache.org/luceneversions
======================= Lucene 5.0.0 =======================
+Changes in backwards compatibility policy
+
+* LUCENE-3312: The API of oal.document was restructured to
+ differentiate between stored documents and indexed documents.
+ IndexReader.document(int) now returns StorableDocument
+ instead of Document. In most cases a simple replacement
+ of the return type is enough to upgrade (see MIGRATE.txt).
+ (Nikola Tanković, Uwe Schindler, Chris Male, Mike McCandless,
+ Robert Muir)
+
======================= Lucene 4.0.0 =======================
New Features
diff --git a/lucene/MIGRATE.txt b/lucene/MIGRATE.txt
index a8120f38a75..88e74530d52 100644
--- a/lucene/MIGRATE.txt
+++ b/lucene/MIGRATE.txt
@@ -1,3 +1,8 @@
# Apache Lucene Migration Guide
-TODO: Lucene 5.0 currently has no migration guide.
\ No newline at end of file
+## Separation of IndexDocument and StoredDocument (LUCENE-3312)
+
+The API of oal.document was restructured to differentiate between stored
+documents and indexed documents. IndexReader.document(int) now returns
+StorableDocument instead of Document. In most cases a simple replacement
+of the return type is enough to upgrade.
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 6961e15dbbc..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
@@ -25,6 +25,7 @@ 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;
@@ -79,7 +80,7 @@ public class UIMABaseAnalyzerTest extends BaseTokenStreamTestCase {
IndexSearcher indexSearcher = new IndexSearcher(directoryReader);
TopDocs result = indexSearcher.search(new MatchAllDocsQuery(), 1);
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());
@@ -99,7 +100,7 @@ public class UIMABaseAnalyzerTest extends BaseTokenStreamTestCase {
directoryReader = DirectoryReader.open(dir);
indexSearcher = new IndexSearcher(directoryReader);
result = indexSearcher.search(new MatchAllDocsQuery(), 2);
- 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 94014279243..5e471b18884 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,11 +226,12 @@ 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);
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..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
@@ -20,11 +20,12 @@ package org.apache.lucene.benchmark.byTask.tasks;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.StoredDocument;
/**
* Abstract class for benchmarking highlighting performance
*/
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..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
@@ -32,6 +32,8 @@ 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;
@@ -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;i
- 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/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..3541da80e5b 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/StoredFieldsWriter.java @@ -19,13 +19,13 @@ package org.apache.lucene.codecs; 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: @@ -33,7 +33,7 @@ import org.apache.lucene.util.Bits; *
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 +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, IndexableField)}, and {@link #finish(FieldInfos, 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). */
@@ -89,7 +89,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 +100,16 @@ public abstract class StoredFieldsWriter implements Closeable {
}
/** sugar method for startDocument() + writeField() for every stored field in the document */
- protected final void addDocument(Iterable extends IndexableField> doc, FieldInfos fieldInfos) throws IOException {
+ protected final void addDocument(Iterable extends StorableField> 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 fa9099386f7..3e5a0a09e28 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
@@ -29,6 +29,8 @@ 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.index.StoredDocument;
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 8b533f368be..5613d8e97a2 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 557d21ebe36..4f2765342d0 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 076af30f530..74e2142da2b 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 {
/**
* Type for 8-bit byte DocValues.
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 bc846a443fe..98755d63673 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!?
/**
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..762f2499fcf 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,15 @@ 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.index.StoredDocument;
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;
/** Documents are the unit of indexing and search.
*
@@ -38,18 +42,36 @@ import org.apache.lucene.util.BytesRef;
* ScoreDoc#doc} or {@link IndexReader#document(int)}.
*/
-public final class Document implements IterableAdds 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 +82,7 @@ public final class Document implements Iterable
byte[]
containing the binary field value or null
*/
public final BytesRef getBinaryValue(String name) {
- for (IndexableField field : fields) {
+ IteratorFieldable[]
array
*/
- public IndexableField[] getFields(String name) {
- ListList[Field]
*/
- public final ListSet<String>
. */
@@ -68,7 +69,7 @@ public class DocumentStoredFieldVisitor extends StoredFieldVisitor {
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, ft));
}
@Override
@@ -98,12 +99,12 @@ public class DocumentStoredFieldVisitor extends StoredFieldVisitor {
/**
* Retrieve the visited document.
- * @return Document populated with stored fields. Note that only
+ * @return {@link StoredDocument} populated with stored fields. Note that only
* the stored information in the field instances is valid,
- * data such as boosts, indexing options, term vector options,
+ * data such as indexing options, term vector options,
* etc is not set.
*/
- 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 bb4d1f57187..6b21cf3dffd 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 {
/**
* Type for 64-bit double DocValues.
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 2a2ec60201c..011187dca33 100644
--- a/lucene/core/src/java/org/apache/lucene/document/Field.java
+++ b/lucene/core/src/java/org/apache/lucene/document/Field.java
@@ -30,6 +30,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
@@ -58,12 +59,13 @@ 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 {
/**
* Field's type
*/
protected final FieldType type;
+
/**
* Field's 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 a47641116b1..8f4b6c90fb8 100644
--- a/lucene/core/src/java/org/apache/lucene/document/FieldType.java
+++ b/lucene/core/src/java/org/apache/lucene/document/FieldType.java
@@ -27,7 +27,7 @@ import org.apache.lucene.util.NumericUtils;
/**
* Describes the properties of a field.
*/
-public class FieldType implements IndexableFieldType {
+public class FieldType implements IndexableFieldType {
/** Data type of the numeric value
* @since 3.2
@@ -52,10 +52,10 @@ public class FieldType implements IndexableFieldType {
private boolean storeTermVectorPayloads;
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;
/**
* Create a new mutable FieldType with all of the properties from ref
@@ -299,29 +299,6 @@ public class FieldType implements IndexableFieldType {
this.indexOptions = value;
}
- /**
- * Set's the field's DocValues.Type
- * @param type DocValues type, or null if no DocValues should be stored.
- * @throws IllegalStateException if this FieldType is frozen against
- * future modifications.
- * @see #docValueType()
- */
- public void setDocValueType(DocValues.Type type) {
- checkIfFrozen();
- docValueType = type;
- }
-
- /**
- * {@inheritDoc}
- *
- * The default is null
(no docValues)
- * @see #setDocValueType(DocValues.Type)
- */
- @Override
- public DocValues.Type docValueType() {
- return docValueType;
- }
-
/**
* Specifies the field's numeric type.
* @param type numeric type, or null if the field has no numeric type.
@@ -423,4 +400,30 @@ public class FieldType implements IndexableFieldType {
return result.toString();
}
+
+ /* from StorableFieldType */
+
+ /**
+ * {@inheritDoc}
+ *
+ * The default is null
(no docValues)
+ * @see #setDocValueType(DocValues.Type)
+ */
+ @Override
+ public DocValues.Type docValueType() {
+ return docValueType;
+ }
+
+ /**
+ * Set's the field's DocValues.Type
+ * @param type DocValues type, or null if no DocValues should be stored.
+ * @throws IllegalStateException if this FieldType is frozen against
+ * future modifications.
+ * @see #docValueType()
+ */
+ public void setDocValueType(DocValues.Type type) {
+ checkIfFrozen();
+ docValueType = type;
+ this.stored = true;
+ }
}
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 dd4f1c20d6a..bf66370ef9b 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 {
/**
* Type for 32-bit float DocValues.
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 28914bce434..a06012cdb44 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 {
/**
* Type for 32-bit integer DocValues.
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 e3484bd60a7..e0233318aa7 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 {
/**
* Type for 64-bit long DocValues.
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 8d3f2ba652f..93908dd15a2 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 {
/**
* Type for packed long DocValues.
@@ -47,6 +47,7 @@ public class PackedLongDocValuesField extends Field {
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/ShortDocValuesField.java b/lucene/core/src/java/org/apache/lucene/document/ShortDocValuesField.java
index 45dafc99664..cb338766083 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 {
/**
* Type for 16-bit short DocValues.
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 594e26da733..a5ec57bff70 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!?
/**
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 6ffa81a8cce..d0fc08d15cc 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;
@@ -24,7 +25,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 {
/**
* Type for a stored-only field.
@@ -36,6 +37,31 @@ public final class StoredField extends Field {
TYPE.freeze();
}
+ /**
+ * Expert: allows you to customize the {@link
+ * FieldType}.
+ * @param name field name
+ * @param type custom {@link FieldType} for this field
+ * @throws IllegalArgumentException if the field name is null.
+ */
+ protected StoredField(String name, FieldType type) {
+ super(name, type);
+ }
+
+ /**
+ * Expert: allows you to customize the {@link
+ * FieldType}.
+ *
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 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. + */ + public StoredField(String name, BytesRef bytes, FieldType type) { + super(name, bytes, type); + } + /** * Create a stored-only field with the given binary value. *
NOTE: the provided byte[] is not copied so be sure
@@ -83,6 +109,18 @@ public final class StoredField extends Field {
public StoredField(String name, String value) {
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);
+ }
// TODO: not great but maybe not a big problem?
/**
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 cdca59b1c9e..f93d6b3e290 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!?
/**
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 0daf83d1f07..f964aa5d654 100644
--- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
+++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
@@ -1180,7 +1180,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..0853ed3b5eb 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;
@@ -218,58 +219,21 @@ 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();
+ 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();
- if (field.fieldType().stored()) {
- fieldsWriter.addField(field, fp.fieldInfo);
- }
+ DocFieldProcessorPerField fp = processField(fieldInfos, thisFieldGen, fieldName, ft);
+ fieldsWriter.addField(field, fp.fieldInfo);
+
final DocValues.Type dvType = field.fieldType().docValueType();
if (dvType != null) {
DocValuesConsumerHolder docValuesConsumer = docValuesConsumer(dvType,
@@ -313,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
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.
@@ -1099,7 +1099,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 extends IndexableField> doc) throws IOException { + public void addDocument(IndexDocument doc) throws IOException { addDocument(doc, analyzer); } @@ -1107,7 +1107,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.
* @@ -1118,7 +1118,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 extends IndexableField> doc, Analyzer analyzer) throws IOException { + public void addDocument(IndexDocument doc, Analyzer analyzer) throws IOException { updateDocument(null, doc, analyzer); } @@ -1143,7 +1143,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.
* @@ -1163,7 +1163,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * * @lucene.experimental */ - public void addDocuments(Iterable extends Iterable extends IndexableField>> docs) throws IOException { + public void addDocuments(Iterable extends IndexDocument> docs) throws IOException { addDocuments(docs, analyzer); } @@ -1178,7 +1178,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * * @lucene.experimental */ - public void addDocuments(Iterable extends Iterable extends IndexableField>> docs, Analyzer analyzer) throws IOException { + public void addDocuments(Iterable extends IndexDocument> docs, Analyzer analyzer) throws IOException { updateDocuments(null, docs, analyzer); } @@ -1195,7 +1195,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * * @lucene.experimental */ - public void updateDocuments(Term delTerm, Iterable extends Iterable extends IndexableField>> docs) throws IOException { + public void updateDocuments(Term delTerm, Iterable extends IndexDocument> docs) throws IOException { updateDocuments(delTerm, docs, analyzer); } @@ -1213,7 +1213,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { * * @lucene.experimental */ - public void updateDocuments(Term delTerm, Iterable extends Iterable extends IndexableField>> docs, Analyzer analyzer) throws IOException { + public void updateDocuments(Term delTerm, Iterable extends IndexDocument> docs, Analyzer analyzer) throws IOException { ensureOpen(); try { boolean success = false; @@ -1410,7 +1410,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 extends IndexableField> doc) throws IOException { + public void updateDocument(Term term, IndexDocument doc) throws IOException { ensureOpen(); updateDocument(term, doc, getAnalyzer()); } @@ -1433,7 +1433,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 extends IndexableField> 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 2df6f009a28..062dc8c427a 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexableField.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexableField.java @@ -35,15 +35,19 @@ import org.apache.lucene.util.BytesRef; * * @lucene.experimental */ -public interface IndexableField { +public interface IndexableField extends GeneralField { - /** Field name */ - public String name(); + /** + * Creates the TokenStream used for indexing this field. If appropriate, + * implementations should use the given Analyzer to create the TokenStreams. + * + * @param analyzer Analyzer that should be used to create the TokenStreams from + * @return TokenStream value for indexing the document. Should always return + * a non-null value if the field is to be indexed + * @throws IOException Can be thrown while creating the TokenStream + */ + public TokenStream tokenStream(Analyzer analyzer) throws IOException; - /** {@link IndexableFieldType} describing the properties - * of this field. */ - public IndexableFieldType fieldType(); - /** * Returns the field's index-time boost. *
@@ -65,27 +69,4 @@ public interface IndexableField {
* @see DefaultSimilarity#encodeNormValue(float)
*/
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,
- * implementations should use the given Analyzer to create the TokenStreams.
- *
- * @param analyzer Analyzer that should be used to create the TokenStreams from
- * @return TokenStream value for indexing the document. Should always return
- * a non-null value if the field is to be indexed
- * @throws IOException Can be thrown while creating the TokenStream
- */
- public TokenStream tokenStream(Analyzer analyzer) throws IOException;
}
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 91f2efe756f..6a7243135e8 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexableFieldType.java
@@ -31,7 +31,7 @@ public interface IndexableFieldType {
/** True if the field's value should be stored */
public boolean stored();
-
+
/**
* True if this field's value should be analyzed by the
* {@link Analyzer}.
@@ -95,5 +95,5 @@ public interface IndexableFieldType {
* DocValues {@link DocValues.Type}: if non-null then the field's value
* will be indexed into docValues.
*/
- public DocValues.Type docValueType();
+ 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..8baecffa124 100644
--- a/lucene/core/src/java/org/apache/lucene/index/Norm.java
+++ b/lucene/core/src/java/org/apache/lucene/index/Norm.java
@@ -26,13 +26,14 @@ 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;
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
@@ -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
+ * Returns the {@link StorableField} representation for this norm
*/
- public IndexableField field() {
+ public StorableField 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..a936c3722b5 100644
--- a/lucene/core/src/java/org/apache/lucene/index/NormsConsumerPerField.java
+++ b/lucene/core/src/java/org/apache/lucene/index/NormsConsumerPerField.java
@@ -51,7 +51,7 @@ 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);
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..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,6 +26,7 @@ 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.StoredField;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Version;
@@ -67,13 +68,13 @@ 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) {
- snapshots.put(f.name(), f.stringValue());
+ for (StorableField f : doc) {
+ if (!f.name().equals(SNAPSHOTS_ID))
+ snapshots.put(f.name(), f.stringValue());
}
} else if (numDocs != 0) {
throw new IllegalStateException(
@@ -184,14 +185,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 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 Listbyte[][]
of binary field values
+ */
+ public final BytesRef[] getBinaryValues(String name) {
+ final Listnull
+ * 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.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