From c649d9a977b4ea100df4d9d1fe18d5c12c07ae8d Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 7 Dec 2011 00:19:04 +0000 Subject: [PATCH 01/19] git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1211241 13f79535-47bb-0310-9956-ffa450edef68 From 249f3c2ee98cf25e2e21ea776766354d777d1260 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 7 Dec 2011 00:21:20 +0000 Subject: [PATCH 02/19] LUCENE-3622: move 4.0 IndexDocValues impl classes underneath Lucene40Codec git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1211242 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/index/codecs/DocValuesConsumer.java | 3 +-- .../lucene/index/codecs/DocValuesReaderBase.java | 6 +++--- .../lucene/index/codecs/DocValuesWriterBase.java | 2 +- .../index/{ => codecs/lucene40}/values/Bytes.java | 5 ++++- .../lucene40}/values/BytesRefUtils.java | 4 ++-- .../lucene40}/values/FixedDerefBytesImpl.java | 10 ++++++---- .../lucene40}/values/FixedSortedBytesImpl.java | 14 ++++++++------ .../lucene40}/values/FixedStraightBytesImpl.java | 10 ++++++---- .../index/{ => codecs/lucene40}/values/Floats.java | 5 ++++- .../lucene40}/values/IndexDocValuesArray.java | 3 ++- .../index/{ => codecs/lucene40}/values/Ints.java | 5 ++++- .../lucene40}/values/PackedIntValues.java | 9 ++++++--- .../lucene40}/values/SortedBytesMergeUtils.java | 4 +++- .../lucene40}/values/VarDerefBytesImpl.java | 10 ++++++---- .../lucene40}/values/VarSortedBytesImpl.java | 14 ++++++++------ .../lucene40}/values/VarStraightBytesImpl.java | 10 ++++++---- .../index/{ => codecs/lucene40}/values/Writer.java | 3 ++- .../index/codecs/sep/SepDocValuesConsumer.java | 2 +- .../apache/lucene/index/values/DirectSource.java | 4 ++-- .../apache/lucene/index/values/TestDocValues.java | 4 ++++ .../lucene/index/values/TestTypePromotion.java | 1 + 21 files changed, 80 insertions(+), 48 deletions(-) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/Bytes.java (98%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/BytesRefUtils.java (97%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/FixedDerefBytesImpl.java (91%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/FixedSortedBytesImpl.java (92%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/FixedStraightBytesImpl.java (96%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/Floats.java (95%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/IndexDocValuesArray.java (98%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/Ints.java (95%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/PackedIntValues.java (95%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/SortedBytesMergeUtils.java (98%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/VarDerefBytesImpl.java (92%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/VarSortedBytesImpl.java (93%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/VarStraightBytesImpl.java (96%) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/Writer.java (98%) diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java index 42dda323996..88a1283ce67 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java @@ -23,7 +23,6 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.MergeState; import org.apache.lucene.index.values.IndexDocValues; import org.apache.lucene.index.values.PerDocFieldValues; -import org.apache.lucene.index.values.Writer; import org.apache.lucene.util.Bits; import org.apache.lucene.util.Counter; @@ -106,7 +105,7 @@ public abstract class DocValuesConsumer { final org.apache.lucene.index.MergeState.IndexReaderAndLiveDocs reader = mergeState.readers.get(readerIDX); if (docValues[readerIDX] != null) { hasMerged = true; - merge(new Writer.SingleSubMergeState(docValues[readerIDX], mergeState.docBase[readerIDX], reader.reader.maxDoc(), + merge(new SingleSubMergeState(docValues[readerIDX], mergeState.docBase[readerIDX], reader.reader.maxDoc(), reader.liveDocs)); } } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java index 1b3e8661098..5ade60eddb3 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java @@ -26,10 +26,10 @@ import java.util.TreeMap; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; -import org.apache.lucene.index.values.Bytes; -import org.apache.lucene.index.values.Floats; +import org.apache.lucene.index.codecs.lucene40.values.Bytes; +import org.apache.lucene.index.codecs.lucene40.values.Floats; +import org.apache.lucene.index.codecs.lucene40.values.Ints; import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.Ints; import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java index 619b1241857..e238f4cea27 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java @@ -22,7 +22,7 @@ import java.util.Comparator; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.PerDocWriteState; -import org.apache.lucene.index.values.Writer; +import org.apache.lucene.index.codecs.lucene40.values.Writer; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.util.BytesRef; diff --git a/lucene/src/java/org/apache/lucene/index/values/Bytes.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java similarity index 98% rename from lucene/src/java/org/apache/lucene/index/values/Bytes.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java index c0b07291e2d..72764cbb2fa 100644 --- a/lucene/src/java/org/apache/lucene/index/values/Bytes.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -24,6 +24,9 @@ import java.util.Comparator; import java.util.concurrent.atomic.AtomicLong; import org.apache.lucene.index.IndexFileNames; +import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.values.PerDocFieldValues; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.index.values.IndexDocValues.SortedSource; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.DataOutput; diff --git a/lucene/src/java/org/apache/lucene/index/values/BytesRefUtils.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/BytesRefUtils.java similarity index 97% rename from lucene/src/java/org/apache/lucene/index/values/BytesRefUtils.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/BytesRefUtils.java index f2c5b376d37..d0a2b9021a0 100644 --- a/lucene/src/java/org/apache/lucene/index/values/BytesRefUtils.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/BytesRefUtils.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -25,7 +25,7 @@ import org.apache.lucene.util.BytesRef; * * @lucene.internal */ -final class BytesRefUtils { +public final class BytesRefUtils { private BytesRefUtils() { } diff --git a/lucene/src/java/org/apache/lucene/index/values/FixedDerefBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedDerefBytesImpl.java similarity index 91% rename from lucene/src/java/org/apache/lucene/index/values/FixedDerefBytesImpl.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedDerefBytesImpl.java index 3c20fd32c30..31efc70e139 100644 --- a/lucene/src/java/org/apache/lucene/index/values/FixedDerefBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedDerefBytesImpl.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -19,9 +19,11 @@ package org.apache.lucene.index.values; import java.io.IOException; -import org.apache.lucene.index.values.Bytes.BytesReaderBase; -import org.apache.lucene.index.values.Bytes.BytesSourceBase; -import org.apache.lucene.index.values.Bytes.DerefBytesWriterBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; +import org.apache.lucene.index.values.DirectSource; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; diff --git a/lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java similarity index 92% rename from lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java index 08fdf94fd9f..b6726d22b4d 100644 --- a/lucene/src/java/org/apache/lucene/index/values/FixedSortedBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -22,12 +22,14 @@ import java.util.Comparator; import java.util.List; import org.apache.lucene.index.MergeState; -import org.apache.lucene.index.values.Bytes.BytesReaderBase; -import org.apache.lucene.index.values.Bytes.BytesSortedSourceBase; -import org.apache.lucene.index.values.Bytes.DerefBytesWriterBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSortedSourceBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; +import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.MergeContext; +import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.SortedSourceSlice; +import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.index.values.IndexDocValues.SortedSource; -import org.apache.lucene.index.values.SortedBytesMergeUtils.MergeContext; -import org.apache.lucene.index.values.SortedBytesMergeUtils.SortedSourceSlice; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; diff --git a/lucene/src/java/org/apache/lucene/index/values/FixedStraightBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedStraightBytesImpl.java similarity index 96% rename from lucene/src/java/org/apache/lucene/index/values/FixedStraightBytesImpl.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedStraightBytesImpl.java index b19fab42675..8562923a6ba 100644 --- a/lucene/src/java/org/apache/lucene/index/values/FixedStraightBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedStraightBytesImpl.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -21,10 +21,12 @@ import static org.apache.lucene.util.ByteBlockPool.BYTE_BLOCK_SIZE; import java.io.IOException; -import org.apache.lucene.index.values.Bytes.BytesSourceBase; -import org.apache.lucene.index.values.Bytes.BytesReaderBase; -import org.apache.lucene.index.values.Bytes.BytesWriterBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesWriterBase; import org.apache.lucene.index.values.DirectSource; +import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; diff --git a/lucene/src/java/org/apache/lucene/index/values/Floats.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Floats.java similarity index 95% rename from lucene/src/java/org/apache/lucene/index/values/Floats.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Floats.java index fee1364d443..4f9e1c45aad 100644 --- a/lucene/src/java/org/apache/lucene/index/values/Floats.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Floats.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -18,6 +18,9 @@ package org.apache.lucene.index.values; */ import java.io.IOException; +import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.values.PerDocFieldValues; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; diff --git a/lucene/src/java/org/apache/lucene/index/values/IndexDocValuesArray.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/IndexDocValuesArray.java similarity index 98% rename from lucene/src/java/org/apache/lucene/index/values/IndexDocValuesArray.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/IndexDocValuesArray.java index 3c2f4f5d87d..e1180c14089 100644 --- a/lucene/src/java/org/apache/lucene/index/values/IndexDocValuesArray.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/IndexDocValuesArray.java @@ -1,10 +1,11 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; import java.io.IOException; import java.util.Collections; import java.util.EnumMap; import java.util.Map; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.BytesRef; diff --git a/lucene/src/java/org/apache/lucene/index/values/Ints.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Ints.java similarity index 95% rename from lucene/src/java/org/apache/lucene/index/values/Ints.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Ints.java index d8fc6fb1183..b4d7deb3913 100644 --- a/lucene/src/java/org/apache/lucene/index/values/Ints.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Ints.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -19,6 +19,9 @@ package org.apache.lucene.index.values; import java.io.IOException; +import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.values.PerDocFieldValues; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; diff --git a/lucene/src/java/org/apache/lucene/index/values/PackedIntValues.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/PackedIntValues.java similarity index 95% rename from lucene/src/java/org/apache/lucene/index/values/PackedIntValues.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/PackedIntValues.java index f147e747f80..54f3f6ce2c3 100644 --- a/lucene/src/java/org/apache/lucene/index/values/PackedIntValues.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/PackedIntValues.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -19,9 +19,12 @@ package org.apache.lucene.index.values; import java.io.IOException; import org.apache.lucene.index.IndexFileNames; -import org.apache.lucene.index.values.FixedStraightBytesImpl.FixedBytesWriterBase; +import org.apache.lucene.index.codecs.lucene40.values.FixedStraightBytesImpl.FixedBytesWriterBase; +import org.apache.lucene.index.codecs.lucene40.values.IndexDocValuesArray.LongValues; +import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.values.PerDocFieldValues; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.index.values.IndexDocValues.Source; -import org.apache.lucene.index.values.IndexDocValuesArray.LongValues; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; diff --git a/lucene/src/java/org/apache/lucene/index/values/SortedBytesMergeUtils.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/SortedBytesMergeUtils.java similarity index 98% rename from lucene/src/java/org/apache/lucene/index/values/SortedBytesMergeUtils.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/SortedBytesMergeUtils.java index e9b2130e2d6..8a32e6aee64 100644 --- a/lucene/src/java/org/apache/lucene/index/values/SortedBytesMergeUtils.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/SortedBytesMergeUtils.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -24,6 +24,8 @@ import java.util.List; import org.apache.lucene.index.MergeState; import org.apache.lucene.index.MergeState.IndexReaderAndLiveDocs; +import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.index.values.IndexDocValues.SortedSource; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.IndexOutput; diff --git a/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarDerefBytesImpl.java similarity index 92% rename from lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarDerefBytesImpl.java index c7e6a6320e7..63443ea18a9 100644 --- a/lucene/src/java/org/apache/lucene/index/values/VarDerefBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarDerefBytesImpl.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -19,9 +19,11 @@ package org.apache.lucene.index.values; import java.io.IOException; -import org.apache.lucene.index.values.Bytes.BytesReaderBase; -import org.apache.lucene.index.values.Bytes.BytesSourceBase; -import org.apache.lucene.index.values.Bytes.DerefBytesWriterBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; +import org.apache.lucene.index.values.DirectSource; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; diff --git a/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java similarity index 93% rename from lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java index ac58a08b074..173fa08877e 100644 --- a/lucene/src/java/org/apache/lucene/index/values/VarSortedBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -22,12 +22,14 @@ import java.util.Comparator; import java.util.List; import org.apache.lucene.index.MergeState; -import org.apache.lucene.index.values.Bytes.BytesSortedSourceBase; -import org.apache.lucene.index.values.Bytes.BytesReaderBase; -import org.apache.lucene.index.values.Bytes.DerefBytesWriterBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSortedSourceBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; +import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.MergeContext; +import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.SortedSourceSlice; +import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.index.values.IndexDocValues.SortedSource; -import org.apache.lucene.index.values.SortedBytesMergeUtils.MergeContext; -import org.apache.lucene.index.values.SortedBytesMergeUtils.SortedSourceSlice; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; diff --git a/lucene/src/java/org/apache/lucene/index/values/VarStraightBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarStraightBytesImpl.java similarity index 96% rename from lucene/src/java/org/apache/lucene/index/values/VarStraightBytesImpl.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarStraightBytesImpl.java index 88f6c537b81..7ac7a931192 100644 --- a/lucene/src/java/org/apache/lucene/index/values/VarStraightBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarStraightBytesImpl.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -19,9 +19,11 @@ package org.apache.lucene.index.values; import java.io.IOException; -import org.apache.lucene.index.values.Bytes.BytesReaderBase; -import org.apache.lucene.index.values.Bytes.BytesSourceBase; -import org.apache.lucene.index.values.Bytes.BytesWriterBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; +import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesWriterBase; +import org.apache.lucene.index.values.DirectSource; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; diff --git a/lucene/src/java/org/apache/lucene/index/values/Writer.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Writer.java similarity index 98% rename from lucene/src/java/org/apache/lucene/index/values/Writer.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Writer.java index 000486a6b2b..53173fc3fdc 100644 --- a/lucene/src/java/org/apache/lucene/index/values/Writer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Writer.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.Comparator; import org.apache.lucene.index.codecs.DocValuesConsumer; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesConsumer.java index 8a387a24cae..43817ab3de3 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesConsumer.java @@ -26,7 +26,7 @@ import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.codecs.DocValuesWriterBase; -import org.apache.lucene.index.values.Writer; +import org.apache.lucene.index.codecs.lucene40.values.Writer; import org.apache.lucene.store.Directory; /** diff --git a/lucene/src/java/org/apache/lucene/index/values/DirectSource.java b/lucene/src/java/org/apache/lucene/index/values/DirectSource.java index b7d71ad3a9f..133f64ced14 100644 --- a/lucene/src/java/org/apache/lucene/index/values/DirectSource.java +++ b/lucene/src/java/org/apache/lucene/index/values/DirectSource.java @@ -27,13 +27,13 @@ import org.apache.lucene.util.BytesRef; * Base class for disk resident source implementations * @lucene.internal */ -abstract class DirectSource extends Source { +public abstract class DirectSource extends Source { protected final IndexInput data; private final ToNumeric toNumeric; protected final long baseOffset; - DirectSource(IndexInput input, ValueType type) { + public DirectSource(IndexInput input, ValueType type) { super(type); this.data = input; baseOffset = input.getFilePointer(); diff --git a/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java b/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java index 14cd8c76499..0c326655f7e 100644 --- a/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java +++ b/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java @@ -20,6 +20,10 @@ package org.apache.lucene.index.values; import java.io.IOException; import java.util.Comparator; +import org.apache.lucene.index.codecs.lucene40.values.Bytes; +import org.apache.lucene.index.codecs.lucene40.values.Floats; +import org.apache.lucene.index.codecs.lucene40.values.Ints; +import org.apache.lucene.index.codecs.lucene40.values.Writer; import org.apache.lucene.index.values.IndexDocValues.SortedSource; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.Directory; diff --git a/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java b/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java index 0ac16019870..70e615298d2 100644 --- a/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java +++ b/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java @@ -16,6 +16,7 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.NoMergePolicy; import org.apache.lucene.index.codecs.Codec; +import org.apache.lucene.index.codecs.lucene40.values.BytesRefUtils; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; From 218f7ae1dd479c719f541bb0cb25246e77e2f78c Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 7 Dec 2011 00:31:27 +0000 Subject: [PATCH 03/19] LUCENE-3622: remove unused method/dead code git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1211244 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/index/codecs/DocValuesConsumer.java | 9 --------- .../lucene/index/codecs/lucene40/values/Bytes.java | 13 ------------- 2 files changed, 22 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java index 88a1283ce67..caf509a7f24 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java @@ -17,7 +17,6 @@ package org.apache.lucene.index.codecs; * limitations under the License. */ import java.io.IOException; -import java.util.Collection; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.MergeState; @@ -78,14 +77,6 @@ public abstract class DocValuesConsumer { */ public abstract void finish(int docCount) throws IOException; - /** - * Gathers files associated with this {@link DocValuesConsumer} - * - * @param files - * the of files to add the consumers files to. - */ - public abstract void files(Collection files) throws IOException; - /** * Merges the given {@link org.apache.lucene.index.MergeState} into * this {@link DocValuesConsumer}. diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java index 72764cbb2fa..4a4ff759af7 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java @@ -19,7 +19,6 @@ package org.apache.lucene.index.codecs.lucene40.values; /** Base class for specific Bytes Reader/Writer implementations */ import java.io.IOException; -import java.util.Collection; import java.util.Comparator; import java.util.concurrent.atomic.AtomicLong; @@ -309,18 +308,6 @@ public final class Bytes { add(docID, ref); } } - - @Override - public void files(Collection files) throws IOException { - assert datOut != null; - files.add(IndexFileNames.segmentFileName(id, DV_SEGMENT_SUFFIX, DATA_EXTENSION)); - if (idxOut != null) { // called after flush - so this must be initialized - // if needed or present - final String idxFile = IndexFileNames.segmentFileName(id, DV_SEGMENT_SUFFIX, - INDEX_EXTENSION); - files.add(idxFile); - } - } } /** From fd3aca000099629cb69362c52cad0cffdf752dea Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 7 Dec 2011 01:19:35 +0000 Subject: [PATCH 04/19] LUCENE-3622: remove unused PerDocValues.fields(), its not per-doc and duplicated with IR.fieldNames/fieldOptions... which looks neglected here git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1211256 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/MultiPerDocValues.java | 10 ---------- .../java/org/apache/lucene/index/ParallelReader.java | 5 ----- .../apache/lucene/index/codecs/DocValuesConsumer.java | 3 +++ .../lucene/index/codecs/DocValuesReaderBase.java | 5 ----- .../org/apache/lucene/index/codecs/PerDocValues.java | 6 ------ 5 files changed, 3 insertions(+), 26 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java b/lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java index 543b6c98e4f..0d969797cc3 100644 --- a/lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java +++ b/lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java @@ -49,15 +49,10 @@ public class MultiPerDocValues extends PerDocValues { private final PerDocValues[] subs; private final ReaderUtil.Slice[] subSlices; private final Map docValues = new ConcurrentHashMap(); - private final TreeSet fields; public MultiPerDocValues(PerDocValues[] subs, ReaderUtil.Slice[] subSlices) { this.subs = subs; this.subSlices = subSlices; - fields = new TreeSet(); - for (PerDocValues sub : subs) { - fields.addAll(sub.fields()); - } } /** @@ -154,9 +149,4 @@ public class MultiPerDocValues extends PerDocValues { public void close() throws IOException { IOUtils.close(this.subs); } - - @Override - public Collection fields() { - return fields; - } } diff --git a/lucene/src/java/org/apache/lucene/index/ParallelReader.java b/lucene/src/java/org/apache/lucene/index/ParallelReader.java index e0944825466..3ffbddf1b4c 100644 --- a/lucene/src/java/org/apache/lucene/index/ParallelReader.java +++ b/lucene/src/java/org/apache/lucene/index/ParallelReader.java @@ -533,11 +533,6 @@ public class ParallelReader extends IndexReader { public IndexDocValues docValues(String field) throws IOException { return fields.get(field); } - - @Override - public Collection fields() { - return fields.keySet(); - } } } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java index caf509a7f24..75d8cf6e623 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java @@ -114,6 +114,9 @@ public abstract class DocValuesConsumer { * @throws IOException * if an {@link IOException} occurs */ + // nocommit: can't we have a default implementation here that merges naively with our apis? + // this is how stored fields and term vectors work. its a pain to have to impl merging + // (should be an optimization to override it) protected abstract void merge(SingleSubMergeState mergeState) throws IOException; /** diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java index 5ade60eddb3..6dc8b3a16f5 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java @@ -53,11 +53,6 @@ public abstract class DocValuesReaderBase extends PerDocValues { public IndexDocValues docValues(String field) throws IOException { return docValues().get(field); } - - @Override - public Collection fields() { - return docValues().keySet(); - } public Comparator getComparator() throws IOException { return BytesRef.getUTF8SortedAsUnicodeComparator(); diff --git a/lucene/src/java/org/apache/lucene/index/codecs/PerDocValues.java b/lucene/src/java/org/apache/lucene/index/codecs/PerDocValues.java index 3420c70bac0..cd6cc1ddb04 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/PerDocValues.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/PerDocValues.java @@ -17,7 +17,6 @@ package org.apache.lucene.index.codecs; */ import java.io.Closeable; import java.io.IOException; -import java.util.Collection; import org.apache.lucene.index.values.IndexDocValues; @@ -46,9 +45,4 @@ public abstract class PerDocValues implements Closeable { public abstract IndexDocValues docValues(String field) throws IOException; public static final PerDocValues[] EMPTY_ARRAY = new PerDocValues[0]; - - /** - * Returns all fields this {@link PerDocValues} contains values for. - */ - public abstract Collection fields(); } From fd47d1464ec9855bd0bc9d9b2af51b6612335875 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 7 Dec 2011 04:34:57 +0000 Subject: [PATCH 05/19] LUCENE-3623: commit preliminary fix to branch git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1211298 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/SegmentMerger.java | 7 ++- .../apache/lucene/index/SegmentReader.java | 3 ++ .../apache/lucene/index/TestAddIndexes.java | 47 ++++++++++++++++++- .../index/values/TestTypePromotion.java | 3 +- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java index 7fe99f745e8..cc8bcdbee7c 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java @@ -31,6 +31,7 @@ import org.apache.lucene.index.codecs.FieldsConsumer; import org.apache.lucene.index.codecs.StoredFieldsWriter; import org.apache.lucene.index.codecs.PerDocConsumer; import org.apache.lucene.index.codecs.TermVectorsWriter; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; @@ -202,7 +203,11 @@ final class SegmentMerger { addIndexed(reader, mergeState.fieldInfos, reader.getFieldNames(FieldOption.STORES_PAYLOADS), false, false, false, true, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); addIndexed(reader, mergeState.fieldInfos, reader.getFieldNames(FieldOption.INDEXED), false, false, false, false, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); mergeState.fieldInfos.addOrUpdate(reader.getFieldNames(FieldOption.UNINDEXED), false); - mergeState.fieldInfos.addOrUpdate(reader.getFieldNames(FieldOption.DOC_VALUES), false); + Collection dvNames = reader.getFieldNames(FieldOption.DOC_VALUES); + mergeState.fieldInfos.addOrUpdate(dvNames, false); + for (String dvName : dvNames) { + mergeState.fieldInfos.fieldInfo(dvName).setDocValues(reader.docValues(dvName).type()); + } } } } diff --git a/lucene/src/java/org/apache/lucene/index/SegmentReader.java b/lucene/src/java/org/apache/lucene/index/SegmentReader.java index ff84c13e678..821267d796e 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentReader.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentReader.java @@ -536,6 +536,9 @@ public class SegmentReader extends IndexReader implements Cloneable { else if ((fi.storeOffsetWithTermVector && fi.storePositionWithTermVector) && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION_OFFSET) { fieldSet.add(fi.name); + } + else if (fi.hasDocValues() && fieldOption == IndexReader.FieldOption.DOC_VALUES) { + fieldSet.add(fi.name); } } return fieldSet; diff --git a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java index b92da6d38e6..067f1e95d63 100755 --- a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java +++ b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java @@ -27,6 +27,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.IndexDocValuesField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; @@ -44,6 +45,7 @@ import org.apache.lucene.index.codecs.lucene40.Lucene40SegmentInfosFormat; import org.apache.lucene.index.codecs.lucene40.Lucene40StoredFieldsFormat; import org.apache.lucene.index.codecs.lucene40.Lucene40TermVectorsFormat; import org.apache.lucene.index.codecs.pulsing.Pulsing40PostingsFormat; +import org.apache.lucene.index.values.IndexDocValues; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.store.AlreadyClosedException; @@ -1212,5 +1214,48 @@ public class TestAddIndexes extends LuceneTestCase { } r3.close(); d3.close(); - } + } + + public void testDocValues() throws IOException { + assumeFalse("preflex does not support docvalues", Codec.getDefault().getName().equals("Lucene3x")); + Directory d1 = newDirectory(); + RandomIndexWriter w = new RandomIndexWriter(random, d1); + Document doc = new Document(); + doc.add(newField("id", "1", StringField.TYPE_STORED)); + IndexDocValuesField dv = new IndexDocValuesField("dv"); + dv.setInt(1); + doc.add(dv); + w.addDocument(doc); + IndexReader r1 = w.getReader(); + w.close(); + + Directory d2 = newDirectory(); + w = new RandomIndexWriter(random, d2); + doc = new Document(); + doc.add(newField("id", "2", StringField.TYPE_STORED)); + dv = new IndexDocValuesField("dv"); + dv.setInt(2); + doc.add(dv); + w.addDocument(doc); + IndexReader r2 = w.getReader(); + w.close(); + + Directory d3 = newDirectory(); + w = new RandomIndexWriter(random, d3); + w.addIndexes(new SlowMultiReaderWrapper(r1), new SlowMultiReaderWrapper(r2)); + r1.close(); + d1.close(); + r2.close(); + d2.close(); + + w.forceMerge(1); + IndexReader r3 = w.getReader(); + w.close(); + IndexReader sr = getOnlySegmentReader(r3); + assertEquals(2, sr.numDocs()); + IndexDocValues docValues = sr.perDocValues().docValues("dv"); + assertNotNull(docValues); + r3.close(); + d3.close(); + } } diff --git a/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java b/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java index 70e615298d2..c3d79d650df 100644 --- a/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java +++ b/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java @@ -15,6 +15,7 @@ import org.apache.lucene.index.IndexReader.ReaderContext; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.NoMergePolicy; +import org.apache.lucene.index.SlowMultiReaderWrapper; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.lucene40.values.BytesRefUtils; import org.apache.lucene.index.values.IndexDocValues.Source; @@ -102,7 +103,7 @@ public class TestTypePromotion extends LuceneTestCase { } else { // do a real merge here IndexReader open = IndexReader.open(dir_2); - writer.addIndexes(open); + writer.addIndexes(random.nextBoolean() ? new SlowMultiReaderWrapper(open) : open); open.close(); } dir_2.close(); From fe6d40076589616b420880cda91ed1bd45079533 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 7 Dec 2011 04:50:37 +0000 Subject: [PATCH 06/19] LUCENE-3622: push this to the impl, its in the perdocwritestate if an impl chooses to buffer git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1211301 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/index/codecs/DocValuesConsumer.java | 15 --------------- .../index/codecs/lucene40/values/Writer.java | 4 +++- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java index 75d8cf6e623..b2e89456448 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java @@ -23,7 +23,6 @@ import org.apache.lucene.index.MergeState; import org.apache.lucene.index.values.IndexDocValues; import org.apache.lucene.index.values.PerDocFieldValues; import org.apache.lucene.util.Bits; -import org.apache.lucene.util.Counter; /** * Abstract API that consumes {@link PerDocFieldValues}. @@ -36,20 +35,6 @@ import org.apache.lucene.util.Counter; */ public abstract class DocValuesConsumer { - protected final Counter bytesUsed; - - /** - * Creates a new {@link DocValuesConsumer}. - * - * @param bytesUsed - * bytes-usage tracking reference used by implementation to track - * internally allocated memory. All tracked bytes must be released - * once {@link #finish(int)} has been called. - */ - protected DocValuesConsumer(Counter bytesUsed) { - this.bytesUsed = bytesUsed == null ? Counter.newCounter() : bytesUsed; - } - /** * Adds the given {@link PerDocFieldValues} instance to this * {@link DocValuesConsumer} diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Writer.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Writer.java index 53173fc3fdc..7aae0f0f6fc 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Writer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Writer.java @@ -42,6 +42,8 @@ import org.apache.lucene.util.Counter; */ public abstract class Writer extends DocValuesConsumer { protected Source currentMergeSource; + protected final Counter bytesUsed; + /** * Creates a new {@link Writer}. * @@ -51,7 +53,7 @@ public abstract class Writer extends DocValuesConsumer { * once {@link #finish(int)} has been called. */ protected Writer(Counter bytesUsed) { - super(bytesUsed); + this.bytesUsed = bytesUsed; } /** From 028ebe812f6b07be25ba739a522dd84984998508 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 7 Dec 2011 11:57:00 +0000 Subject: [PATCH 07/19] LUCENE-3623: don't use SlowMultiReaderWrapper for SORTED_BYTES tests git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1211398 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/values/TestTypePromotion.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java b/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java index c3d79d650df..4799f4b10e6 100644 --- a/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java +++ b/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java @@ -103,7 +103,9 @@ public class TestTypePromotion extends LuceneTestCase { } else { // do a real merge here IndexReader open = IndexReader.open(dir_2); - writer.addIndexes(random.nextBoolean() ? new SlowMultiReaderWrapper(open) : open); + // we cannot use SlowMR for sorted bytes, because it returns a null sortedsource + boolean useSlowMRWrapper = types != SORTED_BYTES && random.nextBoolean(); + writer.addIndexes(useSlowMRWrapper ? new SlowMultiReaderWrapper(open) : open); open.close(); } dir_2.close(); From b2fce371337cd3e3e14601cb5d39cd9ffc43484f Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 7 Dec 2011 14:29:11 +0000 Subject: [PATCH 08/19] LUCENE-3622: merge docvalues fieldsinfos in mergeFieldInfos git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1211451 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/SegmentMerger.java | 60 ++++++++++++++++-- .../lucene/index/codecs/PerDocConsumer.java | 63 ++----------------- 2 files changed, 61 insertions(+), 62 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java index cc8bcdbee7c..cce03d8b37b 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java @@ -21,7 +21,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.IndexReader.FieldOption; @@ -31,6 +33,8 @@ import org.apache.lucene.index.codecs.FieldsConsumer; import org.apache.lucene.index.codecs.StoredFieldsWriter; import org.apache.lucene.index.codecs.PerDocConsumer; import org.apache.lucene.index.codecs.TermVectorsWriter; +import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.values.TypePromoter; import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; @@ -128,9 +132,7 @@ final class SegmentMerger { int numMerged = mergeVectors(); assert numMerged == mergeState.mergedDocCount; } - // write FIS once merge is done. IDV might change types or drops fields - FieldInfosWriter fieldInfosWriter = codec.fieldInfosFormat().getFieldInfosWriter(); - fieldInfosWriter.write(directory, segment, mergeState.fieldInfos, context); + return mergeState; } @@ -183,15 +185,40 @@ final class SegmentMerger { } } } + + // returns an updated typepromoter (tracking type and size) given a previous one, + // and a newly encountered docvalues + private TypePromoter mergeDocValuesType(TypePromoter previous, IndexDocValues docValues) { + TypePromoter incoming = TypePromoter.create(docValues.type(), docValues.getValueSize()); + if (previous == null) { + previous = TypePromoter.getIdentityPromoter(); + } + TypePromoter promoted = previous.promote(incoming); + if (promoted == null) { + // type is incompatible: promote to BYTES_VAR_STRAIGHT + return TypePromoter.create(ValueType.BYTES_VAR_STRAIGHT, TypePromoter.VAR_TYPE_VALUE_SIZE); + } else { + return promoted; + } + } private void mergeFieldInfos() throws IOException { + // mapping from all docvalues fields found to their promoted types + // this is because FieldInfos does not store the valueSize + Map docValuesTypes = new HashMap(); + for (MergeState.IndexReaderAndLiveDocs readerAndLiveDocs : mergeState.readers) { final IndexReader reader = readerAndLiveDocs.reader; if (reader instanceof SegmentReader) { SegmentReader segmentReader = (SegmentReader) reader; FieldInfos readerFieldInfos = segmentReader.fieldInfos(); for (FieldInfo fi : readerFieldInfos) { - mergeState.fieldInfos.add(fi); + FieldInfo merged = mergeState.fieldInfos.add(fi); + // update the type promotion mapping for this reader + if (fi.hasDocValues()) { + TypePromoter previous = docValuesTypes.get(merged); + docValuesTypes.put(merged, mergeDocValuesType(previous, reader.docValues(fi.name))); + } } } else { addIndexed(reader, mergeState.fieldInfos, reader.getFieldNames(FieldOption.TERMVECTOR_WITH_POSITION_OFFSET), true, true, true, false, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); @@ -206,10 +233,33 @@ final class SegmentMerger { Collection dvNames = reader.getFieldNames(FieldOption.DOC_VALUES); mergeState.fieldInfos.addOrUpdate(dvNames, false); for (String dvName : dvNames) { - mergeState.fieldInfos.fieldInfo(dvName).setDocValues(reader.docValues(dvName).type()); + FieldInfo merged = mergeState.fieldInfos.fieldInfo(dvName); + IndexDocValues docValues = reader.docValues(dvName); + merged.setDocValues(docValues.type()); + TypePromoter previous = docValuesTypes.get(merged); + docValuesTypes.put(merged, mergeDocValuesType(previous, docValues)); } } } + + // update any promoted doc values types: + for (Map.Entry e : docValuesTypes.entrySet()) { + FieldInfo fi = e.getKey(); + TypePromoter promoter = e.getValue(); + if (promoter == null) { + fi.resetDocValues(null); + } else { + assert promoter != TypePromoter.getIdentityPromoter(); + if (fi.getDocValues() != promoter.type()) { + // reset the type if we got promoted + fi.resetDocValues(promoter.type()); + } + } + } + + // write the merged infos + FieldInfosWriter fieldInfosWriter = codec.fieldInfosFormat().getFieldInfosWriter(); + fieldInfosWriter.write(directory, segment, mergeState.fieldInfos, context); } /** diff --git a/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java index 94151421983..dd6f50e2c12 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java @@ -19,11 +19,8 @@ import java.io.Closeable; import java.io.IOException; import org.apache.lucene.index.FieldInfo; -import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.MergeState; import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.TypePromoter; -import org.apache.lucene.index.values.ValueType; /** * Abstract API that consumes per document values. Concrete implementations of @@ -44,75 +41,27 @@ public abstract class PerDocConsumer implements Closeable{ * Consumes and merges the given {@link PerDocValues} producer * into this consumers format. */ - public void merge(MergeState mergeState) - throws IOException { - final FieldInfos fieldInfos = mergeState.fieldInfos; + public void merge(MergeState mergeState) throws IOException { final IndexDocValues[] docValues = new IndexDocValues[mergeState.readers.size()]; final PerDocValues[] perDocValues = new PerDocValues[mergeState.readers.size()]; // pull all PerDocValues for (int i = 0; i < perDocValues.length; i++) { - perDocValues[i] = mergeState.readers.get(i).reader.perDocValues(); + perDocValues[i] = mergeState.readers.get(i).reader.perDocValues(); } - for (FieldInfo fieldInfo : fieldInfos) { - mergeState.fieldInfo = fieldInfo; - TypePromoter currentPromoter = TypePromoter.getIdentityPromoter(); + for (FieldInfo fieldInfo : mergeState.fieldInfos) { + mergeState.fieldInfo = fieldInfo; // set the field we are merging if (fieldInfo.hasDocValues()) { for (int i = 0; i < perDocValues.length; i++) { if (perDocValues[i] != null) { // get all IDV to merge docValues[i] = perDocValues[i].docValues(fieldInfo.name); - if (docValues[i] != null) { - currentPromoter = promoteValueType(fieldInfo, docValues[i], currentPromoter); - if (currentPromoter == null) { - break; - } - } } } - - if (currentPromoter == null) { - fieldInfo.resetDocValues(null); - continue; - } - assert currentPromoter != TypePromoter.getIdentityPromoter(); - if (fieldInfo.getDocValues() != currentPromoter.type()) { - // reset the type if we got promoted - fieldInfo.resetDocValues(currentPromoter.type()); - } - - final DocValuesConsumer docValuesConsumer = addValuesField(mergeState.fieldInfo); + final DocValuesConsumer docValuesConsumer = addValuesField(fieldInfo); assert docValuesConsumer != null; docValuesConsumer.merge(mergeState, docValues); } } /* NOTE: don't close the perDocProducers here since they are private segment producers * and will be closed once the SegmentReader goes out of scope */ - } - - protected TypePromoter promoteValueType(final FieldInfo fieldInfo, final IndexDocValues docValues, - TypePromoter currentPromoter) { - assert currentPromoter != null; - final TypePromoter incomingPromoter = TypePromoter.create(docValues.type(), docValues.getValueSize()); - assert incomingPromoter != null; - final TypePromoter newPromoter = currentPromoter.promote(incomingPromoter); - return newPromoter == null ? handleIncompatibleValueType(fieldInfo, incomingPromoter, currentPromoter) : newPromoter; - } - - /** - * Resolves a conflicts of incompatible {@link TypePromoter}s. The default - * implementation promotes incompatible types to - * {@link ValueType#BYTES_VAR_STRAIGHT} and preserves all values. If this - * method returns null all docvalues for the given - * {@link FieldInfo} are dropped and all values are lost. - * - * @param incomingPromoter - * the incompatible incoming promoter - * @param currentPromoter - * the current promoter - * @return a promoted {@link TypePromoter} or null iff this index - * docvalues should be dropped for this field. - */ - protected TypePromoter handleIncompatibleValueType(FieldInfo fieldInfo, TypePromoter incomingPromoter, TypePromoter currentPromoter) { - return TypePromoter.create(ValueType.BYTES_VAR_STRAIGHT, TypePromoter.VAR_TYPE_VALUE_SIZE); - } - + } } From 36b8f12325b32e9623bbbb8eb2d40496fe5b5f72 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Wed, 7 Dec 2011 17:07:38 +0000 Subject: [PATCH 09/19] LUCENE-3622: accept SortedSource impls that don't back the ords with packed ints git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1211541 13f79535-47bb-0310-9956-ffa450edef68 --- .../index/codecs/lucene40/values/Bytes.java | 5 ++ .../lucene40/values/FixedSortedBytesImpl.java | 5 ++ .../lucene40/values/VarSortedBytesImpl.java | 5 ++ .../lucene/index/values/IndexDocValues.java | 11 +++ .../apache/lucene/search/FieldComparator.java | 83 +++++++++++++++---- 5 files changed, 91 insertions(+), 18 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java index 4a4ff759af7..792ca190fdb 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java @@ -578,6 +578,11 @@ public final class Bytes { docToOrdIndex = PackedInts.getReader(idxIn); } + @Override + public boolean hasPackedDocToOrd() { + return true; + } + @Override public PackedInts.Reader getDocToOrd() { return docToOrdIndex; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java index b6726d22b4d..9ca4cb6ea58 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java @@ -196,6 +196,11 @@ class FixedSortedBytesImpl { return (int) docToOrdIndex.get(docID); } + @Override + public boolean hasPackedDocToOrd() { + return true; + } + @Override public PackedInts.Reader getDocToOrd() { return docToOrdIndex; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java index 173fa08877e..7a92a8c26b4 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java @@ -216,6 +216,11 @@ final class VarSortedBytesImpl { return (int) docToOrdIndex.get(docID); } + @Override + public boolean hasPackedDocToOrd() { + return true; + } + @Override public PackedInts.Reader getDocToOrd() { return docToOrdIndex; diff --git a/lucene/src/java/org/apache/lucene/index/values/IndexDocValues.java b/lucene/src/java/org/apache/lucene/index/values/IndexDocValues.java index 81896472482..762b61a4b0c 100644 --- a/lucene/src/java/org/apache/lucene/index/values/IndexDocValues.java +++ b/lucene/src/java/org/apache/lucene/index/values/IndexDocValues.java @@ -258,6 +258,12 @@ public abstract class IndexDocValues implements Closeable { /** Returns value for specified ord. */ public abstract BytesRef getByOrd(int ord, BytesRef bytesRef); + /** Return true if it's safe to call {@link + * #getDocToOrd}. */ + public boolean hasPackedDocToOrd() { + return false; + } + /** * Returns the PackedInts.Reader impl that maps document to ord. */ @@ -391,6 +397,11 @@ public abstract class IndexDocValues implements Closeable { return bytesRef; } + @Override + public boolean hasPackedDocToOrd() { + return true; + } + @Override public PackedInts.Reader getDocToOrd() { return docToOrd; diff --git a/lucene/src/java/org/apache/lucene/search/FieldComparator.java b/lucene/src/java/org/apache/lucene/search/FieldComparator.java index 68ab8e26ca6..bd7a0083939 100644 --- a/lucene/src/java/org/apache/lucene/search/FieldComparator.java +++ b/lucene/src/java/org/apache/lucene/search/FieldComparator.java @@ -1623,11 +1623,11 @@ public abstract class FieldComparator { // Used per-segment when bit width is not a native array // size (8, 16, 32): - private final class AnyOrdComparator extends PerSegmentComparator { + private final class AnyPackedDocToOrdComparator extends PerSegmentComparator { private final PackedInts.Reader readerOrds; private final int docBase; - public AnyOrdComparator(PackedInts.Reader readerOrds, int docBase) { + public AnyPackedDocToOrdComparator(PackedInts.Reader readerOrds, int docBase) { this.readerOrds = readerOrds; this.docBase = docBase; } @@ -1664,6 +1664,47 @@ public abstract class FieldComparator { } } + // Used per-segment when DV doesn't use packed ints for + // docToOrds: + private final class AnyOrdComparator extends PerSegmentComparator { + private final int docBase; + + public AnyOrdComparator(int docBase) { + this.docBase = docBase; + } + + @Override + public int compareBottom(int doc) { + assert bottomSlot != -1; + if (bottomSameReader) { + // ord is precisely comparable, even in the equal case + return bottomOrd - termsIndex.ord(doc); + } else { + // ord is only approx comparable: if they are not + // equal, we can use that; if they are equal, we + // must fallback to compare by value + final int order = termsIndex.ord(doc); + final int cmp = bottomOrd - order; + if (cmp != 0) { + return cmp; + } + termsIndex.getByOrd(order, tempBR); + return comp.compare(bottomValue, tempBR); + } + } + + @Override + public void copy(int slot, int doc) { + final int ord = termsIndex.ord(doc); + ords[slot] = ord; + if (values[slot] == null) { + values[slot] = new BytesRef(); + } + termsIndex.getByOrd(ord, values[slot]); + readerGen[slot] = currentReaderGen; + } + } + @Override public FieldComparator setNextReader(AtomicReaderContext context) throws IOException { final int docBase = context.docBase; @@ -1687,24 +1728,30 @@ public abstract class FieldComparator { comp = termsIndex.getComparator(); FieldComparator perSegComp = null; - final PackedInts.Reader docToOrd = termsIndex.getDocToOrd(); - if (docToOrd.hasArray()) { - final Object arr = docToOrd.getArray(); - assert arr != null; - if (arr instanceof byte[]) { - // 8 bit packed - perSegComp = new ByteOrdComparator((byte[]) arr, termsIndex, docBase); - } else if (arr instanceof short[]) { - // 16 bit packed - perSegComp = new ShortOrdComparator((short[]) arr, termsIndex, docBase); - } else if (arr instanceof int[]) { - // 32 bit packed - perSegComp = new IntOrdComparator((int[]) arr, termsIndex, docBase); + if (termsIndex.hasPackedDocToOrd()) { + final PackedInts.Reader docToOrd = termsIndex.getDocToOrd(); + if (docToOrd.hasArray()) { + final Object arr = docToOrd.getArray(); + assert arr != null; + if (arr instanceof byte[]) { + // 8 bit packed + perSegComp = new ByteOrdComparator((byte[]) arr, termsIndex, docBase); + } else if (arr instanceof short[]) { + // 16 bit packed + perSegComp = new ShortOrdComparator((short[]) arr, termsIndex, docBase); + } else if (arr instanceof int[]) { + // 32 bit packed + perSegComp = new IntOrdComparator((int[]) arr, termsIndex, docBase); + } } - } - if (perSegComp == null) { - perSegComp = new AnyOrdComparator(docToOrd, docBase); + if (perSegComp == null) { + perSegComp = new AnyPackedDocToOrdComparator(docToOrd, docBase); + } + } else { + if (perSegComp == null) { + perSegComp = new AnyOrdComparator(docBase); + } } currentReaderGen++; From d6fd85f4c03a0dfb31a71c6ee40d82b9c541ccbb Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Wed, 7 Dec 2011 19:06:49 +0000 Subject: [PATCH 10/19] LUCENE-3622: simplify how indexing chain makes changes to FIS git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1211601 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/CheckIndex.java | 4 +- .../lucene/index/DocFieldProcessor.java | 25 ++++------ .../index/DocumentsWriterPerThread.java | 2 - .../org/apache/lucene/index/FieldInfo.java | 46 ++++--------------- .../org/apache/lucene/index/FieldInfos.java | 32 ++++++------- .../apache/lucene/index/SegmentMerger.java | 8 ++-- .../index/TermVectorsConsumerPerField.java | 4 +- .../index/codecs/DocValuesReaderBase.java | 2 +- .../index/codecs/DocValuesWriterBase.java | 5 +- .../lucene/index/codecs/PerDocConsumer.java | 5 +- .../lucene40/Lucene40FieldInfosWriter.java | 4 +- .../codecs/sep/SepDocValuesConsumer.java | 2 +- .../SimpleTextFieldInfosWriter.java | 2 +- .../org/apache/lucene/util/_TestUtil.java | 2 +- .../apache/lucene/index/TestFieldInfos.java | 2 - 15 files changed, 54 insertions(+), 91 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/src/java/org/apache/lucene/index/CheckIndex.java index c106311b0c9..7300af8e5e0 100644 --- a/lucene/src/java/org/apache/lucene/index/CheckIndex.java +++ b/lucene/src/java/org/apache/lucene/index/CheckIndex.java @@ -1140,7 +1140,7 @@ public class CheckIndex { final Source values = docValues.getDirectSource(); final int maxDoc = reader.maxDoc(); for (int i = 0; i < maxDoc; i++) { - switch (fieldInfo.docValues) { + switch (fieldInfo.getDocValuesType()) { case BYTES_FIXED_SORTED: case BYTES_VAR_SORTED: case BYTES_FIXED_DEREF: @@ -1162,7 +1162,7 @@ public class CheckIndex { break; default: throw new IllegalArgumentException("Field: " + fieldInfo.name - + " - no such DocValues type: " + fieldInfo.docValues); + + " - no such DocValues type: " + fieldInfo.getDocValuesType()); } } } diff --git a/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java b/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java index 12e1524f9af..e0bad01dc5a 100644 --- a/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java +++ b/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java @@ -26,11 +26,12 @@ import java.util.Map; import org.apache.lucene.index.DocumentsWriterPerThread.DocState; import org.apache.lucene.index.codecs.Codec; -import org.apache.lucene.index.codecs.DocValuesFormat; import org.apache.lucene.index.codecs.DocValuesConsumer; +import org.apache.lucene.index.codecs.DocValuesFormat; import org.apache.lucene.index.codecs.FieldInfosWriter; import org.apache.lucene.index.codecs.PerDocConsumer; import org.apache.lucene.index.values.PerDocFieldValues; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.IOContext; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.IOUtils; @@ -224,7 +225,7 @@ final class DocFieldProcessor extends DocConsumer { // 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(), false, field.docValuesType()); + FieldInfo fi = fieldInfos.addOrUpdate(fieldName, field.fieldType()); fp = new DocFieldProcessorPerField(this, fi); fp.next = fieldHash[hashPos]; @@ -235,7 +236,7 @@ final class DocFieldProcessor extends DocConsumer { rehash(); } } else { - fieldInfos.addOrUpdate(fp.fieldInfo.name, field.fieldType(), false, field.docValuesType()); + fieldInfos.addOrUpdate(fp.fieldInfo.name, field.fieldType()); } if (thisFieldGen != fp.lastGen) { @@ -261,7 +262,7 @@ final class DocFieldProcessor extends DocConsumer { } final PerDocFieldValues docValues = field.docValues(); if (docValues != null) { - docValuesConsumer(docState, fp.fieldInfo).add(docState.docID, docValues); + docValuesConsumer(field.docValuesType(), docState, fp.fieldInfo).add(docState.docID, docValues); } } @@ -310,7 +311,7 @@ final class DocFieldProcessor extends DocConsumer { final private Map docValues = new HashMap(); final private Map perDocConsumers = new HashMap(); - DocValuesConsumer docValuesConsumer(DocState docState, FieldInfo fieldInfo) + DocValuesConsumer docValuesConsumer(ValueType valueType, DocState docState, FieldInfo fieldInfo) throws IOException { DocValuesConsumerAndDocID docValuesConsumerAndDocID = docValues.get(fieldInfo.name); if (docValuesConsumerAndDocID != null) { @@ -329,17 +330,9 @@ final class DocFieldProcessor extends DocConsumer { perDocConsumer = dvFormat.docsConsumer(perDocWriteState); perDocConsumers.put(0, perDocConsumer); } - boolean success = false; - DocValuesConsumer docValuesConsumer = null; - try { - docValuesConsumer = perDocConsumer.addValuesField(fieldInfo); - fieldInfo.commitDocValues(); - success = true; - } finally { - if (!success) { - fieldInfo.revertUncommitted(); - } - } + + DocValuesConsumer docValuesConsumer = perDocConsumer.addValuesField(valueType, fieldInfo); + fieldInfo.setDocValuesType(valueType); docValuesConsumerAndDocID = new DocValuesConsumerAndDocID(docValuesConsumer); docValuesConsumerAndDocID.docID = docState.docID; diff --git a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java index 15a3b848230..fb8ea4f1cb4 100644 --- a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java +++ b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java @@ -244,7 +244,6 @@ public class DocumentsWriterPerThread { // mark document as deleted deleteDocID(docState.docID); numDocsInRAM++; - fieldInfos.revertUncommitted(); } else { abort(); } @@ -308,7 +307,6 @@ public class DocumentsWriterPerThread { // Incr here because finishDocument will not // be called (because an exc is being thrown): numDocsInRAM++; - fieldInfos.revertUncommitted(); } else { abort(); } diff --git a/lucene/src/java/org/apache/lucene/index/FieldInfo.java b/lucene/src/java/org/apache/lucene/index/FieldInfo.java index d6ae0d2d073..8b324f063f6 100644 --- a/lucene/src/java/org/apache/lucene/index/FieldInfo.java +++ b/lucene/src/java/org/apache/lucene/index/FieldInfo.java @@ -25,7 +25,7 @@ public final class FieldInfo { public final int number; public boolean isIndexed; - ValueType docValues; + private ValueType docValues; // true if term vector for this field should be stored @@ -118,13 +118,14 @@ public final class FieldInfo { } assert this.indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !this.storePayloads; } - void setDocValues(ValueType v) { + + void setDocValuesType(ValueType v) { if (docValues == null) { docValues = v; } } - public void resetDocValues(ValueType v) { + public void resetDocValuesType(ValueType v) { if (docValues != null) { docValues = v; } @@ -134,42 +135,13 @@ public final class FieldInfo { return docValues != null; } - public ValueType getDocValues() { + public ValueType getDocValuesType() { return docValues; } - - private boolean vectorsCommitted; - private boolean docValuesCommitted; - - /** - * Reverts all uncommitted changes on this {@link FieldInfo} - * @see #commitVectors() - */ - void revertUncommitted() { - if (storeTermVector && !vectorsCommitted) { - storeOffsetWithTermVector = false; - storePositionWithTermVector = false; - storeTermVector = false; - } - - if (docValues != null && !docValuesCommitted) { - docValues = null; - } - } - /** - * Commits term vector modifications. Changes to term-vectors must be - * explicitly committed once the necessary files are created. If those changes - * are not committed subsequent {@link #revertUncommitted()} will reset the - * all term-vector flags before the next document. - */ - void commitVectors() { - assert storeTermVector; - vectorsCommitted = true; - } - - void commitDocValues() { - assert hasDocValues(); - docValuesCommitted = true; + public void setStoreTermVectors(boolean withPositions, boolean withOffsets) { + storeTermVector = true; + storePositionWithTermVector |= withPositions; + storeOffsetWithTermVector |= withOffsets; } } diff --git a/lucene/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/src/java/org/apache/lucene/index/FieldInfos.java index 8e12ef5e864..125717f8c22 100644 --- a/lucene/src/java/org/apache/lucene/index/FieldInfos.java +++ b/lucene/src/java/org/apache/lucene/index/FieldInfos.java @@ -304,10 +304,20 @@ public final class FieldInfos implements Iterable { storeOffsetWithTermVector, omitNorms, storePayloads, indexOptions, docValues); } - synchronized public FieldInfo addOrUpdate(String name, IndexableFieldType fieldType, boolean scorePayloads, ValueType docValues) { - return addOrUpdateInternal(name, -1, fieldType.indexed(), fieldType.storeTermVectors(), - fieldType.storeTermVectorPositions(), fieldType.storeTermVectorOffsets(), fieldType.omitNorms(), scorePayloads, - fieldType.indexOptions(), docValues); + // NOTE: this method does not carry over termVector + // booleans nor docValuesType; the indexer chain + // (TermVectorsConsumerPerField, DocFieldProcessor) must + // set these fields when they succeed in consuming + // the document: + public FieldInfo addOrUpdate(String name, IndexableFieldType fieldType) { + // TODO: really, indexer shouldn't even call this + // method (it's only called from DocFieldProcessor); + // 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, false, false, + fieldType.omitNorms(), false, + fieldType.indexOptions(), null); } synchronized private FieldInfo addOrUpdateInternal(String name, int preferredFieldNumber, boolean isIndexed, @@ -322,7 +332,7 @@ public final class FieldInfos implements Iterable { fi = addInternal(name, fieldNumber, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, indexOptions, docValues); } else { fi.update(isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, indexOptions); - fi.setDocValues(docValues); + fi.setDocValuesType(docValues); } version++; return fi; @@ -333,7 +343,7 @@ public final class FieldInfos implements Iterable { return addOrUpdateInternal(fi.name, fi.number, fi.isIndexed, fi.storeTermVector, fi.storePositionWithTermVector, fi.storeOffsetWithTermVector, fi.omitNorms, fi.storePayloads, - fi.indexOptions, fi.docValues); + fi.indexOptions, fi.getDocValuesType()); } /* @@ -429,16 +439,6 @@ public final class FieldInfos implements Iterable { return version; } - /** - * Reverts all uncommitted changes - * @see FieldInfo#revertUncommitted() - */ - void revertUncommitted() { - for (FieldInfo fieldInfo : this) { - fieldInfo.revertUncommitted(); - } - } - final FieldInfos asReadOnly() { if (isReadOnly()) { return this; diff --git a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java index cce03d8b37b..6ec8a5e64e8 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java @@ -235,7 +235,7 @@ final class SegmentMerger { for (String dvName : dvNames) { FieldInfo merged = mergeState.fieldInfos.fieldInfo(dvName); IndexDocValues docValues = reader.docValues(dvName); - merged.setDocValues(docValues.type()); + merged.setDocValuesType(docValues.type()); TypePromoter previous = docValuesTypes.get(merged); docValuesTypes.put(merged, mergeDocValuesType(previous, docValues)); } @@ -247,12 +247,12 @@ final class SegmentMerger { FieldInfo fi = e.getKey(); TypePromoter promoter = e.getValue(); if (promoter == null) { - fi.resetDocValues(null); + fi.resetDocValuesType(null); } else { assert promoter != TypePromoter.getIdentityPromoter(); - if (fi.getDocValues() != promoter.type()) { + if (fi.getDocValuesType() != promoter.type()) { // reset the type if we got promoted - fi.resetDocValues(promoter.type()); + fi.resetDocValuesType(promoter.type()); } } } diff --git a/lucene/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java b/lucene/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java index 2e837331384..a38b7db1ac2 100644 --- a/lucene/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java +++ b/lucene/src/java/org/apache/lucene/index/TermVectorsConsumerPerField.java @@ -113,7 +113,6 @@ final class TermVectorsConsumerPerField extends TermsHashConsumerPerField { // of a given field in the doc. At this point we flush // our hash into the DocWriter. - assert fieldInfo.storeTermVector; assert termsWriter.vectorFieldsInOrder(fieldInfo); TermVectorsPostingsArray postings = (TermVectorsPostingsArray) termsHashPerField.postingsArray; @@ -150,8 +149,9 @@ final class TermVectorsConsumerPerField extends TermsHashConsumerPerField { } termsHashPerField.reset(); + // commit the termVectors once successful success - FI will otherwise reset them - fieldInfo.commitVectors(); + fieldInfo.setStoreTermVectors(doVectorPositions, doVectorOffsets); } void shrinkHash() { diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java index 6dc8b3a16f5..ccd9b64e7af 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java @@ -74,7 +74,7 @@ public abstract class DocValuesReaderBase extends PerDocValues { final String id = DocValuesWriterBase.docValuesId(segment, fieldInfo.number); values.put(field, - loadDocValues(docCount, dir, id, fieldInfo.getDocValues(), context)); + loadDocValues(docCount, dir, id, fieldInfo.getDocValuesType(), context)); } } success = true; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java index e238f4cea27..ad57ac49679 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java @@ -23,6 +23,7 @@ import java.util.Comparator; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.codecs.lucene40.values.Writer; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.util.BytesRef; @@ -52,8 +53,8 @@ public abstract class DocValuesWriterBase extends PerDocConsumer { } @Override - public DocValuesConsumer addValuesField(FieldInfo field) throws IOException { - return Writer.create(field.getDocValues(), + public DocValuesConsumer addValuesField(ValueType valueType, FieldInfo field) throws IOException { + return Writer.create(valueType, docValuesId(segmentName, field.number), getDirectory(), getComparator(), bytesUsed, context); } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java index dd6f50e2c12..60cacd81671 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.MergeState; import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.values.ValueType; /** * Abstract API that consumes per document values. Concrete implementations of @@ -34,7 +35,7 @@ import org.apache.lucene.index.values.IndexDocValues; */ public abstract class PerDocConsumer implements Closeable{ /** Adds a new DocValuesField */ - public abstract DocValuesConsumer addValuesField(FieldInfo field) + public abstract DocValuesConsumer addValuesField(ValueType type, FieldInfo field) throws IOException; /** @@ -56,7 +57,7 @@ public abstract class PerDocConsumer implements Closeable{ docValues[i] = perDocValues[i].docValues(fieldInfo.name); } } - final DocValuesConsumer docValuesConsumer = addValuesField(fieldInfo); + final DocValuesConsumer docValuesConsumer = addValuesField(fieldInfo.getDocValuesType(), fieldInfo); assert docValuesConsumer != null; docValuesConsumer.merge(mergeState, docValues); } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40FieldInfosWriter.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40FieldInfosWriter.java index 1fe16854a76..c809fd05720 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40FieldInfosWriter.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40FieldInfosWriter.java @@ -83,7 +83,7 @@ public class Lucene40FieldInfosWriter extends FieldInfosWriter { if (!fi.hasDocValues()) { b = 0; } else { - switch(fi.getDocValues()) { + switch(fi.getDocValuesType()) { case VAR_INTS: b = 1; break; @@ -124,7 +124,7 @@ public class Lucene40FieldInfosWriter extends FieldInfosWriter { b = 13; break; default: - throw new IllegalStateException("unhandled indexValues type " + fi.getDocValues()); + throw new IllegalStateException("unhandled indexValues type " + fi.getDocValuesType()); } } output.writeByte(b); diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesConsumer.java index 43817ab3de3..0d28f42b9e3 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesConsumer.java @@ -53,7 +53,7 @@ public class SepDocValuesConsumer extends DocValuesWriterBase { for (FieldInfo fieldInfo : fieldInfos) { if (fieldInfo.hasDocValues()) { String filename = docValuesId(segmentInfo.name, fieldInfo.number); - switch (fieldInfo.getDocValues()) { + switch (fieldInfo.getDocValuesType()) { case BYTES_FIXED_DEREF: case BYTES_VAR_DEREF: case BYTES_VAR_STRAIGHT: diff --git a/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldInfosWriter.java b/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldInfosWriter.java index abc2c7af235..e6f5fab33c0 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldInfosWriter.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldInfosWriter.java @@ -100,7 +100,7 @@ public class SimpleTextFieldInfosWriter extends FieldInfosWriter { if (!fi.hasDocValues()) { SimpleTextUtil.write(out, "false", scratch); } else { - SimpleTextUtil.write(out, fi.getDocValues().toString(), scratch); + SimpleTextUtil.write(out, fi.getDocValuesType().toString(), scratch); } SimpleTextUtil.writeNewline(out); diff --git a/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java b/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java index 0cfde9ab597..8fb0d3521d7 100644 --- a/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java +++ b/lucene/src/test-framework/java/org/apache/lucene/util/_TestUtil.java @@ -440,7 +440,7 @@ public class _TestUtil { /** Adds field info for a Document. */ public static void add(Document doc, FieldInfos fieldInfos) { for (IndexableField field : doc) { - fieldInfos.addOrUpdate(field.name(), field.fieldType(), false, field.docValuesType()); + fieldInfos.addOrUpdate(field.name(), field.fieldType()); } } diff --git a/lucene/src/test/org/apache/lucene/index/TestFieldInfos.java b/lucene/src/test/org/apache/lucene/index/TestFieldInfos.java index c95c0a1e03e..726729e9d72 100644 --- a/lucene/src/test/org/apache/lucene/index/TestFieldInfos.java +++ b/lucene/src/test/org/apache/lucene/index/TestFieldInfos.java @@ -27,7 +27,6 @@ import org.apache.lucene.index.codecs.FieldInfosWriter; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; -import org.junit.Ignore; import java.io.IOException; import java.util.Arrays; @@ -82,7 +81,6 @@ public class TestFieldInfos extends LuceneTestCase { info = readIn.fieldInfo("textField2"); assertTrue(info != null); - assertTrue(info.storeTermVector == true); assertTrue(info.omitNorms == false); info = readIn.fieldInfo("textField3"); From 2698e0943417e92daab953758751509091c0d3f2 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 9 Dec 2011 14:42:21 +0000 Subject: [PATCH 11/19] LUCENE-3622: move DirectSource under codec, its specific to that format (indexinput etc) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1212447 13f79535-47bb-0310-9956-ffa450edef68 --- .../index/{ => codecs/lucene40}/values/DirectSource.java | 4 +++- .../index/codecs/lucene40/values/FixedDerefBytesImpl.java | 1 - .../index/codecs/lucene40/values/FixedStraightBytesImpl.java | 1 - .../index/codecs/lucene40/values/VarDerefBytesImpl.java | 1 - .../index/codecs/lucene40/values/VarStraightBytesImpl.java | 1 - 5 files changed, 3 insertions(+), 5 deletions(-) rename lucene/src/java/org/apache/lucene/index/{ => codecs/lucene40}/values/DirectSource.java (95%) diff --git a/lucene/src/java/org/apache/lucene/index/values/DirectSource.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/DirectSource.java similarity index 95% rename from lucene/src/java/org/apache/lucene/index/values/DirectSource.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/DirectSource.java index 133f64ced14..02a957e9b65 100644 --- a/lucene/src/java/org/apache/lucene/index/values/DirectSource.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/DirectSource.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index.codecs.lucene40.values; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -19,6 +19,8 @@ package org.apache.lucene.index.values; import java.io.IOException; +import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.values.ValueType; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.BytesRef; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedDerefBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedDerefBytesImpl.java index 31efc70e139..ec807050f12 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedDerefBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedDerefBytesImpl.java @@ -22,7 +22,6 @@ import java.io.IOException; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; -import org.apache.lucene.index.values.DirectSource; import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedStraightBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedStraightBytesImpl.java index 8562923a6ba..52622d05d79 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedStraightBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedStraightBytesImpl.java @@ -24,7 +24,6 @@ import java.io.IOException; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesWriterBase; -import org.apache.lucene.index.values.DirectSource; import org.apache.lucene.index.values.IndexDocValues; import org.apache.lucene.index.values.ValueType; import org.apache.lucene.index.values.IndexDocValues.Source; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarDerefBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarDerefBytesImpl.java index 63443ea18a9..2f035de1271 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarDerefBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarDerefBytesImpl.java @@ -22,7 +22,6 @@ import java.io.IOException; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; -import org.apache.lucene.index.values.DirectSource; import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarStraightBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarStraightBytesImpl.java index 7ac7a931192..0e7ff31bc30 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarStraightBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarStraightBytesImpl.java @@ -22,7 +22,6 @@ import java.io.IOException; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesWriterBase; -import org.apache.lucene.index.values.DirectSource; import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; From 4387ff6161be5963e44157a5aa05f7d634fa8337 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 9 Dec 2011 16:43:45 +0000 Subject: [PATCH 12/19] LUCENE-3622: fix naming issues, IDV->DV, ValueType -> DV.Type, move all DV user-facing api into .index, TypePromoter pkg-private, etc git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1212506 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 12 +- .../lucene/index/memory/MemoryIndex.java | 2 +- .../apache/lucene/document/LazyDocument.java | 6 +- ...ocValuesField.java => DocValuesField.java} | 120 +-- .../org/apache/lucene/document/Field.java | 6 +- .../org/apache/lucene/index/CheckIndex.java | 6 +- .../apache/lucene/index/DirectoryReader.java | 1 - .../lucene/index/DocFieldProcessor.java | 7 +- .../org/apache/lucene/index/DocValues.java | 687 ++++++++++++++++++ .../org/apache/lucene/index/FieldInfo.java | 12 +- .../org/apache/lucene/index/FieldInfos.java | 8 +- .../lucene/index/FilterIndexReader.java | 1 - .../org/apache/lucene/index/IndexReader.java | 4 +- .../apache/lucene/index/IndexableField.java | 5 +- ...ndexDocValues.java => MultiDocValues.java} | 30 +- .../apache/lucene/index/MultiFieldsEnum.java | 5 +- .../lucene/index/MultiPerDocValues.java | 33 +- .../org/apache/lucene/index/MultiReader.java | 1 - .../apache/lucene/index/ParallelReader.java | 6 +- .../index/{values => }/PerDocFieldValues.java | 32 +- .../index/{codecs => }/PerDocValues.java | 11 +- .../lucene/index/SegmentCoreReaders.java | 1 - .../apache/lucene/index/SegmentMerger.java | 10 +- .../apache/lucene/index/SegmentReader.java | 1 - .../lucene/index/SlowMultiReaderWrapper.java | 1 - .../index/{values => }/TypePromoter.java | 30 +- .../index/codecs/DocValuesConsumer.java | 12 +- .../lucene/index/codecs/DocValuesFormat.java | 1 + .../index/codecs/DocValuesReaderBase.java | 28 +- .../index/codecs/DocValuesWriterBase.java | 5 +- .../lucene/index/codecs/PerDocConsumer.java | 8 +- .../index/codecs/lucene3x/Lucene3xCodec.java | 2 +- .../lucene40/Lucene40DocValuesFormat.java | 2 +- .../lucene40/Lucene40DocValuesProducer.java | 10 +- .../lucene40/Lucene40FieldInfosReader.java | 30 +- .../index/codecs/lucene40/values/Bytes.java | 38 +- .../codecs/lucene40/values/DirectSource.java | 8 +- ...ocValuesArray.java => DocValuesArray.java} | 76 +- .../lucene40/values/FixedDerefBytesImpl.java | 8 +- .../lucene40/values/FixedSortedBytesImpl.java | 16 +- .../values/FixedStraightBytesImpl.java | 18 +- .../index/codecs/lucene40/values/Floats.java | 28 +- .../index/codecs/lucene40/values/Ints.java | 44 +- .../lucene40/values/PackedIntValues.java | 20 +- .../values/SortedBytesMergeUtils.java | 22 +- .../lucene40/values/VarDerefBytesImpl.java | 8 +- .../lucene40/values/VarSortedBytesImpl.java | 18 +- .../lucene40/values/VarStraightBytesImpl.java | 8 +- .../index/codecs/lucene40/values/Writer.java | 12 +- .../codecs/sep/SepDocValuesProducer.java | 8 +- .../SimpleTextFieldInfosReader.java | 6 +- .../lucene/index/values/IndexDocValues.java | 425 ----------- .../lucene/index/values/SourceCache.java | 93 --- .../apache/lucene/index/values/ValueType.java | 220 ------ .../apache/lucene/search/FieldComparator.java | 41 +- .../search/similarities/Similarity.java | 6 +- .../lucene/index/RandomIndexWriter.java | 10 +- .../mocksep/MockSepDocValuesFormat.java | 2 +- .../apache/lucene/index/TestAddIndexes.java | 9 +- .../lucene/index/TestDuelingCodecs.java | 12 +- .../lucene/index/TestIndexableField.java | 5 +- .../lucene/index/values/TestDocValues.java | 75 +- .../index/values/TestDocValuesIndexing.java | 72 +- .../index/values/TestTypePromotion.java | 56 +- .../lucene/search/TestDocValuesScoring.java | 8 +- .../org/apache/lucene/search/TestSort.java | 28 +- modules/grouping/CHANGES.txt | 2 +- .../grouping/dv/DVAllGroupHeadsCollector.java | 52 +- .../grouping/dv/DVAllGroupsCollector.java | 64 +- .../dv/DVFirstPassGroupingCollector.java | 48 +- .../dv/DVSecondPassGroupingCollector.java | 54 +- .../lucene/search/grouping/package.html | 8 +- .../grouping/AllGroupHeadsCollectorTest.java | 20 +- .../grouping/AllGroupsCollectorTest.java | 8 +- .../lucene/search/grouping/TestGrouping.java | 20 +- .../NumericIndexDocValueSource.java | 12 +- 76 files changed, 1379 insertions(+), 1445 deletions(-) rename lucene/src/java/org/apache/lucene/document/{IndexDocValuesField.java => DocValuesField.java} (70%) create mode 100644 lucene/src/java/org/apache/lucene/index/DocValues.java rename lucene/src/java/org/apache/lucene/index/{values/MultiIndexDocValues.java => MultiDocValues.java} (88%) rename lucene/src/java/org/apache/lucene/index/{values => }/PerDocFieldValues.java (73%) rename lucene/src/java/org/apache/lucene/index/{codecs => }/PerDocValues.java (82%) rename lucene/src/java/org/apache/lucene/index/{values => }/TypePromoter.java (88%) rename lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/{IndexDocValuesArray.java => DocValuesArray.java} (71%) delete mode 100644 lucene/src/java/org/apache/lucene/index/values/IndexDocValues.java delete mode 100644 lucene/src/java/org/apache/lucene/index/values/SourceCache.java delete mode 100644 lucene/src/java/org/apache/lucene/index/values/ValueType.java diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 5af808273fd..8bd4727f658 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -497,23 +497,23 @@ New features bytes in RAM. (Mike McCandless) * LUCENE-3108, LUCENE-2935, LUCENE-2168, LUCENE-1231: Changes from - IndexDocValues (ColumnStrideFields): + DocValues (ColumnStrideFields): - IndexWriter now supports typesafe dense per-document values stored in - a column like storage. IndexDocValues are stored on a per-document + a column like storage. DocValues are stored on a per-document basis where each documents field can hold exactly one value of a given - type. IndexDocValues are provided via Fieldable and can be used in + type. DocValues are provided via Fieldable and can be used in conjunction with stored and indexed values. - - IndexDocValues provides an entirely RAM resident document id to value + - DocValues provides an entirely RAM resident document id to value mapping per field as well as a DocIdSetIterator based disk-resident sequential access API relying on filesystem-caches. - Both APIs are exposed via IndexReader and the Codec / Flex API allowing - expert users to integrate customized IndexDocValues reader and writer + expert users to integrate customized DocValues reader and writer implementations by extending existing Codecs. - - IndexDocValues provides implementations for primitive datatypes like int, + - DocValues provides implementations for primitive datatypes like int, long, float, double and arrays of byte. Byte based implementations further provide storage variants like straight or dereferenced stored bytes, fixed and variable length bytes as well as index time sorted based on diff --git a/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java b/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java index c2399ee73e5..6f1869329ed 100644 --- a/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java +++ b/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java @@ -40,13 +40,13 @@ import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.FieldInvertState; import org.apache.lucene.index.Fields; import org.apache.lucene.index.FieldsEnum; +import org.apache.lucene.index.PerDocValues; import org.apache.lucene.index.IndexReader.AtomicReaderContext; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.OrdTermState; import org.apache.lucene.index.StoredFieldVisitor; import org.apache.lucene.index.Term; import org.apache.lucene.index.TermState; -import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.index.Terms; import org.apache.lucene.index.TermsEnum; import org.apache.lucene.search.Collector; diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java b/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java index d006a8949e8..edaf7f52329 100644 --- a/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java +++ b/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java @@ -28,8 +28,8 @@ 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.values.PerDocFieldValues; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.PerDocFieldValues; +import org.apache.lucene.index.DocValues; import org.apache.lucene.util.BytesRef; /** Defers actually loading a field's value until you ask @@ -166,7 +166,7 @@ public class LazyDocument { } @Override - public ValueType docValuesType() { + public DocValues.Type docValuesType() { if (num == 0) { return getDocument().getField(name).docValuesType(); } else { diff --git a/lucene/src/java/org/apache/lucene/document/IndexDocValuesField.java b/lucene/src/java/org/apache/lucene/document/DocValuesField.java similarity index 70% rename from lucene/src/java/org/apache/lucene/document/IndexDocValuesField.java rename to lucene/src/java/org/apache/lucene/document/DocValuesField.java index 741aefc098a..097a8814b2e 100644 --- a/lucene/src/java/org/apache/lucene/document/IndexDocValuesField.java +++ b/lucene/src/java/org/apache/lucene/document/DocValuesField.java @@ -20,8 +20,9 @@ import java.io.Reader; import java.util.Comparator; import org.apache.lucene.index.IndexableFieldType; -import org.apache.lucene.index.values.PerDocFieldValues; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.PerDocFieldValues; +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.DocValues.Type; // javadocs import org.apache.lucene.util.BytesRef; /** @@ -31,14 +32,14 @@ import org.apache.lucene.util.BytesRef; * example usage, adding an int value: * *
- * document.add(new IndexDocValuesField(name).setInt(value));
+ * document.add(new DocValuesField(name).setInt(value));
  * 
* * For optimal performance, re-use the DocValuesField and * {@link Document} instance for more than one document: * *
- *  IndexDocValuesField field = new IndexDocValuesField(name);
+ *  DocValuesField field = new DocValuesField(name);
  *  Document document = new Document();
  *  document.add(field);
  * 
@@ -56,7 +57,7 @@ import org.apache.lucene.util.BytesRef;
  * when creating the field:
  * 
  * 
- *  IndexDocValuesField field = new IndexDocValuesField(name, StringField.TYPE_STORED);
+ *  DocValuesField field = new DocValuesField(name, StringField.TYPE_STORED);
  *  Document document = new Document();
  *  document.add(field);
  *  for(all documents) {
@@ -68,27 +69,26 @@ import org.apache.lucene.util.BytesRef;
  * 
* * */ -// TODO: maybe rename to DocValuesField? -public class IndexDocValuesField extends Field implements PerDocFieldValues { +public class DocValuesField extends Field implements PerDocFieldValues { protected BytesRef bytes; protected double doubleValue; protected long longValue; - protected ValueType type; + protected DocValues.Type type; protected Comparator bytesComparator; /** - * Creates a new {@link IndexDocValuesField} with the given name. + * Creates a new {@link DocValuesField} with the given name. */ - public IndexDocValuesField(String name) { + public DocValuesField(String name) { this(name, new FieldType()); } - public IndexDocValuesField(String name, IndexableFieldType type) { + public DocValuesField(String name, IndexableFieldType type) { this(name, type, null); } - public IndexDocValuesField(String name, IndexableFieldType type, String value) { + public DocValuesField(String name, IndexableFieldType type, String value) { super(name, type); fieldsData = value; } @@ -99,9 +99,9 @@ public class IndexDocValuesField extends Field implements PerDocFieldValues { } /** - * Sets the given long value and sets the field's {@link ValueType} to - * {@link ValueType#VAR_INTS} unless already set. If you want to change the - * default type use {@link #setDocValuesType(ValueType)}. + * Sets the given long value and sets the field's {@link Type} to + * {@link Type#VAR_INTS} unless already set. If you want to change the + * default type use {@link #setDocValuesType(DocValues.Type)}. */ public void setInt(long value) { setInt(value, false); @@ -113,20 +113,20 @@ public class IndexDocValuesField extends Field implements PerDocFieldValues { * @param value * the value to set * @param fixed - * if true {@link ValueType#FIXED_INTS_64} is used - * otherwise {@link ValueType#VAR_INTS} + * if true {@link Type#FIXED_INTS_64} is used + * otherwise {@link Type#VAR_INTS} */ public void setInt(long value, boolean fixed) { if (type == null) { - type = fixed ? ValueType.FIXED_INTS_64 : ValueType.VAR_INTS; + type = fixed ? DocValues.Type.FIXED_INTS_64 : DocValues.Type.VAR_INTS; } longValue = value; } /** - * Sets the given int value and sets the field's {@link ValueType} to - * {@link ValueType#VAR_INTS} unless already set. If you want to change the - * default type use {@link #setDocValuesType(ValueType)}. + * Sets the given int value and sets the field's {@link Type} to + * {@link Type#VAR_INTS} unless already set. If you want to change the + * default type use {@link #setDocValuesType(DocValues.Type)}. */ public void setInt(int value) { setInt(value, false); @@ -138,20 +138,20 @@ public class IndexDocValuesField extends Field implements PerDocFieldValues { * @param value * the value to set * @param fixed - * if true {@link ValueType#FIXED_INTS_32} is used - * otherwise {@link ValueType#VAR_INTS} + * if true {@link Type#FIXED_INTS_32} is used + * otherwise {@link Type#VAR_INTS} */ public void setInt(int value, boolean fixed) { if (type == null) { - type = fixed ? ValueType.FIXED_INTS_32 : ValueType.VAR_INTS; + type = fixed ? DocValues.Type.FIXED_INTS_32 : DocValues.Type.VAR_INTS; } longValue = value; } /** - * Sets the given short value and sets the field's {@link ValueType} to - * {@link ValueType#VAR_INTS} unless already set. If you want to change the - * default type use {@link #setDocValuesType(ValueType)}. + * Sets the given short value and sets the field's {@link Type} to + * {@link Type#VAR_INTS} unless already set. If you want to change the + * default type use {@link #setDocValuesType(DocValues.Type)}. */ public void setInt(short value) { setInt(value, false); @@ -163,20 +163,20 @@ public class IndexDocValuesField extends Field implements PerDocFieldValues { * @param value * the value to set * @param fixed - * if true {@link ValueType#FIXED_INTS_16} is used - * otherwise {@link ValueType#VAR_INTS} + * if true {@link Type#FIXED_INTS_16} is used + * otherwise {@link Type#VAR_INTS} */ public void setInt(short value, boolean fixed) { if (type == null) { - type = fixed ? ValueType.FIXED_INTS_16 : ValueType.VAR_INTS; + type = fixed ? DocValues.Type.FIXED_INTS_16 : DocValues.Type.VAR_INTS; } longValue = value; } /** - * Sets the given byte value and sets the field's {@link ValueType} to - * {@link ValueType#VAR_INTS} unless already set. If you want to change the - * default type use {@link #setDocValuesType(ValueType)}. + * Sets the given byte value and sets the field's {@link Type} to + * {@link Type#VAR_INTS} unless already set. If you want to change the + * default type use {@link #setDocValuesType(DocValues.Type)}. */ public void setInt(byte value) { setInt(value, false); @@ -188,59 +188,59 @@ public class IndexDocValuesField extends Field implements PerDocFieldValues { * @param value * the value to set * @param fixed - * if true {@link ValueType#FIXED_INTS_8} is used - * otherwise {@link ValueType#VAR_INTS} + * if true {@link Type#FIXED_INTS_8} is used + * otherwise {@link Type#VAR_INTS} */ public void setInt(byte value, boolean fixed) { if (type == null) { - type = fixed ? ValueType.FIXED_INTS_8 : ValueType.VAR_INTS; + type = fixed ? DocValues.Type.FIXED_INTS_8 : DocValues.Type.VAR_INTS; } longValue = value; } /** - * Sets the given float value and sets the field's {@link ValueType} - * to {@link ValueType#FLOAT_32} unless already set. If you want to - * change the type use {@link #setDocValuesType(ValueType)}. + * Sets the given float value and sets the field's {@link Type} + * to {@link Type#FLOAT_32} unless already set. If you want to + * change the type use {@link #setDocValuesType(DocValues.Type)}. */ public void setFloat(float value) { if (type == null) { - type = ValueType.FLOAT_32; + type = DocValues.Type.FLOAT_32; } doubleValue = value; } /** - * Sets the given double value and sets the field's {@link ValueType} - * to {@link ValueType#FLOAT_64} unless already set. If you want to - * change the default type use {@link #setDocValuesType(ValueType)}. + * Sets the given double value and sets the field's {@link Type} + * to {@link Type#FLOAT_64} unless already set. If you want to + * change the default type use {@link #setDocValuesType(DocValues.Type)}. */ public void setFloat(double value) { if (type == null) { - type = ValueType.FLOAT_64; + type = DocValues.Type.FLOAT_64; } doubleValue = value; } /** - * Sets the given {@link BytesRef} value and the field's {@link ValueType}. The + * Sets the given {@link BytesRef} value and the field's {@link Type}. The * comparator for this field is set to null. If a * null comparator is set the default comparator for the given - * {@link ValueType} is used. + * {@link Type} is used. */ - public void setBytes(BytesRef value, ValueType type) { + public void setBytes(BytesRef value, DocValues.Type type) { setBytes(value, type, null); } /** - * Sets the given {@link BytesRef} value, the field's {@link ValueType} and the + * Sets the given {@link BytesRef} value, the field's {@link Type} and the * field's comparator. If the {@link Comparator} is set to null - * the default for the given {@link ValueType} is used instead. + * the default for the given {@link Type} is used instead. * * @throws IllegalArgumentException * if the value or the type are null */ - public void setBytes(BytesRef value, ValueType type, Comparator comp) { + public void setBytes(BytesRef value, DocValues.Type type, Comparator comp) { if (value == null) { throw new IllegalArgumentException("value must not be null"); } @@ -283,16 +283,16 @@ public class IndexDocValuesField extends Field implements PerDocFieldValues { /** * Sets the {@link BytesRef} comparator for this field. If the field has a - * numeric {@link ValueType} the comparator will be ignored. + * numeric {@link Type} the comparator will be ignored. */ public void setBytesComparator(Comparator comp) { this.bytesComparator = comp; } /** - * Sets the {@link ValueType} for this field. + * Sets the {@link Type} for this field. */ - public void setDocValuesType(ValueType type) { + public void setDocValuesType(DocValues.Type type) { if (type == null) { throw new IllegalArgumentException("Type must not be null"); } @@ -307,7 +307,7 @@ public class IndexDocValuesField extends Field implements PerDocFieldValues { } @Override - public ValueType docValuesType() { + public DocValues.Type docValuesType() { return type; } @@ -348,21 +348,21 @@ public class IndexDocValuesField extends Field implements PerDocFieldValues { default: throw new IllegalArgumentException("unknown type: " + type); } - return "<" + name() + ": IndexDocValuesField " + value + ">"; + return "<" + name() + ": DocValuesField " + value + ">"; } /** - * Returns an IndexDocValuesField holding the value from + * Returns an DocValuesField holding the value from * the provided string field, as the specified type. The * incoming field must have a string value. The name, {@link * FieldType} and string value are carried over from the * incoming Field. */ - public static IndexDocValuesField build(Field field, ValueType type) { - if (field instanceof IndexDocValuesField) { - return (IndexDocValuesField) field; + public static DocValuesField build(Field field, DocValues.Type type) { + if (field instanceof DocValuesField) { + return (DocValuesField) field; } - final IndexDocValuesField valField = new IndexDocValuesField(field.name(), field.fieldType(), field.stringValue()); + final DocValuesField valField = new DocValuesField(field.name(), field.fieldType(), field.stringValue()); switch (type) { case BYTES_FIXED_DEREF: case BYTES_FIXED_STRAIGHT: diff --git a/lucene/src/java/org/apache/lucene/document/Field.java b/lucene/src/java/org/apache/lucene/document/Field.java index 9c374736890..45b9a5a2ff1 100644 --- a/lucene/src/java/org/apache/lucene/document/Field.java +++ b/lucene/src/java/org/apache/lucene/document/Field.java @@ -25,10 +25,10 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexableFieldType; import org.apache.lucene.index.IndexableField; -import org.apache.lucene.index.values.PerDocFieldValues; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.PerDocFieldValues; import org.apache.lucene.util.BytesRef; /** @@ -302,7 +302,7 @@ public class Field implements IndexableField { } @Override - public ValueType docValuesType() { + public DocValues.Type docValuesType() { return null; } diff --git a/lucene/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/src/java/org/apache/lucene/index/CheckIndex.java index 9172f8a3b71..2e6c7002396 100644 --- a/lucene/src/java/org/apache/lucene/index/CheckIndex.java +++ b/lucene/src/java/org/apache/lucene/index/CheckIndex.java @@ -25,6 +25,7 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.document.Document; +import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.codecs.Codec; import java.io.File; import java.io.IOException; @@ -38,9 +39,6 @@ import java.util.List; import java.util.Map; import org.apache.lucene.index.codecs.BlockTreeTermsReader; -import org.apache.lucene.index.codecs.PerDocValues; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; @@ -1133,7 +1131,7 @@ public class CheckIndex { if (fieldInfo.hasDocValues()) { status.totalValueFields++; final PerDocValues perDocValues = reader.perDocValues(); - final IndexDocValues docValues = perDocValues.docValues(fieldInfo.name); + final DocValues docValues = perDocValues.docValues(fieldInfo.name); if (docValues == null) { continue; } diff --git a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java index b9489f02245..e1468b75624 100644 --- a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java +++ b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java @@ -33,7 +33,6 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.Lock; import org.apache.lucene.store.LockObtainFailedException; -import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.InfoStream; diff --git a/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java b/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java index e0bad01dc5a..df3f4202d2a 100644 --- a/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java +++ b/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java @@ -30,8 +30,7 @@ import org.apache.lucene.index.codecs.DocValuesConsumer; import org.apache.lucene.index.codecs.DocValuesFormat; import org.apache.lucene.index.codecs.FieldInfosWriter; import org.apache.lucene.index.codecs.PerDocConsumer; -import org.apache.lucene.index.values.PerDocFieldValues; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues; import org.apache.lucene.store.IOContext; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.IOUtils; @@ -311,12 +310,12 @@ final class DocFieldProcessor extends DocConsumer { final private Map docValues = new HashMap(); final private Map perDocConsumers = new HashMap(); - DocValuesConsumer docValuesConsumer(ValueType valueType, DocState docState, FieldInfo fieldInfo) + DocValuesConsumer docValuesConsumer(DocValues.Type valueType, DocState docState, FieldInfo fieldInfo) throws IOException { DocValuesConsumerAndDocID docValuesConsumerAndDocID = docValues.get(fieldInfo.name); if (docValuesConsumerAndDocID != null) { if (docState.docID == docValuesConsumerAndDocID.docID) { - throw new IllegalArgumentException("IndexDocValuesField \"" + fieldInfo.name + "\" appears more than once in this document (only one value is allowed, per field)"); + throw new IllegalArgumentException("DocValuesField \"" + fieldInfo.name + "\" appears more than once in this document (only one value is allowed, per field)"); } assert docValuesConsumerAndDocID.docID < docState.docID; docValuesConsumerAndDocID.docID = docState.docID; diff --git a/lucene/src/java/org/apache/lucene/index/DocValues.java b/lucene/src/java/org/apache/lucene/index/DocValues.java new file mode 100644 index 00000000000..c724700ae9b --- /dev/null +++ b/lucene/src/java/org/apache/lucene/index/DocValues.java @@ -0,0 +1,687 @@ +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. + */ +import java.io.Closeable; +import java.io.IOException; +import java.util.Comparator; + +import org.apache.lucene.document.DocValuesField; +import org.apache.lucene.index.codecs.DocValuesFormat; +import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.packed.PackedInts; + +/** + * {@link DocValues} provides a dense per-document typed storage for fast + * value access based on the lucene internal document id. {@link DocValues} + * exposes two distinct APIs: + *
    + *
  • via {@link #getSource()} providing RAM resident random access
  • + *
  • via {@link #getDirectSource()} providing on disk random access
  • + *
{@link DocValues} are exposed via + * {@link IndexReader#perDocValues()} on a per-segment basis. For best + * performance {@link DocValues} should be consumed per-segment just like + * IndexReader. + *

+ * {@link DocValues} are fully integrated into the {@link DocValuesFormat} API. + * + * @see Type for limitations and default implementation documentation + * @see DocValuesField for adding values to the index + * @see DocValuesFormat#docsConsumer(org.apache.lucene.index.PerDocWriteState) for + * customization + * @lucene.experimental + */ +public abstract class DocValues implements Closeable { + + public static final DocValues[] EMPTY_ARRAY = new DocValues[0]; + + private volatile SourceCache cache = new SourceCache.DirectSourceCache(); + private final Object cacheLock = new Object(); + + /** + * Loads a new {@link Source} instance for this {@link DocValues} field + * instance. Source instances returned from this method are not cached. It is + * the callers responsibility to maintain the instance and release its + * resources once the source is not needed anymore. + *

+ * For managed {@link Source} instances see {@link #getSource()}. + * + * @see #getSource() + * @see #setCache(SourceCache) + */ + public abstract Source load() throws IOException; + + /** + * Returns a {@link Source} instance through the current {@link SourceCache}. + * Iff no {@link Source} has been loaded into the cache so far the source will + * be loaded through {@link #load()} and passed to the {@link SourceCache}. + * The caller of this method should not close the obtained {@link Source} + * instance unless it is not needed for the rest of its life time. + *

+ * {@link Source} instances obtained from this method are closed / released + * from the cache once this {@link DocValues} instance is closed by the + * {@link IndexReader}, {@link Fields} or {@link FieldsEnum} the + * {@link DocValues} was created from. + */ + public Source getSource() throws IOException { + return cache.load(this); + } + + /** + * Returns a disk resident {@link Source} instance. Direct Sources are not + * cached in the {@link SourceCache} and should not be shared between threads. + */ + public abstract Source getDirectSource() throws IOException; + + /** + * Returns the {@link Type} of this {@link DocValues} instance + */ + public abstract Type type(); + + /** + * Closes this {@link DocValues} instance. This method should only be called + * by the creator of this {@link DocValues} instance. API users should not + * close {@link DocValues} instances. + */ + public void close() throws IOException { + cache.close(this); + } + + /** + * Returns the size per value in bytes or -1 iff size per value + * is variable. + * + * @return the size per value in bytes or -1 iff size per value + * is variable. + */ + public int getValueSize() { + return -1; + } + + /** + * Sets the {@link SourceCache} used by this {@link DocValues} instance. This + * method should be called before {@link #load()} is called. All {@link Source} instances in the currently used cache will be closed + * before the new cache is installed. + *

+ * Note: All instances previously obtained from {@link #load()} will be lost. + * + * @throws IllegalArgumentException + * if the given cache is null + * + */ + public void setCache(SourceCache cache) { + if (cache == null) + throw new IllegalArgumentException("cache must not be null"); + synchronized (cacheLock) { + SourceCache toClose = this.cache; + this.cache = cache; + toClose.close(this); + } + } + + /** + * Source of per document values like long, double or {@link BytesRef} + * depending on the {@link DocValues} fields {@link Type}. Source + * implementations provide random access semantics similar to array lookups + *

+ * @see DocValues#getSource() + * @see DocValues#getDirectSource() + */ + public static abstract class Source { + + protected final Type type; + + protected Source(Type type) { + this.type = type; + } + /** + * Returns a long for the given document id or throws an + * {@link UnsupportedOperationException} if this source doesn't support + * long values. + * + * @throws UnsupportedOperationException + * if this source doesn't support long values. + */ + public long getInt(int docID) { + throw new UnsupportedOperationException("ints are not supported"); + } + + /** + * Returns a double for the given document id or throws an + * {@link UnsupportedOperationException} if this source doesn't support + * double values. + * + * @throws UnsupportedOperationException + * if this source doesn't support double values. + */ + public double getFloat(int docID) { + throw new UnsupportedOperationException("floats are not supported"); + } + + /** + * Returns a {@link BytesRef} for the given document id or throws an + * {@link UnsupportedOperationException} if this source doesn't support + * byte[] values. + * @throws IOException + * + * @throws UnsupportedOperationException + * if this source doesn't support byte[] values. + */ + public BytesRef getBytes(int docID, BytesRef ref) { + throw new UnsupportedOperationException("bytes are not supported"); + } + + /** + * Returns the {@link Type} of this source. + * + * @return the {@link Type} of this source. + */ + public Type type() { + return type; + } + + /** + * Returns true iff this {@link Source} exposes an array via + * {@link #getArray()} otherwise false. + * + * @return true iff this {@link Source} exposes an array via + * {@link #getArray()} otherwise false. + */ + public boolean hasArray() { + return false; + } + + /** + * Returns the internal array representation iff this {@link Source} uses an + * array as its inner representation, otherwise UOE. + */ + public Object getArray() { + throw new UnsupportedOperationException("getArray is not supported"); + } + + /** + * If this {@link Source} is sorted this method will return an instance of + * {@link SortedSource} otherwise UOE + */ + public SortedSource asSortedSource() { + throw new UnsupportedOperationException("asSortedSource is not supported"); + } + } + + /** + * A sorted variant of {@link Source} for byte[] values per document. + *

+ */ + public static abstract class SortedSource extends Source { + + private final Comparator comparator; + + protected SortedSource(Type type, Comparator comparator) { + super(type); + this.comparator = comparator; + } + + @Override + public BytesRef getBytes(int docID, BytesRef bytesRef) { + final int ord = ord(docID); + if (ord < 0) { + bytesRef.length = 0; + } else { + getByOrd(ord , bytesRef); + } + return bytesRef; + } + + /** + * Returns ord for specified docID. Ord is dense, ie, starts at 0, then increments by 1 + * for the next (as defined by {@link Comparator} value. + */ + public abstract int ord(int docID); + + /** Returns value for specified ord. */ + public abstract BytesRef getByOrd(int ord, BytesRef bytesRef); + + /** Return true if it's safe to call {@link + * #getDocToOrd}. */ + public boolean hasPackedDocToOrd() { + return false; + } + + /** + * Returns the PackedInts.Reader impl that maps document to ord. + */ + public abstract PackedInts.Reader getDocToOrd(); + + /** + * Returns the comparator used to order the BytesRefs. + */ + public Comparator getComparator() { + return comparator; + } + + /** + * Performs a lookup by value. + * + * @param value + * the value to look up + * @param spare + * a spare {@link BytesRef} instance used to compare internal + * values to the given value. Must not be null + * @return the given values ordinal if found or otherwise + * (-(ord)-1), defined as the ordinal of the first + * element that is greater than the given value. This guarantees + * that the return value will always be >= 0 if the given value + * is found. + */ + public int getByValue(BytesRef value, BytesRef spare) { + return binarySearch(value, spare, 0, getValueCount() - 1); + } + + private int binarySearch(BytesRef b, BytesRef bytesRef, int low, + int high) { + int mid = 0; + while (low <= high) { + mid = (low + high) >>> 1; + getByOrd(mid, bytesRef); + final int cmp = comparator.compare(bytesRef, b); + if (cmp < 0) { + low = mid + 1; + } else if (cmp > 0) { + high = mid - 1; + } else { + return mid; + } + } + assert comparator.compare(bytesRef, b) != 0; + return -(low + 1); + } + + @Override + public SortedSource asSortedSource() { + return this; + } + + /** + * Returns the number of unique values in this sorted source + */ + public abstract int getValueCount(); + } + + /** Returns a Source that always returns default (missing) + * values for all documents. */ + public static Source getDefaultSource(final Type type) { + return new Source(type) { + @Override + public long getInt(int docID) { + return 0; + } + + @Override + public double getFloat(int docID) { + return 0.0; + } + + @Override + public BytesRef getBytes(int docID, BytesRef ref) { + ref.length = 0; + return ref; + } + }; + } + + /** Returns a SortedSource that always returns default (missing) + * values for all documents. */ + public static SortedSource getDefaultSortedSource(final Type type, final int size) { + + final PackedInts.Reader docToOrd = new PackedInts.Reader() { + @Override + public long get(int index) { + return 0; + } + + @Override + public int getBitsPerValue() { + return 0; + } + + @Override + public int size() { + return size; + } + + @Override + public boolean hasArray() { + return false; + } + + @Override + public Object getArray() { + return null; + } + }; + + return new SortedSource(type, BytesRef.getUTF8SortedAsUnicodeComparator()) { + + @Override + public BytesRef getBytes(int docID, BytesRef ref) { + ref.length = 0; + return ref; + } + + @Override + public int ord(int docID) { + return 0; + } + + @Override + public BytesRef getByOrd(int ord, BytesRef bytesRef) { + assert ord == 0; + bytesRef.length = 0; + return bytesRef; + } + + @Override + public boolean hasPackedDocToOrd() { + return true; + } + + @Override + public PackedInts.Reader getDocToOrd() { + return docToOrd; + } + + @Override + public int getByValue(BytesRef value, BytesRef spare) { + if (value.length == 0) { + return 0; + } else { + return -1; + } + } + + @Override + public int getValueCount() { + return 1; + } + }; + } + + /** + * Type specifies the {@link DocValues} type for a + * certain field. A Type only defines the data type for a field + * while the actual implementation used to encode and decode the values depends + * on the the {@link DocValuesFormat#docsConsumer} and {@link DocValuesFormat#docsProducer} methods. + * + * @lucene.experimental + */ + public static enum Type { + + /** + * A variable bit signed integer value. By default this type uses + * {@link PackedInts} to compress the values, as an offset + * from the minimum value, as long as the value range + * fits into 263-1. Otherwise, + * the default implementation falls back to fixed size 64bit + * integers ({@link #FIXED_INTS_64}). + *

+ * NOTE: this type uses 0 as the default value without any + * distinction between provided 0 values during indexing. All + * documents without an explicit value will use 0 instead. + * Custom default values must be assigned explicitly. + *

+ */ + VAR_INTS, + + /** + * A 8 bit signed integer value. {@link Source} instances of + * this type return a byte array from {@link Source#getArray()} + *

+ * NOTE: this type uses 0 as the default value without any + * distinction between provided 0 values during indexing. All + * documents without an explicit value will use 0 instead. + * Custom default values must be assigned explicitly. + *

+ */ + FIXED_INTS_8, + + /** + * A 16 bit signed integer value. {@link Source} instances of + * this type return a short array from {@link Source#getArray()} + *

+ * NOTE: this type uses 0 as the default value without any + * distinction between provided 0 values during indexing. All + * documents without an explicit value will use 0 instead. + * Custom default values must be assigned explicitly. + *

+ */ + FIXED_INTS_16, + + /** + * A 32 bit signed integer value. {@link Source} instances of + * this type return a int array from {@link Source#getArray()} + *

+ * NOTE: this type uses 0 as the default value without any + * distinction between provided 0 values during indexing. All + * documents without an explicit value will use 0 instead. + * Custom default values must be assigned explicitly. + *

+ */ + FIXED_INTS_32, + + /** + * A 64 bit signed integer value. {@link Source} instances of + * this type return a long array from {@link Source#getArray()} + *

+ * NOTE: this type uses 0 as the default value without any + * distinction between provided 0 values during indexing. All + * documents without an explicit value will use 0 instead. + * Custom default values must be assigned explicitly. + *

+ */ + FIXED_INTS_64, + /** + * A 32 bit floating point value. By default there is no compression + * applied. To fit custom float values into less than 32bit either a custom + * implementation is needed or values must be encoded into a + * {@link #BYTES_FIXED_STRAIGHT} type. {@link Source} instances of + * this type return a float array from {@link Source#getArray()} + *

+ * NOTE: this type uses 0.0f as the default value without any + * distinction between provided 0.0f values during indexing. All + * documents without an explicit value will use 0.0f instead. + * Custom default values must be assigned explicitly. + *

+ */ + FLOAT_32, + /** + * + * A 64 bit floating point value. By default there is no compression + * applied. To fit custom float values into less than 64bit either a custom + * implementation is needed or values must be encoded into a + * {@link #BYTES_FIXED_STRAIGHT} type. {@link Source} instances of + * this type return a double array from {@link Source#getArray()} + *

+ * NOTE: this type uses 0.0d as the default value without any + * distinction between provided 0.0d values during indexing. All + * documents without an explicit value will use 0.0d instead. + * Custom default values must be assigned explicitly. + *

+ */ + FLOAT_64, + + // TODO(simonw): -- shouldn't lucene decide/detect straight vs + // deref, as well fixed vs var? + /** + * A fixed length straight byte[]. All values added to + * such a field must be of the same length. All bytes are stored sequentially + * for fast offset access. + *

+ * NOTE: this type uses 0 byte filled byte[] based on the length of the first seen + * value as the default value without any distinction between explicitly + * provided values during indexing. All documents without an explicit value + * will use the default instead.Custom default values must be assigned explicitly. + *

+ */ + BYTES_FIXED_STRAIGHT, + + /** + * A fixed length dereferenced byte[] variant. Fields with + * this type only store distinct byte values and store an additional offset + * pointer per document to dereference the shared byte[]. + * Use this type if your documents may share the same byte[]. + *

+ * NOTE: Fields of this type will not store values for documents without and + * explicitly provided value. If a documents value is accessed while no + * explicit value is stored the returned {@link BytesRef} will be a 0-length + * reference. Custom default values must be assigned explicitly. + *

+ */ + BYTES_FIXED_DEREF, + + /** + * Variable length straight stored byte[] variant. All bytes are + * stored sequentially for compactness. Usage of this type via the + * disk-resident API might yield performance degradation since no additional + * index is used to advance by more than one document value at a time. + *

+ * NOTE: Fields of this type will not store values for documents without an + * explicitly provided value. If a documents value is accessed while no + * explicit value is stored the returned {@link BytesRef} will be a 0-length + * byte[] reference. Custom default values must be assigned explicitly. + *

+ */ + BYTES_VAR_STRAIGHT, + + /** + * A variable length dereferenced byte[]. Just like + * {@link #BYTES_FIXED_DEREF}, but allowing each + * document's value to be a different length. + *

+ * NOTE: Fields of this type will not store values for documents without and + * explicitly provided value. If a documents value is accessed while no + * explicit value is stored the returned {@link BytesRef} will be a 0-length + * reference. Custom default values must be assigned explicitly. + *

+ */ + BYTES_VAR_DEREF, + + + /** + * A variable length pre-sorted byte[] variant. Just like + * {@link #BYTES_FIXED_SORTED}, but allowing each + * document's value to be a different length. + *

+ * NOTE: Fields of this type will not store values for documents without and + * explicitly provided value. If a documents value is accessed while no + * explicit value is stored the returned {@link BytesRef} will be a 0-length + * reference.Custom default values must be assigned explicitly. + *

+ * + * @see SortedSource + */ + BYTES_VAR_SORTED, + + /** + * A fixed length pre-sorted byte[] variant. Fields with this type only + * store distinct byte values and store an additional offset pointer per + * document to dereference the shared byte[]. The stored + * byte[] is presorted, by default by unsigned byte order, + * and allows access via document id, ordinal and by-value. + * Use this type if your documents may share the same byte[]. + *

+ * NOTE: Fields of this type will not store values for documents without and + * explicitly provided value. If a documents value is accessed while no + * explicit value is stored the returned {@link BytesRef} will be a 0-length + * reference. Custom default values must be assigned + * explicitly. + *

+ * + * @see SortedSource + */ + BYTES_FIXED_SORTED + + } + + /** + * Abstract base class for {@link DocValues} {@link Source} cache. + *

+ * {@link Source} instances loaded via {@link DocValues#load()} are entirely memory resident + * and need to be maintained by the caller. Each call to + * {@link DocValues#load()} will cause an entire reload of + * the underlying data. Source instances obtained from + * {@link DocValues#getSource()} and {@link DocValues#getSource()} + * respectively are maintained by a {@link SourceCache} that is closed ( + * {@link #close(DocValues)}) once the {@link IndexReader} that created the + * {@link DocValues} instance is closed. + *

+ * Unless {@link Source} instances are managed by another entity it is + * recommended to use the cached variants to obtain a source instance. + *

+ * Implementation of this API must be thread-safe. + * + * @see DocValues#setCache(SourceCache) + * @see DocValues#getSource() + * + * @lucene.experimental + */ + public static abstract class SourceCache { + + /** + * Atomically loads a {@link Source} into the cache from the given + * {@link DocValues} and returns it iff no other {@link Source} has already + * been cached. Otherwise the cached source is returned. + *

+ * This method will not return null + */ + public abstract Source load(DocValues values) throws IOException; + + /** + * Atomically invalidates the cached {@link Source} + * instances if any and empties the cache. + */ + public abstract void invalidate(DocValues values); + + /** + * Atomically closes the cache and frees all resources. + */ + public synchronized void close(DocValues values) { + invalidate(values); + } + + /** + * Simple per {@link DocValues} instance cache implementation that holds a + * {@link Source} a member variable. + *

+ * If a {@link DirectSourceCache} instance is closed or invalidated the cached + * reference are simply set to null + */ + public static final class DirectSourceCache extends SourceCache { + private Source ref; + + public synchronized Source load(DocValues values) throws IOException { + if (ref == null) { + ref = values.load(); + } + return ref; + } + + public synchronized void invalidate(DocValues values) { + ref = null; + } + } + } +} diff --git a/lucene/src/java/org/apache/lucene/index/FieldInfo.java b/lucene/src/java/org/apache/lucene/index/FieldInfo.java index 8b324f063f6..2c1123a285d 100644 --- a/lucene/src/java/org/apache/lucene/index/FieldInfo.java +++ b/lucene/src/java/org/apache/lucene/index/FieldInfo.java @@ -1,6 +1,6 @@ package org.apache.lucene.index; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -25,7 +25,7 @@ public final class FieldInfo { public final int number; public boolean isIndexed; - private ValueType docValues; + private DocValues.Type docValues; // true if term vector for this field should be stored @@ -57,7 +57,7 @@ public final class FieldInfo { */ public FieldInfo(String name, boolean isIndexed, int number, boolean storeTermVector, boolean storePositionWithTermVector, boolean storeOffsetWithTermVector, - boolean omitNorms, boolean storePayloads, IndexOptions indexOptions, ValueType docValues) { + boolean omitNorms, boolean storePayloads, IndexOptions indexOptions, DocValues.Type docValues) { this.name = name; this.isIndexed = isIndexed; this.number = number; @@ -119,13 +119,13 @@ public final class FieldInfo { assert this.indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !this.storePayloads; } - void setDocValuesType(ValueType v) { + void setDocValuesType(DocValues.Type v) { if (docValues == null) { docValues = v; } } - public void resetDocValuesType(ValueType v) { + public void resetDocValuesType(DocValues.Type v) { if (docValues != null) { docValues = v; } @@ -135,7 +135,7 @@ public final class FieldInfo { return docValues != null; } - public ValueType getDocValuesType() { + public DocValues.Type getDocValuesType() { return docValues; } diff --git a/lucene/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/src/java/org/apache/lucene/index/FieldInfos.java index a71d6e0403c..4abcd207d18 100644 --- a/lucene/src/java/org/apache/lucene/index/FieldInfos.java +++ b/lucene/src/java/org/apache/lucene/index/FieldInfos.java @@ -25,7 +25,7 @@ import java.util.SortedMap; import java.util.TreeMap; import org.apache.lucene.index.FieldInfo.IndexOptions; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues; /** Access to the Field Info file that describes document fields and whether or * not they are indexed. Each segment has a separate Field Info file. Objects @@ -299,7 +299,7 @@ public final class FieldInfos implements Iterable { */ synchronized public FieldInfo addOrUpdate(String name, boolean isIndexed, boolean storeTermVector, boolean storePositionWithTermVector, boolean storeOffsetWithTermVector, - boolean omitNorms, boolean storePayloads, IndexOptions indexOptions, ValueType docValues) { + boolean omitNorms, boolean storePayloads, IndexOptions indexOptions, DocValues.Type docValues) { return addOrUpdateInternal(name, -1, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, indexOptions, docValues); } @@ -322,7 +322,7 @@ public final class FieldInfos implements Iterable { synchronized private FieldInfo addOrUpdateInternal(String name, int preferredFieldNumber, boolean isIndexed, boolean storeTermVector, boolean storePositionWithTermVector, boolean storeOffsetWithTermVector, - boolean omitNorms, boolean storePayloads, IndexOptions indexOptions, ValueType docValues) { + boolean omitNorms, boolean storePayloads, IndexOptions indexOptions, DocValues.Type docValues) { if (globalFieldNumbers == null) { throw new IllegalStateException("FieldInfos are read-only, create a new instance with a global field map to make modifications to FieldInfos"); } @@ -351,7 +351,7 @@ public final class FieldInfos implements Iterable { */ private FieldInfo addInternal(String name, int fieldNumber, boolean isIndexed, boolean storeTermVector, boolean storePositionWithTermVector, - boolean storeOffsetWithTermVector, boolean omitNorms, boolean storePayloads, IndexOptions indexOptions, ValueType docValuesType) { + boolean storeOffsetWithTermVector, boolean omitNorms, boolean storePayloads, IndexOptions indexOptions, DocValues.Type docValuesType) { // don't check modifiable here since we use that to initially build up FIs if (globalFieldNumbers != null) { globalFieldNumbers.setIfNotSet(fieldNumber, name); diff --git a/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java b/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java index 822460571db..3c64cbeccd7 100644 --- a/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java +++ b/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java @@ -17,7 +17,6 @@ package org.apache.lucene.index; * limitations under the License. */ -import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; diff --git a/lucene/src/java/org/apache/lucene/index/IndexReader.java b/lucene/src/java/org/apache/lucene/index/IndexReader.java index 66352fcb2e4..592e66dd09e 100644 --- a/lucene/src/java/org/apache/lucene/index/IndexReader.java +++ b/lucene/src/java/org/apache/lucene/index/IndexReader.java @@ -28,8 +28,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.document.Document; import org.apache.lucene.document.DocumentStoredFieldVisitor; -import org.apache.lucene.index.codecs.PerDocValues; -import org.apache.lucene.index.values.IndexDocValues; import org.apache.lucene.search.FieldCache; // javadocs import org.apache.lucene.search.SearcherManager; // javadocs import org.apache.lucene.store.*; @@ -1148,7 +1146,7 @@ public abstract class IndexReader implements Cloneable,Closeable { throw new UnsupportedOperationException("This reader does not support this method."); } - public final IndexDocValues docValues(String field) throws IOException { + public final DocValues docValues(String field) throws IOException { ensureOpen(); final PerDocValues perDoc = perDocValues(); if (perDoc == null) { diff --git a/lucene/src/java/org/apache/lucene/index/IndexableField.java b/lucene/src/java/org/apache/lucene/index/IndexableField.java index 22782a5582d..4a2c8a95073 100644 --- a/lucene/src/java/org/apache/lucene/index/IndexableField.java +++ b/lucene/src/java/org/apache/lucene/index/IndexableField.java @@ -23,8 +23,7 @@ import java.io.Reader; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.NumericField; -import org.apache.lucene.index.values.PerDocFieldValues; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues; import org.apache.lucene.util.BytesRef; // TODO: how to handle versioning here...? @@ -80,7 +79,7 @@ public interface IndexableField { public PerDocFieldValues docValues(); /** DocValues type; only used if docValues is non-null */ - public ValueType docValuesType(); + public DocValues.Type docValuesType(); /** * Creates the TokenStream used for indexing this field. If appropriate, diff --git a/lucene/src/java/org/apache/lucene/index/values/MultiIndexDocValues.java b/lucene/src/java/org/apache/lucene/index/MultiDocValues.java similarity index 88% rename from lucene/src/java/org/apache/lucene/index/values/MultiIndexDocValues.java rename to lucene/src/java/org/apache/lucene/index/MultiDocValues.java index f89be42aa9c..529058e8362 100644 --- a/lucene/src/java/org/apache/lucene/index/values/MultiIndexDocValues.java +++ b/lucene/src/java/org/apache/lucene/index/MultiDocValues.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -24,20 +24,20 @@ import org.apache.lucene.util.ReaderUtil; /** * A wrapper for compound IndexReader providing access to per segment - * {@link IndexDocValues} + * {@link DocValues} * * @lucene.experimental * @lucene.internal */ -public class MultiIndexDocValues extends IndexDocValues { +public class MultiDocValues extends DocValues { public static class DocValuesIndex { public final static DocValuesIndex[] EMPTY_ARRAY = new DocValuesIndex[0]; final int start; final int length; - final IndexDocValues docValues; + final DocValues docValues; - public DocValuesIndex(IndexDocValues docValues, int start, int length) { + public DocValuesIndex(DocValues docValues, int start, int length) { this.docValues = docValues; this.start = start; this.length = length; @@ -46,15 +46,15 @@ public class MultiIndexDocValues extends IndexDocValues { private DocValuesIndex[] docValuesIdx; private int[] starts; - private ValueType type; + private Type type; private int valueSize; - public MultiIndexDocValues() { + public MultiDocValues() { starts = new int[0]; docValuesIdx = new DocValuesIndex[0]; } - public MultiIndexDocValues(DocValuesIndex[] docValuesIdx) { + public MultiDocValues(DocValuesIndex[] docValuesIdx) { reset(docValuesIdx); } @@ -63,7 +63,7 @@ public class MultiIndexDocValues extends IndexDocValues { return new MultiSource(docValuesIdx, starts, false); } - public IndexDocValues reset(DocValuesIndex[] docValuesIdx) { + public DocValues reset(DocValuesIndex[] docValuesIdx) { final int[] start = new int[docValuesIdx.length]; TypePromoter promoter = TypePromoter.getIdentityPromoter(); for (int i = 0; i < docValuesIdx.length; i++) { @@ -86,11 +86,11 @@ public class MultiIndexDocValues extends IndexDocValues { return this; } - public static class EmptyDocValues extends IndexDocValues { + public static class EmptyDocValues extends DocValues { final int maxDoc; final Source emptySource; - public EmptyDocValues(int maxDoc, ValueType type) { + public EmptyDocValues(int maxDoc, Type type) { this.maxDoc = maxDoc; this.emptySource = new EmptySource(type); } @@ -101,7 +101,7 @@ public class MultiIndexDocValues extends IndexDocValues { } @Override - public ValueType type() { + public Type type() { return emptySource.type(); } @@ -169,10 +169,10 @@ public class MultiIndexDocValues extends IndexDocValues { } } - // TODO: this is dup of IndexDocValues.getDefaultSource()? + // TODO: this is dup of DocValues.getDefaultSource()? private static class EmptySource extends Source { - public EmptySource(ValueType type) { + public EmptySource(Type type) { super(type); } @@ -195,7 +195,7 @@ public class MultiIndexDocValues extends IndexDocValues { } @Override - public ValueType type() { + public Type type() { return type; } diff --git a/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java b/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java index 79757a83a32..2411f5dca63 100644 --- a/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java +++ b/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java @@ -17,7 +17,6 @@ package org.apache.lucene.index; * limitations under the License. */ -import org.apache.lucene.index.values.MultiIndexDocValues; import org.apache.lucene.util.PriorityQueue; import org.apache.lucene.util.ReaderUtil; @@ -45,7 +44,7 @@ public final class MultiFieldsEnum extends FieldsEnum { // Re-used TermsEnum private final MultiTermsEnum terms; - private final MultiIndexDocValues docValues; + private final MultiDocValues docValues; private final Fields fields; @@ -57,7 +56,7 @@ public final class MultiFieldsEnum extends FieldsEnum { this.fields = fields; terms = new MultiTermsEnum(subSlices); queue = new FieldMergeQueue(subs.length); - docValues = new MultiIndexDocValues(); + docValues = new MultiDocValues(); top = new FieldsEnumWithSlice[subs.length]; List enumWithSlices = new ArrayList(); diff --git a/lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java b/lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java index 0d969797cc3..8f7a6a7d9e7 100644 --- a/lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java +++ b/lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java @@ -17,17 +17,12 @@ package org.apache.lucene.index; */ import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; -import org.apache.lucene.index.codecs.PerDocValues; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.MultiIndexDocValues; -import org.apache.lucene.index.values.ValueType; -import org.apache.lucene.index.values.MultiIndexDocValues.DocValuesIndex; +import org.apache.lucene.index.MultiDocValues.DocValuesIndex; +import org.apache.lucene.index.DocValues; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.ReaderUtil; import org.apache.lucene.util.ReaderUtil.Gather; @@ -48,7 +43,7 @@ import org.apache.lucene.util.ReaderUtil.Gather; public class MultiPerDocValues extends PerDocValues { private final PerDocValues[] subs; private final ReaderUtil.Slice[] subSlices; - private final Map docValues = new ConcurrentHashMap(); + private final Map docValues = new ConcurrentHashMap(); public MultiPerDocValues(PerDocValues[] subs, ReaderUtil.Slice[] subSlices) { this.subs = subs; @@ -106,40 +101,40 @@ public class MultiPerDocValues extends PerDocValues { return perDocValues; } - public IndexDocValues docValues(String field) throws IOException { - IndexDocValues result = docValues.get(field); + public DocValues docValues(String field) throws IOException { + DocValues result = docValues.get(field); if (result == null) { // Lazy init: first time this field is requested, we // create & add to docValues: - final List docValuesIndex = new ArrayList(); + final List docValuesIndex = new ArrayList(); int docsUpto = 0; - ValueType type = null; + DocValues.Type type = null; // Gather all sub-readers that share this field for (int i = 0; i < subs.length; i++) { - IndexDocValues values = subs[i].docValues(field); + DocValues values = subs[i].docValues(field); final int start = subSlices[i].start; final int length = subSlices[i].length; if (values != null) { if (docsUpto != start) { type = values.type(); - docValuesIndex.add(new MultiIndexDocValues.DocValuesIndex( - new MultiIndexDocValues.EmptyDocValues(start, type), docsUpto, start + docValuesIndex.add(new MultiDocValues.DocValuesIndex( + new MultiDocValues.EmptyDocValues(start, type), docsUpto, start - docsUpto)); } - docValuesIndex.add(new MultiIndexDocValues.DocValuesIndex(values, start, + docValuesIndex.add(new MultiDocValues.DocValuesIndex(values, start, length)); docsUpto = start + length; } else if (i + 1 == subs.length && !docValuesIndex.isEmpty()) { - docValuesIndex.add(new MultiIndexDocValues.DocValuesIndex( - new MultiIndexDocValues.EmptyDocValues(start, type), docsUpto, start + docValuesIndex.add(new MultiDocValues.DocValuesIndex( + new MultiDocValues.EmptyDocValues(start, type), docsUpto, start - docsUpto)); } } if (docValuesIndex.isEmpty()) { return null; } - result = new MultiIndexDocValues( + result = new MultiDocValues( docValuesIndex.toArray(DocValuesIndex.EMPTY_ARRAY)); docValues.put(field, result); } diff --git a/lucene/src/java/org/apache/lucene/index/MultiReader.java b/lucene/src/java/org/apache/lucene/index/MultiReader.java index fdc364dfe4f..6eb41266918 100644 --- a/lucene/src/java/org/apache/lucene/index/MultiReader.java +++ b/lucene/src/java/org/apache/lucene/index/MultiReader.java @@ -22,7 +22,6 @@ import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.ReaderUtil; diff --git a/lucene/src/java/org/apache/lucene/index/ParallelReader.java b/lucene/src/java/org/apache/lucene/index/ParallelReader.java index af008ea38b5..6b3d9eaf9f8 100644 --- a/lucene/src/java/org/apache/lucene/index/ParallelReader.java +++ b/lucene/src/java/org/apache/lucene/index/ParallelReader.java @@ -17,8 +17,6 @@ package org.apache.lucene.index; * limitations under the License. */ -import org.apache.lucene.index.codecs.PerDocValues; -import org.apache.lucene.index.values.IndexDocValues; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.MapBackedSet; @@ -472,7 +470,7 @@ public class ParallelReader extends IndexReader { // Single instance of this, per ParallelReader instance private static final class ParallelPerDocs extends PerDocValues { - final TreeMap fields = new TreeMap(); + final TreeMap fields = new TreeMap(); void addField(String field, IndexReader r) throws IOException { PerDocValues perDocs = MultiPerDocValues.getPerDocs(r); @@ -487,7 +485,7 @@ public class ParallelReader extends IndexReader { } @Override - public IndexDocValues docValues(String field) throws IOException { + public DocValues docValues(String field) throws IOException { return fields.get(field); } } diff --git a/lucene/src/java/org/apache/lucene/index/values/PerDocFieldValues.java b/lucene/src/java/org/apache/lucene/index/PerDocFieldValues.java similarity index 73% rename from lucene/src/java/org/apache/lucene/index/values/PerDocFieldValues.java rename to lucene/src/java/org/apache/lucene/index/PerDocFieldValues.java index 74e67e12ffe..c82545eed6d 100644 --- a/lucene/src/java/org/apache/lucene/index/values/PerDocFieldValues.java +++ b/lucene/src/java/org/apache/lucene/index/PerDocFieldValues.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -18,13 +18,15 @@ package org.apache.lucene.index.values; */ import java.util.Comparator; -import org.apache.lucene.document.IndexDocValuesField; -import org.apache.lucene.index.codecs.DocValuesConsumer; +import org.apache.lucene.document.DocValuesField; +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.DocValues.Type; // javadocs +import org.apache.lucene.index.codecs.DocValuesConsumer; // javadocs import org.apache.lucene.util.BytesRef; /** * Per document and field values consumed by {@link DocValuesConsumer}. - * @see IndexDocValuesField + * @see DocValuesField * * @lucene.experimental */ @@ -46,19 +48,19 @@ public interface PerDocFieldValues { public void setFloat(double value); /** - * Sets the given {@link BytesRef} value and the field's {@link ValueType}. The + * Sets the given {@link BytesRef} value and the field's {@link Type}. The * comparator for this field is set to null. If a * null comparator is set the default comparator for the given - * {@link ValueType} is used. + * {@link Type} is used. */ - public void setBytes(BytesRef value, ValueType type); + public void setBytes(BytesRef value, DocValues.Type type); /** - * Sets the given {@link BytesRef} value, the field's {@link ValueType} and the + * Sets the given {@link BytesRef} value, the field's {@link Type} and the * field's comparator. If the {@link Comparator} is set to null - * the default for the given {@link ValueType} is used instead. + * the default for the given {@link Type} is used instead. */ - public void setBytes(BytesRef value, ValueType type, Comparator comp); + public void setBytes(BytesRef value, DocValues.Type type, Comparator comp); /** * Returns the set {@link BytesRef} or null if not set. @@ -82,17 +84,17 @@ public interface PerDocFieldValues { /** * Sets the {@link BytesRef} comparator for this field. If the field has a - * numeric {@link ValueType} the comparator will be ignored. + * numeric {@link Type} the comparator will be ignored. */ public void setBytesComparator(Comparator comp); /** - * Sets the {@link ValueType} + * Sets the {@link Type} */ - public void setDocValuesType(ValueType type); + public void setDocValuesType(DocValues.Type type); /** - * Returns the {@link ValueType} + * Returns the {@link Type} */ - public ValueType docValuesType(); + public DocValues.Type docValuesType(); } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/PerDocValues.java b/lucene/src/java/org/apache/lucene/index/PerDocValues.java similarity index 82% rename from lucene/src/java/org/apache/lucene/index/codecs/PerDocValues.java rename to lucene/src/java/org/apache/lucene/index/PerDocValues.java index cd6cc1ddb04..08a91577d02 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/PerDocValues.java +++ b/lucene/src/java/org/apache/lucene/index/PerDocValues.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.codecs; +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 @@ -18,7 +18,8 @@ package org.apache.lucene.index.codecs; import java.io.Closeable; import java.io.IOException; -import org.apache.lucene.index.values.IndexDocValues; +import org.apache.lucene.index.codecs.PerDocConsumer; +import org.apache.lucene.index.codecs.PostingsFormat; /** * Abstract API that provides access to one or more per-document storage @@ -34,15 +35,15 @@ import org.apache.lucene.index.values.IndexDocValues; */ public abstract class PerDocValues implements Closeable { /** - * Returns {@link IndexDocValues} for the current field. + * Returns {@link DocValues} for the current field. * * @param field * the field name - * @return the {@link IndexDocValues} for this field or null if not + * @return the {@link DocValues} for this field or null if not * applicable. * @throws IOException */ - public abstract IndexDocValues docValues(String field) throws IOException; + public abstract DocValues docValues(String field) throws IOException; public static final PerDocValues[] EMPTY_ARRAY = new PerDocValues[0]; } diff --git a/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java b/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java index 57769522e42..65755b43a28 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java @@ -25,7 +25,6 @@ import org.apache.lucene.index.codecs.NormsReader; import org.apache.lucene.index.codecs.PostingsFormat; import org.apache.lucene.index.codecs.FieldsProducer; import org.apache.lucene.index.codecs.StoredFieldsReader; -import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.index.codecs.TermVectorsReader; import org.apache.lucene.store.CompoundFileDirectory; import org.apache.lucene.store.Directory; diff --git a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java index 5d33bb6d5e0..c338e3c248f 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentMerger.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentMerger.java @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.IndexReader.FieldOption; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.FieldInfosWriter; import org.apache.lucene.index.codecs.FieldsConsumer; @@ -33,9 +34,6 @@ import org.apache.lucene.index.codecs.NormsWriter; import org.apache.lucene.index.codecs.StoredFieldsWriter; import org.apache.lucene.index.codecs.PerDocConsumer; import org.apache.lucene.index.codecs.TermVectorsWriter; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.TypePromoter; -import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.util.Bits; @@ -191,7 +189,7 @@ final class SegmentMerger { // returns an updated typepromoter (tracking type and size) given a previous one, // and a newly encountered docvalues - private TypePromoter mergeDocValuesType(TypePromoter previous, IndexDocValues docValues) { + private TypePromoter mergeDocValuesType(TypePromoter previous, DocValues docValues) { TypePromoter incoming = TypePromoter.create(docValues.type(), docValues.getValueSize()); if (previous == null) { previous = TypePromoter.getIdentityPromoter(); @@ -199,7 +197,7 @@ final class SegmentMerger { TypePromoter promoted = previous.promote(incoming); if (promoted == null) { // type is incompatible: promote to BYTES_VAR_STRAIGHT - return TypePromoter.create(ValueType.BYTES_VAR_STRAIGHT, TypePromoter.VAR_TYPE_VALUE_SIZE); + return TypePromoter.create(DocValues.Type.BYTES_VAR_STRAIGHT, TypePromoter.VAR_TYPE_VALUE_SIZE); } else { return promoted; } @@ -237,7 +235,7 @@ final class SegmentMerger { mergeState.fieldInfos.addOrUpdate(dvNames, false); for (String dvName : dvNames) { FieldInfo merged = mergeState.fieldInfos.fieldInfo(dvName); - IndexDocValues docValues = reader.docValues(dvName); + DocValues docValues = reader.docValues(dvName); merged.setDocValuesType(docValues.type()); TypePromoter previous = docValuesTypes.get(merged); docValuesTypes.put(merged, mergeDocValuesType(previous, docValues)); diff --git a/lucene/src/java/org/apache/lucene/index/SegmentReader.java b/lucene/src/java/org/apache/lucene/index/SegmentReader.java index f94fa0dfad4..7eb54687616 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentReader.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentReader.java @@ -28,7 +28,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.store.Directory; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.codecs.StoredFieldsReader; -import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.index.codecs.TermVectorsReader; import org.apache.lucene.store.IOContext; import org.apache.lucene.util.BitVector; diff --git a/lucene/src/java/org/apache/lucene/index/SlowMultiReaderWrapper.java b/lucene/src/java/org/apache/lucene/index/SlowMultiReaderWrapper.java index 75db4a5b2a0..f945f5e4976 100644 --- a/lucene/src/java/org/apache/lucene/index/SlowMultiReaderWrapper.java +++ b/lucene/src/java/org/apache/lucene/index/SlowMultiReaderWrapper.java @@ -26,7 +26,6 @@ import org.apache.lucene.util.ReaderUtil; // javadoc import org.apache.lucene.index.DirectoryReader; // javadoc import org.apache.lucene.index.MultiReader; // javadoc -import org.apache.lucene.index.codecs.PerDocValues; /** * This class forces a composite reader (eg a {@link diff --git a/lucene/src/java/org/apache/lucene/index/values/TypePromoter.java b/lucene/src/java/org/apache/lucene/index/TypePromoter.java similarity index 88% rename from lucene/src/java/org/apache/lucene/index/values/TypePromoter.java rename to lucene/src/java/org/apache/lucene/index/TypePromoter.java index ac8544e01a6..baed1b94c4f 100644 --- a/lucene/src/java/org/apache/lucene/index/values/TypePromoter.java +++ b/lucene/src/java/org/apache/lucene/index/TypePromoter.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.values; +package org.apache.lucene.index; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -19,15 +19,17 @@ package org.apache.lucene.index.values; import java.util.HashMap; import java.util.Map; +import org.apache.lucene.index.DocValues.Type; + /** - * Type promoter that promotes {@link IndexDocValues} during merge based on - * their {@link ValueType} and {@link #getValueSize()} + * Type promoter that promotes {@link DocValues} during merge based on + * their {@link Type} and {@link #getValueSize()} * * @lucene.internal */ -public class TypePromoter { +class TypePromoter { - private final static Map FLAGS_MAP = new HashMap(); + private final static Map FLAGS_MAP = new HashMap(); private static final TypePromoter IDENTITY_PROMOTER = new IdentityTypePromoter(); public static final int VAR_TYPE_VALUE_SIZE = -1; @@ -49,7 +51,7 @@ public class TypePromoter { private static final int IS_32_BIT = 1 << 10 | 1 << 11; private static final int IS_64_BIT = 1 << 11; - private final ValueType type; + private final Type type; private final int flags; private final int valueSize; @@ -65,7 +67,7 @@ public class TypePromoter { } static { - for (ValueType type : ValueType.values()) { + for (Type type : Type.values()) { TypePromoter create = create(type, VAR_TYPE_VALUE_SIZE); FLAGS_MAP.put(create.flags, type); } @@ -75,13 +77,13 @@ public class TypePromoter { * Creates a new {@link TypePromoter} * * @param type - * the {@link ValueType} this promoter represents + * the {@link Type} this promoter represents * @param flags * the promoters flags * @param valueSize * the value size if {@link #IS_FIXED} or -1 otherwise. */ - protected TypePromoter(ValueType type, int flags, int valueSize) { + protected TypePromoter(Type type, int flags, int valueSize) { this.type = type; this.flags = flags; this.valueSize = valueSize; @@ -117,11 +119,11 @@ public class TypePromoter { } /** - * Returns the {@link ValueType} of this {@link TypePromoter} + * Returns the {@link Type} of this {@link TypePromoter} * - * @return the {@link ValueType} of this {@link TypePromoter} + * @return the {@link Type} of this {@link TypePromoter} */ - public ValueType type() { + public Type type() { return type; } @@ -134,13 +136,13 @@ public class TypePromoter { * Creates a new {@link TypePromoter} for the given type and size per value. * * @param type - * the {@link ValueType} to create the promoter for + * the {@link Type} to create the promoter for * @param valueSize * the size per value in bytes or -1 iff the types have * variable length. * @return a new {@link TypePromoter} */ - public static TypePromoter create(ValueType type, int valueSize) { + public static TypePromoter create(Type type, int valueSize) { if (type == null) { return null; } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java index b2e89456448..e8ddee5088e 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java @@ -18,10 +18,10 @@ package org.apache.lucene.index.codecs; */ import java.io.IOException; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.MergeState; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.PerDocFieldValues; +import org.apache.lucene.index.PerDocFieldValues; import org.apache.lucene.util.Bits; /** @@ -70,11 +70,11 @@ public abstract class DocValuesConsumer { * the state to merge * @param docValues docValues array containing one instance per reader ( * {@link org.apache.lucene.index.MergeState#readers}) or null if the reader has - * no {@link IndexDocValues} instance. + * no {@link DocValues} instance. * @throws IOException * if an {@link IOException} occurs */ - public void merge(MergeState mergeState, IndexDocValues[] docValues) throws IOException { + public void merge(MergeState mergeState, DocValues[] docValues) throws IOException { assert mergeState != null; boolean hasMerged = false; for(int readerIDX=0;readerIDX closeables) throws IOException; - protected abstract Map docValues(); + protected abstract Map docValues(); @Override public void close() throws IOException { @@ -50,7 +52,7 @@ public abstract class DocValuesReaderBase extends PerDocValues { } @Override - public IndexDocValues docValues(String field) throws IOException { + public DocValues docValues(String field) throws IOException { return docValues().get(field); } @@ -59,10 +61,10 @@ public abstract class DocValuesReaderBase extends PerDocValues { } // Only opens files... doesn't actually load any values - protected TreeMap load(FieldInfos fieldInfos, + protected TreeMap load(FieldInfos fieldInfos, String segment, int docCount, Directory dir, IOContext context) throws IOException { - TreeMap values = new TreeMap(); + TreeMap values = new TreeMap(); boolean success = false; try { @@ -88,26 +90,26 @@ public abstract class DocValuesReaderBase extends PerDocValues { } /** - * Loads a {@link IndexDocValues} instance depending on the given {@link ValueType}. - * Codecs that use different implementations for a certain {@link ValueType} can + * Loads a {@link DocValues} instance depending on the given {@link Type}. + * Codecs that use different implementations for a certain {@link Type} can * simply override this method and return their custom implementations. * * @param docCount * number of documents in the segment * @param dir - * the {@link Directory} to load the {@link IndexDocValues} from + * the {@link Directory} to load the {@link DocValues} from * @param id * the unique file ID within the segment * @param type * the type to load - * @return a {@link IndexDocValues} instance for the given type + * @return a {@link DocValues} instance for the given type * @throws IOException * if an {@link IOException} occurs * @throws IllegalArgumentException - * if the given {@link ValueType} is not supported + * if the given {@link Type} is not supported */ - protected IndexDocValues loadDocValues(int docCount, Directory dir, String id, - ValueType type, IOContext context) throws IOException { + protected DocValues loadDocValues(int docCount, Directory dir, String id, + DocValues.Type type, IOContext context) throws IOException { switch (type) { case FIXED_INTS_16: case FIXED_INTS_32: diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java index ad57ac49679..86261c1c3ce 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesWriterBase.java @@ -23,7 +23,7 @@ import java.util.Comparator; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.codecs.lucene40.values.Writer; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.util.BytesRef; @@ -33,6 +33,7 @@ import org.apache.lucene.util.Counter; * Abstract base class for PerDocConsumer implementations * @lucene.experimental */ +//TODO: this needs to go under lucene40 codec (its specific to its impl) public abstract class DocValuesWriterBase extends PerDocConsumer { protected final String segmentName; protected final String segmentSuffix; @@ -53,7 +54,7 @@ public abstract class DocValuesWriterBase extends PerDocConsumer { } @Override - public DocValuesConsumer addValuesField(ValueType valueType, FieldInfo field) throws IOException { + public DocValuesConsumer addValuesField(DocValues.Type valueType, FieldInfo field) throws IOException { return Writer.create(valueType, docValuesId(segmentName, field.number), getDirectory(), getComparator(), bytesUsed, context); diff --git a/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java index 60cacd81671..f2d1f814be9 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java @@ -19,9 +19,9 @@ import java.io.Closeable; import java.io.IOException; import org.apache.lucene.index.FieldInfo; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.MergeState; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.PerDocValues; /** * Abstract API that consumes per document values. Concrete implementations of @@ -35,7 +35,7 @@ import org.apache.lucene.index.values.ValueType; */ public abstract class PerDocConsumer implements Closeable{ /** Adds a new DocValuesField */ - public abstract DocValuesConsumer addValuesField(ValueType type, FieldInfo field) + public abstract DocValuesConsumer addValuesField(DocValues.Type type, FieldInfo field) throws IOException; /** @@ -43,7 +43,7 @@ public abstract class PerDocConsumer implements Closeable{ * into this consumers format. */ public void merge(MergeState mergeState) throws IOException { - final IndexDocValues[] docValues = new IndexDocValues[mergeState.readers.size()]; + final DocValues[] docValues = new DocValues[mergeState.readers.size()]; final PerDocValues[] perDocValues = new PerDocValues[mergeState.readers.size()]; // pull all PerDocValues for (int i = 0; i < perDocValues.length; i++) { diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xCodec.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xCodec.java index ab74a789676..19689788375 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xCodec.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xCodec.java @@ -20,6 +20,7 @@ package org.apache.lucene.index.codecs.lucene3x; import java.io.IOException; import java.util.Set; +import org.apache.lucene.index.PerDocValues; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentReadState; @@ -29,7 +30,6 @@ import org.apache.lucene.index.codecs.FieldInfosFormat; import org.apache.lucene.index.codecs.NormsFormat; import org.apache.lucene.index.codecs.StoredFieldsFormat; import org.apache.lucene.index.codecs.PerDocConsumer; -import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.index.codecs.PostingsFormat; import org.apache.lucene.index.codecs.SegmentInfosFormat; import org.apache.lucene.index.codecs.TermVectorsFormat; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesFormat.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesFormat.java index 0f0a1fb7de7..0257e8ba9bf 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesFormat.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesFormat.java @@ -20,12 +20,12 @@ package org.apache.lucene.index.codecs.lucene40; import java.io.IOException; import java.util.Set; +import org.apache.lucene.index.PerDocValues; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.index.codecs.DocValuesFormat; import org.apache.lucene.index.codecs.PerDocConsumer; -import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.store.Directory; public class Lucene40DocValuesFormat extends DocValuesFormat { diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesProducer.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesProducer.java index f9c43c87aaa..c737486d610 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesProducer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesProducer.java @@ -24,10 +24,10 @@ import java.util.Collection; import java.util.Map; import java.util.TreeMap; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.index.codecs.DocValuesReaderBase; -import org.apache.lucene.index.values.IndexDocValues; import org.apache.lucene.store.CompoundFileDirectory; import org.apache.lucene.store.Directory; import org.apache.lucene.util.IOUtils; @@ -37,12 +37,12 @@ import org.apache.lucene.util.IOUtils; * @lucene.experimental */ public class Lucene40DocValuesProducer extends DocValuesReaderBase { - protected final TreeMap docValues; + protected final TreeMap docValues; private final Directory cfs; /** * Creates a new {@link Lucene40DocValuesProducer} instance and loads all - * {@link IndexDocValues} instances for this segment and codec. + * {@link DocValues} instances for this segment and codec. */ public Lucene40DocValuesProducer(SegmentReadState state) throws IOException { if (state.fieldInfos.anyDocValuesFields()) { @@ -53,12 +53,12 @@ public class Lucene40DocValuesProducer extends DocValuesReaderBase { docValues = load(state.fieldInfos, state.segmentInfo.name, state.segmentInfo.docCount, cfs, state.context); } else { cfs = null; - docValues = new TreeMap(); + docValues = new TreeMap(); } } @Override - protected Map docValues() { + protected Map docValues() { return docValues; } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40FieldInfosReader.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40FieldInfosReader.java index 1842538d18f..04ad825eab6 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40FieldInfosReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40FieldInfosReader.java @@ -12,7 +12,7 @@ import org.apache.lucene.index.IndexFormatTooOldException; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.FieldInfo.IndexOptions; import org.apache.lucene.index.codecs.FieldInfosReader; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -95,7 +95,7 @@ public class Lucene40FieldInfosReader extends FieldInfosReader { hasVectors |= storeTermVector; hasProx |= isIndexed && indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS; hasFreq |= isIndexed && indexOptions != IndexOptions.DOCS_ONLY; - ValueType docValuesType = null; + DocValues.Type docValuesType = null; if (format <= Lucene40FieldInfosWriter.FORMAT_FLEX) { final byte b = input.readByte(); switch(b) { @@ -103,43 +103,43 @@ public class Lucene40FieldInfosReader extends FieldInfosReader { docValuesType = null; break; case 1: - docValuesType = ValueType.VAR_INTS; + docValuesType = DocValues.Type.VAR_INTS; break; case 2: - docValuesType = ValueType.FLOAT_32; + docValuesType = DocValues.Type.FLOAT_32; break; case 3: - docValuesType = ValueType.FLOAT_64; + docValuesType = DocValues.Type.FLOAT_64; break; case 4: - docValuesType = ValueType.BYTES_FIXED_STRAIGHT; + docValuesType = DocValues.Type.BYTES_FIXED_STRAIGHT; break; case 5: - docValuesType = ValueType.BYTES_FIXED_DEREF; + docValuesType = DocValues.Type.BYTES_FIXED_DEREF; break; case 6: - docValuesType = ValueType.BYTES_VAR_STRAIGHT; + docValuesType = DocValues.Type.BYTES_VAR_STRAIGHT; break; case 7: - docValuesType = ValueType.BYTES_VAR_DEREF; + docValuesType = DocValues.Type.BYTES_VAR_DEREF; break; case 8: - docValuesType = ValueType.FIXED_INTS_16; + docValuesType = DocValues.Type.FIXED_INTS_16; break; case 9: - docValuesType = ValueType.FIXED_INTS_32; + docValuesType = DocValues.Type.FIXED_INTS_32; break; case 10: - docValuesType = ValueType.FIXED_INTS_64; + docValuesType = DocValues.Type.FIXED_INTS_64; break; case 11: - docValuesType = ValueType.FIXED_INTS_8; + docValuesType = DocValues.Type.FIXED_INTS_8; break; case 12: - docValuesType = ValueType.BYTES_FIXED_SORTED; + docValuesType = DocValues.Type.BYTES_FIXED_SORTED; break; case 13: - docValuesType = ValueType.BYTES_VAR_SORTED; + docValuesType = DocValues.Type.BYTES_VAR_SORTED; break; default: diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java index 792ca190fdb..2b227e32d8a 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java @@ -22,12 +22,12 @@ import java.io.IOException; import java.util.Comparator; import java.util.concurrent.atomic.AtomicLong; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexFileNames; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.PerDocFieldValues; -import org.apache.lucene.index.values.ValueType; -import org.apache.lucene.index.values.IndexDocValues.SortedSource; -import org.apache.lucene.index.values.IndexDocValues.Source; +import org.apache.lucene.index.PerDocFieldValues; +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.store.DataOutput; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; @@ -150,13 +150,13 @@ public final class Bytes { } /** - * Creates a new {@link IndexDocValues} instance that provides either memory + * Creates a new {@link DocValues} instance that provides either memory * resident or iterative access to a per-document stored byte[] - * value. The returned {@link IndexDocValues} instance will be initialized without + * value. The returned {@link DocValues} instance will be initialized without * consuming a significant amount of memory. * * @param dir - * the directory to load the {@link IndexDocValues} from. + * the directory to load the {@link DocValues} from. * @param id * the file ID in the {@link Directory} to load the values from. * @param mode @@ -169,11 +169,11 @@ public final class Bytes { * @param sortComparator {@link BytesRef} comparator used by sorted variants. * If null {@link BytesRef#getUTF8SortedAsUnicodeComparator()} * is used instead - * @return an initialized {@link IndexDocValues} instance. + * @return an initialized {@link DocValues} instance. * @throws IOException * if an {@link IOException} occurs */ - public static IndexDocValues getValues(Directory dir, String id, Mode mode, + public static DocValues getValues(Directory dir, String id, Mode mode, boolean fixedSize, int maxDoc, Comparator sortComparator, IOContext context) throws IOException { if (sortComparator == null) { sortComparator = BytesRef.getUTF8SortedAsUnicodeComparator(); @@ -185,7 +185,7 @@ public final class Bytes { } else if (mode == Mode.DEREF) { return new FixedDerefBytesImpl.FixedDerefReader(dir, id, maxDoc, context); } else if (mode == Mode.SORTED) { - return new FixedSortedBytesImpl.Reader(dir, id, maxDoc, context, ValueType.BYTES_FIXED_SORTED, sortComparator); + return new FixedSortedBytesImpl.Reader(dir, id, maxDoc, context, Type.BYTES_FIXED_SORTED, sortComparator); } } else { if (mode == Mode.STRAIGHT) { @@ -193,7 +193,7 @@ public final class Bytes { } else if (mode == Mode.DEREF) { return new VarDerefBytesImpl.VarDerefReader(dir, id, maxDoc, context); } else if (mode == Mode.SORTED) { - return new VarSortedBytesImpl.Reader(dir, id, maxDoc,context, ValueType.BYTES_VAR_SORTED, sortComparator); + return new VarSortedBytesImpl.Reader(dir, id, maxDoc,context, Type.BYTES_VAR_SORTED, sortComparator); } } @@ -211,7 +211,7 @@ public final class Bytes { protected BytesSourceBase(IndexInput datIn, IndexInput idxIn, - PagedBytes pagedBytes, long bytesToRead, ValueType type) throws IOException { + PagedBytes pagedBytes, long bytesToRead, Type type) throws IOException { super(type); assert bytesToRead <= datIn.length() : " file size is less than the expected size diff: " + (bytesToRead - datIn.length()) + " pos: " + datIn.getFilePointer(); @@ -314,15 +314,15 @@ public final class Bytes { * Opens all necessary files, but does not read any data in until you call * {@link #load}. */ - static abstract class BytesReaderBase extends IndexDocValues { + static abstract class BytesReaderBase extends DocValues { protected final IndexInput idxIn; protected final IndexInput datIn; protected final int version; protected final String id; - protected final ValueType type; + protected final Type type; protected BytesReaderBase(Directory dir, String id, String codecName, - int maxVersion, boolean doIndex, IOContext context, ValueType type) throws IOException { + int maxVersion, boolean doIndex, IOContext context, Type type) throws IOException { IndexInput dataIn = null; IndexInput indexIn = null; boolean success = false; @@ -375,7 +375,7 @@ public final class Bytes { } @Override - public ValueType type() { + public Type type() { return type; } @@ -559,12 +559,12 @@ public final class Bytes { protected final PagedBytes.Reader data; protected BytesSortedSourceBase(IndexInput datIn, IndexInput idxIn, - Comparator comp, long bytesToRead, ValueType type, boolean hasOffsets) throws IOException { + Comparator comp, long bytesToRead, Type type, boolean hasOffsets) throws IOException { this(datIn, idxIn, comp, new PagedBytes(PAGED_BYTES_BITS), bytesToRead, type, hasOffsets); } protected BytesSortedSourceBase(IndexInput datIn, IndexInput idxIn, - Comparator comp, PagedBytes pagedBytes, long bytesToRead, ValueType type, boolean hasOffsets) + Comparator comp, PagedBytes pagedBytes, long bytesToRead, Type type, boolean hasOffsets) throws IOException { super(type, comp); assert bytesToRead <= datIn.length() : " file size is less than the expected size diff: " diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/DirectSource.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/DirectSource.java index 02a957e9b65..d5ee351801d 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/DirectSource.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/DirectSource.java @@ -19,9 +19,9 @@ package org.apache.lucene.index.codecs.lucene40.values; import java.io.IOException; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.ValueType; -import org.apache.lucene.index.values.IndexDocValues.Source; +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.DocValues.Source; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.BytesRef; @@ -35,7 +35,7 @@ public abstract class DirectSource extends Source { private final ToNumeric toNumeric; protected final long baseOffset; - public DirectSource(IndexInput input, ValueType type) { + public DirectSource(IndexInput input, Type type) { super(type); this.data = input; baseOffset = input.getFilePointer(); diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/IndexDocValuesArray.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/DocValuesArray.java similarity index 71% rename from lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/IndexDocValuesArray.java rename to lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/DocValuesArray.java index e1180c14089..cc3c76acc8a 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/IndexDocValuesArray.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/DocValuesArray.java @@ -5,8 +5,8 @@ import java.util.Collections; import java.util.EnumMap; import java.util.Map; -import org.apache.lucene.index.values.ValueType; -import org.apache.lucene.index.values.IndexDocValues.Source; +import org.apache.lucene.index.DocValues.Source; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.store.IndexInput; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.RamUsageEstimator; @@ -31,30 +31,30 @@ import org.apache.lucene.util.RamUsageEstimator; /** * @lucene.experimental */ -abstract class IndexDocValuesArray extends Source { +abstract class DocValuesArray extends Source { - static final Map TEMPLATES; + static final Map TEMPLATES; static { - EnumMap templates = new EnumMap( - ValueType.class); - templates.put(ValueType.FIXED_INTS_16, new ShortValues()); - templates.put(ValueType.FIXED_INTS_32, new IntValues()); - templates.put(ValueType.FIXED_INTS_64, new LongValues()); - templates.put(ValueType.FIXED_INTS_8, new ByteValues()); - templates.put(ValueType.FLOAT_32, new FloatValues()); - templates.put(ValueType.FLOAT_64, new DoubleValues()); + EnumMap templates = new EnumMap( + Type.class); + templates.put(Type.FIXED_INTS_16, new ShortValues()); + templates.put(Type.FIXED_INTS_32, new IntValues()); + templates.put(Type.FIXED_INTS_64, new LongValues()); + templates.put(Type.FIXED_INTS_8, new ByteValues()); + templates.put(Type.FLOAT_32, new FloatValues()); + templates.put(Type.FLOAT_64, new DoubleValues()); TEMPLATES = Collections.unmodifiableMap(templates); } protected final int bytesPerValue; - IndexDocValuesArray(int bytesPerValue, ValueType type) { + DocValuesArray(int bytesPerValue, Type type) { super(type); this.bytesPerValue = bytesPerValue; } - public abstract IndexDocValuesArray newFromInput(IndexInput input, int numDocs) + public abstract DocValuesArray newFromInput(IndexInput input, int numDocs) throws IOException; @Override @@ -70,16 +70,16 @@ abstract class IndexDocValuesArray extends Source { BytesRefUtils.copyLong(bytesRef, Double.doubleToRawLongBits(value)); } - final static class ByteValues extends IndexDocValuesArray { + final static class ByteValues extends DocValuesArray { private final byte[] values; ByteValues() { - super(1, ValueType.FIXED_INTS_8); + super(1, Type.FIXED_INTS_8); values = new byte[0]; } private ByteValues(IndexInput input, int numDocs) throws IOException { - super(1, ValueType.FIXED_INTS_8); + super(1, Type.FIXED_INTS_8); values = new byte[numDocs]; input.readBytes(values, 0, values.length, false); } @@ -96,7 +96,7 @@ abstract class IndexDocValuesArray extends Source { } @Override - public IndexDocValuesArray newFromInput(IndexInput input, int numDocs) + public DocValuesArray newFromInput(IndexInput input, int numDocs) throws IOException { return new ByteValues(input, numDocs); } @@ -107,16 +107,16 @@ abstract class IndexDocValuesArray extends Source { }; - final static class ShortValues extends IndexDocValuesArray { + final static class ShortValues extends DocValuesArray { private final short[] values; ShortValues() { - super(RamUsageEstimator.NUM_BYTES_SHORT, ValueType.FIXED_INTS_16); + super(RamUsageEstimator.NUM_BYTES_SHORT, Type.FIXED_INTS_16); values = new short[0]; } private ShortValues(IndexInput input, int numDocs) throws IOException { - super(RamUsageEstimator.NUM_BYTES_SHORT, ValueType.FIXED_INTS_16); + super(RamUsageEstimator.NUM_BYTES_SHORT, Type.FIXED_INTS_16); values = new short[numDocs]; for (int i = 0; i < values.length; i++) { values[i] = input.readShort(); @@ -135,7 +135,7 @@ abstract class IndexDocValuesArray extends Source { } @Override - public IndexDocValuesArray newFromInput(IndexInput input, int numDocs) + public DocValuesArray newFromInput(IndexInput input, int numDocs) throws IOException { return new ShortValues(input, numDocs); } @@ -146,16 +146,16 @@ abstract class IndexDocValuesArray extends Source { }; - final static class IntValues extends IndexDocValuesArray { + final static class IntValues extends DocValuesArray { private final int[] values; IntValues() { - super(RamUsageEstimator.NUM_BYTES_INT, ValueType.FIXED_INTS_32); + super(RamUsageEstimator.NUM_BYTES_INT, Type.FIXED_INTS_32); values = new int[0]; } private IntValues(IndexInput input, int numDocs) throws IOException { - super(RamUsageEstimator.NUM_BYTES_INT, ValueType.FIXED_INTS_32); + super(RamUsageEstimator.NUM_BYTES_INT, Type.FIXED_INTS_32); values = new int[numDocs]; for (int i = 0; i < values.length; i++) { values[i] = input.readInt(); @@ -174,7 +174,7 @@ abstract class IndexDocValuesArray extends Source { } @Override - public IndexDocValuesArray newFromInput(IndexInput input, int numDocs) + public DocValuesArray newFromInput(IndexInput input, int numDocs) throws IOException { return new IntValues(input, numDocs); } @@ -185,16 +185,16 @@ abstract class IndexDocValuesArray extends Source { }; - final static class LongValues extends IndexDocValuesArray { + final static class LongValues extends DocValuesArray { private final long[] values; LongValues() { - super(RamUsageEstimator.NUM_BYTES_LONG, ValueType.FIXED_INTS_64); + super(RamUsageEstimator.NUM_BYTES_LONG, Type.FIXED_INTS_64); values = new long[0]; } private LongValues(IndexInput input, int numDocs) throws IOException { - super(RamUsageEstimator.NUM_BYTES_LONG, ValueType.FIXED_INTS_64); + super(RamUsageEstimator.NUM_BYTES_LONG, Type.FIXED_INTS_64); values = new long[numDocs]; for (int i = 0; i < values.length; i++) { values[i] = input.readLong(); @@ -213,23 +213,23 @@ abstract class IndexDocValuesArray extends Source { } @Override - public IndexDocValuesArray newFromInput(IndexInput input, int numDocs) + public DocValuesArray newFromInput(IndexInput input, int numDocs) throws IOException { return new LongValues(input, numDocs); } }; - final static class FloatValues extends IndexDocValuesArray { + final static class FloatValues extends DocValuesArray { private final float[] values; FloatValues() { - super(RamUsageEstimator.NUM_BYTES_FLOAT, ValueType.FLOAT_32); + super(RamUsageEstimator.NUM_BYTES_FLOAT, Type.FLOAT_32); values = new float[0]; } private FloatValues(IndexInput input, int numDocs) throws IOException { - super(RamUsageEstimator.NUM_BYTES_FLOAT, ValueType.FLOAT_32); + super(RamUsageEstimator.NUM_BYTES_FLOAT, Type.FLOAT_32); values = new float[numDocs]; /* * we always read BIG_ENDIAN here since the writer serialized plain bytes @@ -258,22 +258,22 @@ abstract class IndexDocValuesArray extends Source { } @Override - public IndexDocValuesArray newFromInput(IndexInput input, int numDocs) + public DocValuesArray newFromInput(IndexInput input, int numDocs) throws IOException { return new FloatValues(input, numDocs); } }; - final static class DoubleValues extends IndexDocValuesArray { + final static class DoubleValues extends DocValuesArray { private final double[] values; DoubleValues() { - super(RamUsageEstimator.NUM_BYTES_DOUBLE, ValueType.FLOAT_64); + super(RamUsageEstimator.NUM_BYTES_DOUBLE, Type.FLOAT_64); values = new double[0]; } private DoubleValues(IndexInput input, int numDocs) throws IOException { - super(RamUsageEstimator.NUM_BYTES_DOUBLE, ValueType.FLOAT_64); + super(RamUsageEstimator.NUM_BYTES_DOUBLE, Type.FLOAT_64); values = new double[numDocs]; /* * we always read BIG_ENDIAN here since the writer serialized plain bytes @@ -296,7 +296,7 @@ abstract class IndexDocValuesArray extends Source { } @Override - public IndexDocValuesArray newFromInput(IndexInput input, int numDocs) + public DocValuesArray newFromInput(IndexInput input, int numDocs) throws IOException { return new DoubleValues(input, numDocs); } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedDerefBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedDerefBytesImpl.java index ec807050f12..6052ddd5376 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedDerefBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedDerefBytesImpl.java @@ -22,7 +22,7 @@ import java.io.IOException; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -71,7 +71,7 @@ class FixedDerefBytesImpl { private final int size; private final int numValuesStored; FixedDerefReader(Directory dir, String id, int maxDoc, IOContext context) throws IOException { - super(dir, id, CODEC_NAME, VERSION_START, true, context, ValueType.BYTES_FIXED_DEREF); + super(dir, id, CODEC_NAME, VERSION_START, true, context, Type.BYTES_FIXED_DEREF); size = datIn.readInt(); numValuesStored = idxIn.readInt(); } @@ -100,7 +100,7 @@ class FixedDerefBytesImpl { protected FixedDerefSource(IndexInput datIn, IndexInput idxIn, int size, long numValues) throws IOException { super(datIn, idxIn, new PagedBytes(PAGED_BYTES_BITS), size * numValues, - ValueType.BYTES_FIXED_DEREF); + Type.BYTES_FIXED_DEREF); this.size = size; addresses = PackedInts.getReader(idxIn); } @@ -117,7 +117,7 @@ class FixedDerefBytesImpl { private final PackedInts.Reader index; private final int size; - DirectFixedDerefSource(IndexInput data, IndexInput index, int size, ValueType type) + DirectFixedDerefSource(IndexInput data, IndexInput index, int size, Type type) throws IOException { super(data, type); this.size = size; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java index 9ca4cb6ea58..617fb64b8f9 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java @@ -21,15 +21,15 @@ import java.io.IOException; import java.util.Comparator; import java.util.List; +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.DocValues.SortedSource; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.MergeState; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSortedSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.MergeContext; import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.SortedSourceSlice; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.ValueType; -import org.apache.lucene.index.values.IndexDocValues.SortedSource; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -61,11 +61,11 @@ class FixedSortedBytesImpl { } @Override - public void merge(MergeState mergeState, IndexDocValues[] docValues) + public void merge(MergeState mergeState, DocValues[] docValues) throws IOException { boolean success = false; try { - final MergeContext ctx = SortedBytesMergeUtils.init(ValueType.BYTES_FIXED_SORTED, docValues, comp, mergeState); + final MergeContext ctx = SortedBytesMergeUtils.init(Type.BYTES_FIXED_SORTED, docValues, comp, mergeState); List slices = SortedBytesMergeUtils.buildSlices(mergeState, docValues, ctx); final IndexOutput datOut = getOrCreateDataOut(); datOut.writeInt(ctx.sizePerValues); @@ -124,7 +124,7 @@ class FixedSortedBytesImpl { private final Comparator comparator; public Reader(Directory dir, String id, int maxDoc, IOContext context, - ValueType type, Comparator comparator) throws IOException { + Type type, Comparator comparator) throws IOException { super(dir, id, CODEC_NAME, VERSION_START, true, context, type); size = datIn.readInt(); valueCount = idxIn.readInt(); @@ -155,7 +155,7 @@ class FixedSortedBytesImpl { FixedSortedSource(IndexInput datIn, IndexInput idxIn, int size, int numValues, Comparator comp) throws IOException { - super(datIn, idxIn, comp, size * numValues, ValueType.BYTES_FIXED_SORTED, + super(datIn, idxIn, comp, size * numValues, Type.BYTES_FIXED_SORTED, false); this.size = size; this.valueCount = numValues; @@ -181,7 +181,7 @@ class FixedSortedBytesImpl { private final int valueCount; DirectFixedSortedSource(IndexInput datIn, IndexInput idxIn, int size, - int valueCount, Comparator comp, ValueType type) + int valueCount, Comparator comp, Type type) throws IOException { super(type, comp); docToOrdIndex = PackedInts.getDirectReader(idxIn); diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedStraightBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedStraightBytesImpl.java index 52622d05d79..2af949394e3 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedStraightBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedStraightBytesImpl.java @@ -21,12 +21,12 @@ import static org.apache.lucene.util.ByteBlockPool.BYTE_BLOCK_SIZE; import java.io.IOException; +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.DocValues.Source; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesWriterBase; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.ValueType; -import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -180,7 +180,7 @@ class FixedStraightBytesImpl { } } - protected boolean tryBulkMerge(IndexDocValues docValues) { + protected boolean tryBulkMerge(DocValues docValues) { return docValues instanceof FixedStraightReader; } @@ -256,10 +256,10 @@ class FixedStraightBytesImpl { protected final int maxDoc; FixedStraightReader(Directory dir, String id, int maxDoc, IOContext context) throws IOException { - this(dir, id, CODEC_NAME, VERSION_CURRENT, maxDoc, context, ValueType.BYTES_FIXED_STRAIGHT); + this(dir, id, CODEC_NAME, VERSION_CURRENT, maxDoc, context, Type.BYTES_FIXED_STRAIGHT); } - protected FixedStraightReader(Directory dir, String id, String codec, int version, int maxDoc, IOContext context, ValueType type) throws IOException { + protected FixedStraightReader(Directory dir, String id, String codec, int version, int maxDoc, IOContext context, Type type) throws IOException { super(dir, id, codec, version, false, context, type); size = datIn.readInt(); this.maxDoc = maxDoc; @@ -292,7 +292,7 @@ class FixedStraightBytesImpl { private final byte[] data; public SingleByteSource(IndexInput datIn, int maxDoc) throws IOException { - super(ValueType.BYTES_FIXED_STRAIGHT); + super(Type.BYTES_FIXED_STRAIGHT); try { data = new byte[maxDoc]; datIn.readBytes(data, 0, data.length, false); @@ -324,7 +324,7 @@ class FixedStraightBytesImpl { private final static class FixedStraightSource extends BytesSourceBase { private final int size; - public FixedStraightSource(IndexInput datIn, int size, int maxDoc, ValueType type) + public FixedStraightSource(IndexInput datIn, int size, int maxDoc, Type type) throws IOException { super(datIn, null, new PagedBytes(PAGED_BYTES_BITS), size * maxDoc, type); @@ -340,7 +340,7 @@ class FixedStraightBytesImpl { public final static class DirectFixedStraightSource extends DirectSource { private final int size; - DirectFixedStraightSource(IndexInput input, int size, ValueType type) { + DirectFixedStraightSource(IndexInput input, int size, Type type) { super(input, type); this.size = size; } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Floats.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Floats.java index 4f9e1c45aad..b2ed4ea0abb 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Floats.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Floats.java @@ -18,10 +18,10 @@ package org.apache.lucene.index.codecs.lucene40.values; */ import java.io.IOException; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.PerDocFieldValues; -import org.apache.lucene.index.values.ValueType; -import org.apache.lucene.index.values.IndexDocValues.Source; +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.PerDocFieldValues; +import org.apache.lucene.index.DocValues.Source; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -45,16 +45,16 @@ public class Floats { protected static final int VERSION_CURRENT = VERSION_START; public static Writer getWriter(Directory dir, String id, Counter bytesUsed, - IOContext context, ValueType type) throws IOException { + IOContext context, Type type) throws IOException { return new FloatsWriter(dir, id, bytesUsed, context, type); } - public static IndexDocValues getValues(Directory dir, String id, int maxDoc, IOContext context, ValueType type) + public static DocValues getValues(Directory dir, String id, int maxDoc, IOContext context, Type type) throws IOException { return new FloatsReader(dir, id, maxDoc, context, type); } - private static int typeToSize(ValueType type) { + private static int typeToSize(Type type) { switch (type) { case FLOAT_32: return 4; @@ -68,14 +68,14 @@ public class Floats { final static class FloatsWriter extends FixedStraightBytesImpl.Writer { private final int size; - private final IndexDocValuesArray template; + private final DocValuesArray template; public FloatsWriter(Directory dir, String id, Counter bytesUsed, - IOContext context, ValueType type) throws IOException { + IOContext context, Type type) throws IOException { super(dir, id, CODEC_NAME, VERSION_CURRENT, bytesUsed, context); size = typeToSize(type); this.bytesRef = new BytesRef(size); bytesRef.length = size; - template = IndexDocValuesArray.TEMPLATES.get(type); + template = DocValuesArray.TEMPLATES.get(type); assert template != null; } @@ -90,7 +90,7 @@ public class Floats { } @Override - protected boolean tryBulkMerge(IndexDocValues docValues) { + protected boolean tryBulkMerge(DocValues docValues) { // only bulk merge if value type is the same otherwise size differs return super.tryBulkMerge(docValues) && docValues.type() == template.type(); } @@ -103,11 +103,11 @@ public class Floats { } final static class FloatsReader extends FixedStraightBytesImpl.FixedStraightReader { - final IndexDocValuesArray arrayTemplate; - FloatsReader(Directory dir, String id, int maxDoc, IOContext context, ValueType type) + final DocValuesArray arrayTemplate; + FloatsReader(Directory dir, String id, int maxDoc, IOContext context, Type type) throws IOException { super(dir, id, CODEC_NAME, VERSION_CURRENT, maxDoc, context, type); - arrayTemplate = IndexDocValuesArray.TEMPLATES.get(type); + arrayTemplate = DocValuesArray.TEMPLATES.get(type); assert size == 4 || size == 8; } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Ints.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Ints.java index b4d7deb3913..5da35ab299d 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Ints.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Ints.java @@ -19,9 +19,9 @@ package org.apache.lucene.index.codecs.lucene40.values; import java.io.IOException; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.PerDocFieldValues; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.DocValues.Type; +import org.apache.lucene.index.PerDocFieldValues; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -43,33 +43,33 @@ public final class Ints { } public static Writer getWriter(Directory dir, String id, Counter bytesUsed, - ValueType type, IOContext context) throws IOException { - return type == ValueType.VAR_INTS ? new PackedIntValues.PackedIntsWriter(dir, id, + Type type, IOContext context) throws IOException { + return type == Type.VAR_INTS ? new PackedIntValues.PackedIntsWriter(dir, id, bytesUsed, context) : new IntsWriter(dir, id, bytesUsed, context, type); } - public static IndexDocValues getValues(Directory dir, String id, int numDocs, - ValueType type, IOContext context) throws IOException { - return type == ValueType.VAR_INTS ? new PackedIntValues.PackedIntsReader(dir, id, + public static DocValues getValues(Directory dir, String id, int numDocs, + Type type, IOContext context) throws IOException { + return type == Type.VAR_INTS ? new PackedIntValues.PackedIntsReader(dir, id, numDocs, context) : new IntsReader(dir, id, numDocs, context, type); } - private static ValueType sizeToType(int size) { + private static Type sizeToType(int size) { switch (size) { case 1: - return ValueType.FIXED_INTS_8; + return Type.FIXED_INTS_8; case 2: - return ValueType.FIXED_INTS_16; + return Type.FIXED_INTS_16; case 4: - return ValueType.FIXED_INTS_32; + return Type.FIXED_INTS_32; case 8: - return ValueType.FIXED_INTS_64; + return Type.FIXED_INTS_64; default: throw new IllegalStateException("illegal size " + size); } } - private static int typeToSize(ValueType type) { + private static int typeToSize(Type type) { switch (type) { case FIXED_INTS_16: return 2; @@ -86,20 +86,20 @@ public final class Ints { static class IntsWriter extends FixedStraightBytesImpl.Writer { - private final IndexDocValuesArray template; + private final DocValuesArray template; public IntsWriter(Directory dir, String id, Counter bytesUsed, - IOContext context, ValueType valueType) throws IOException { + IOContext context, Type valueType) throws IOException { this(dir, id, CODEC_NAME, VERSION_CURRENT, bytesUsed, context, valueType); } protected IntsWriter(Directory dir, String id, String codecName, - int version, Counter bytesUsed, IOContext context, ValueType valueType) throws IOException { + int version, Counter bytesUsed, IOContext context, Type valueType) throws IOException { super(dir, id, codecName, version, bytesUsed, context); size = typeToSize(valueType); this.bytesRef = new BytesRef(size); bytesRef.length = size; - template = IndexDocValuesArray.TEMPLATES.get(valueType); + template = DocValuesArray.TEMPLATES.get(valueType); } @Override @@ -120,20 +120,20 @@ public final class Ints { } @Override - protected boolean tryBulkMerge(IndexDocValues docValues) { + protected boolean tryBulkMerge(DocValues docValues) { // only bulk merge if value type is the same otherwise size differs return super.tryBulkMerge(docValues) && docValues.type() == template.type(); } } final static class IntsReader extends FixedStraightBytesImpl.FixedStraightReader { - private final IndexDocValuesArray arrayTemplate; + private final DocValuesArray arrayTemplate; - IntsReader(Directory dir, String id, int maxDoc, IOContext context, ValueType type) + IntsReader(Directory dir, String id, int maxDoc, IOContext context, Type type) throws IOException { super(dir, id, CODEC_NAME, VERSION_CURRENT, maxDoc, context, type); - arrayTemplate = IndexDocValuesArray.TEMPLATES.get(type); + arrayTemplate = DocValuesArray.TEMPLATES.get(type); assert arrayTemplate != null; assert type == sizeToType(size); } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/PackedIntValues.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/PackedIntValues.java index 54f3f6ce2c3..10983e4bf37 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/PackedIntValues.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/PackedIntValues.java @@ -18,13 +18,13 @@ package org.apache.lucene.index.codecs.lucene40.values; */ import java.io.IOException; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexFileNames; +import org.apache.lucene.index.PerDocFieldValues; +import org.apache.lucene.index.DocValues.Source; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.codecs.lucene40.values.FixedStraightBytesImpl.FixedBytesWriterBase; -import org.apache.lucene.index.codecs.lucene40.values.IndexDocValuesArray.LongValues; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.PerDocFieldValues; -import org.apache.lucene.index.values.ValueType; -import org.apache.lucene.index.values.IndexDocValues.Source; +import org.apache.lucene.index.codecs.lucene40.values.DocValuesArray.LongValues; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -160,7 +160,7 @@ class PackedIntValues { * Opens all necessary files, but does not read any data in until you call * {@link #load}. */ - static class PackedIntsReader extends IndexDocValues { + static class PackedIntsReader extends DocValues { private final IndexInput datIn; private final byte type; private final int numDocs; @@ -220,14 +220,14 @@ class PackedIntValues { @Override - public ValueType type() { - return ValueType.VAR_INTS; + public Type type() { + return Type.VAR_INTS; } @Override public Source getDirectSource() throws IOException { - return values != null ? new FixedStraightBytesImpl.DirectFixedStraightSource((IndexInput) datIn.clone(), 8, ValueType.FIXED_INTS_64) : new PackedIntsSource((IndexInput) datIn.clone(), true); + return values != null ? new FixedStraightBytesImpl.DirectFixedStraightSource((IndexInput) datIn.clone(), 8, Type.FIXED_INTS_64) : new PackedIntsSource((IndexInput) datIn.clone(), true); } } @@ -238,7 +238,7 @@ class PackedIntValues { private final PackedInts.Reader values; public PackedIntsSource(IndexInput dataIn, boolean direct) throws IOException { - super(ValueType.VAR_INTS); + super(Type.VAR_INTS); minValue = dataIn.readLong(); defaultValue = dataIn.readLong(); values = direct ? PackedInts.getDirectReader(dataIn) : PackedInts.getReader(dataIn); diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/SortedBytesMergeUtils.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/SortedBytesMergeUtils.java index 8a32e6aee64..3b09a91ecee 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/SortedBytesMergeUtils.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/SortedBytesMergeUtils.java @@ -22,12 +22,12 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.MergeState; +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.MergeState.IndexReaderAndLiveDocs; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.ValueType; -import org.apache.lucene.index.values.IndexDocValues.SortedSource; -import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.BytesRef; @@ -43,11 +43,11 @@ final class SortedBytesMergeUtils { // no instance } - static MergeContext init(ValueType type, IndexDocValues[] docValues, + static MergeContext init(Type type, DocValues[] docValues, Comparator comp, MergeState mergeState) { int size = -1; - if (type == ValueType.BYTES_FIXED_SORTED) { - for (IndexDocValues indexDocValues : docValues) { + if (type == Type.BYTES_FIXED_SORTED) { + for (DocValues indexDocValues : docValues) { if (indexDocValues != null) { size = indexDocValues.getValueSize(); break; @@ -62,13 +62,13 @@ final class SortedBytesMergeUtils { private final Comparator comp; private final BytesRef missingValue = new BytesRef(); final int sizePerValues; // -1 if var length - final ValueType type; + final Type type; final int[] docToEntry; long[] offsets; // if non-null #mergeRecords collects byte offsets here public MergeContext(Comparator comp, MergeState mergeState, - int size, ValueType type) { - assert type == ValueType.BYTES_FIXED_SORTED || type == ValueType.BYTES_VAR_SORTED; + int size, Type type) { + assert type == Type.BYTES_FIXED_SORTED || type == Type.BYTES_VAR_SORTED; this.comp = comp; this.sizePerValues = size; this.type = type; @@ -81,7 +81,7 @@ final class SortedBytesMergeUtils { } static List buildSlices(MergeState mergeState, - IndexDocValues[] docValues, MergeContext ctx) throws IOException { + DocValues[] docValues, MergeContext ctx) throws IOException { final List slices = new ArrayList(); for (int i = 0; i < docValues.length; i++) { final SortedSourceSlice nextSlice; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarDerefBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarDerefBytesImpl.java index 2f035de1271..31db5fcf364 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarDerefBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarDerefBytesImpl.java @@ -22,7 +22,7 @@ import java.io.IOException; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -93,7 +93,7 @@ class VarDerefBytesImpl { public static class VarDerefReader extends BytesReaderBase { private final long totalBytes; VarDerefReader(Directory dir, String id, int maxDoc, IOContext context) throws IOException { - super(dir, id, CODEC_NAME, VERSION_START, true, context, ValueType.BYTES_VAR_DEREF); + super(dir, id, CODEC_NAME, VERSION_START, true, context, Type.BYTES_VAR_DEREF); totalBytes = idxIn.readLong(); } @@ -115,7 +115,7 @@ class VarDerefBytesImpl { public VarDerefSource(IndexInput datIn, IndexInput idxIn, long totalBytes) throws IOException { super(datIn, idxIn, new PagedBytes(PAGED_BYTES_BITS), totalBytes, - ValueType.BYTES_VAR_DEREF); + Type.BYTES_VAR_DEREF); addresses = PackedInts.getReader(idxIn); } @@ -130,7 +130,7 @@ class VarDerefBytesImpl { final static class DirectVarDerefSource extends DirectSource { private final PackedInts.Reader index; - DirectVarDerefSource(IndexInput data, IndexInput index, ValueType type) + DirectVarDerefSource(IndexInput data, IndexInput index, Type type) throws IOException { super(data, type); this.index = PackedInts.getDirectReader(index); diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java index 7a92a8c26b4..20de637f62e 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java @@ -21,15 +21,15 @@ import java.io.IOException; import java.util.Comparator; import java.util.List; +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.DocValues.SortedSource; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.MergeState; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSortedSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.MergeContext; import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.SortedSourceSlice; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.ValueType; -import org.apache.lucene.index.values.IndexDocValues.SortedSource; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -62,11 +62,11 @@ final class VarSortedBytesImpl { size = 0; } @Override - public void merge(MergeState mergeState, IndexDocValues[] docValues) + public void merge(MergeState mergeState, DocValues[] docValues) throws IOException { boolean success = false; try { - MergeContext ctx = SortedBytesMergeUtils.init(ValueType.BYTES_VAR_SORTED, docValues, comp, mergeState); + MergeContext ctx = SortedBytesMergeUtils.init(Type.BYTES_VAR_SORTED, docValues, comp, mergeState); final List slices = SortedBytesMergeUtils.buildSlices(mergeState, docValues, ctx); IndexOutput datOut = getOrCreateDataOut(); @@ -149,14 +149,14 @@ final class VarSortedBytesImpl { private final Comparator comparator; Reader(Directory dir, String id, int maxDoc, - IOContext context, ValueType type, Comparator comparator) + IOContext context, Type type, Comparator comparator) throws IOException { super(dir, id, CODEC_NAME, VERSION_START, true, context, type); this.comparator = comparator; } @Override - public org.apache.lucene.index.values.IndexDocValues.Source load() + public org.apache.lucene.index.DocValues.Source load() throws IOException { return new VarSortedSource(cloneData(), cloneIndex(), comparator); } @@ -172,7 +172,7 @@ final class VarSortedBytesImpl { VarSortedSource(IndexInput datIn, IndexInput idxIn, Comparator comp) throws IOException { - super(datIn, idxIn, comp, idxIn.readLong(), ValueType.BYTES_VAR_SORTED, true); + super(datIn, idxIn, comp, idxIn.readLong(), Type.BYTES_VAR_SORTED, true); valueCount = ordToOffsetIndex.size()-1; // the last value here is just a dummy value to get the length of the last value closeIndexInput(); } @@ -199,7 +199,7 @@ final class VarSortedBytesImpl { private final int valueCount; DirectSortedSource(IndexInput datIn, IndexInput idxIn, - Comparator comparator, ValueType type) throws IOException { + Comparator comparator, Type type) throws IOException { super(type, comparator); idxIn.readLong(); ordToOffsetIndex = PackedInts.getDirectReader(idxIn); diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarStraightBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarStraightBytesImpl.java index 0e7ff31bc30..e50fba6c758 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarStraightBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarStraightBytesImpl.java @@ -22,7 +22,7 @@ import java.io.IOException; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesWriterBase; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -229,7 +229,7 @@ class VarStraightBytesImpl { private final int maxDoc; VarStraightReader(Directory dir, String id, int maxDoc, IOContext context) throws IOException { - super(dir, id, CODEC_NAME, VERSION_START, true, context, ValueType.BYTES_VAR_STRAIGHT); + super(dir, id, CODEC_NAME, VERSION_START, true, context, Type.BYTES_VAR_STRAIGHT); this.maxDoc = maxDoc; } @@ -250,7 +250,7 @@ class VarStraightBytesImpl { public VarStraightSource(IndexInput datIn, IndexInput idxIn) throws IOException { super(datIn, idxIn, new PagedBytes(PAGED_BYTES_BITS), idxIn.readVLong(), - ValueType.BYTES_VAR_STRAIGHT); + Type.BYTES_VAR_STRAIGHT); addresses = PackedInts.getReader(idxIn); } @@ -266,7 +266,7 @@ class VarStraightBytesImpl { private final PackedInts.Reader index; - DirectVarStraightSource(IndexInput data, IndexInput index, ValueType type) + DirectVarStraightSource(IndexInput data, IndexInput index, Type type) throws IOException { super(data, type); index.readVLong(); diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Writer.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Writer.java index 7aae0f0f6fc..330b744c89b 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Writer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Writer.java @@ -19,9 +19,9 @@ package org.apache.lucene.index.codecs.lucene40.values; import java.io.IOException; import java.util.Comparator; +import org.apache.lucene.index.DocValues.Source; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.codecs.DocValuesConsumer; -import org.apache.lucene.index.values.ValueType; -import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.util.Bits; @@ -165,20 +165,20 @@ public abstract class Writer extends DocValuesConsumer { /** * Factory method to create a {@link Writer} instance for a given type. This * method returns default implementations for each of the different types - * defined in the {@link ValueType} enumeration. + * defined in the {@link Type} enumeration. * * @param type - * the {@link ValueType} to create the {@link Writer} for + * the {@link Type} to create the {@link Writer} for * @param id * the file name id used to create files within the writer. * @param directory * the {@link Directory} to create the files from. * @param bytesUsed * a byte-usage tracking reference - * @return a new {@link Writer} instance for the given {@link ValueType} + * @return a new {@link Writer} instance for the given {@link Type} * @throws IOException */ - public static Writer create(ValueType type, String id, Directory directory, + public static Writer create(Type type, String id, Directory directory, Comparator comp, Counter bytesUsed, IOContext context) throws IOException { if (comp == null) { comp = BytesRef.getUTF8SortedAsUnicodeComparator(); diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesProducer.java b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesProducer.java index 88d9f1f260d..82daa2ee41e 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesProducer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesProducer.java @@ -22,9 +22,9 @@ import java.util.Collection; import java.util.Map; import java.util.TreeMap; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.index.codecs.DocValuesReaderBase; -import org.apache.lucene.index.values.IndexDocValues; import org.apache.lucene.util.IOUtils; /** @@ -32,18 +32,18 @@ import org.apache.lucene.util.IOUtils; * @lucene.experimental */ public class SepDocValuesProducer extends DocValuesReaderBase { - private final TreeMap docValues; + private final TreeMap docValues; /** * Creates a new {@link SepDocValuesProducer} instance and loads all - * {@link IndexDocValues} instances for this segment and codec. + * {@link DocValues} instances for this segment and codec. */ public SepDocValuesProducer(SegmentReadState state) throws IOException { docValues = load(state.fieldInfos, state.segmentInfo.name, state.segmentInfo.docCount, state.dir, state.context); } @Override - protected Map docValues() { + protected Map docValues() { return docValues; } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldInfosReader.java b/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldInfosReader.java index d3525736ab1..6f97f0c4765 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldInfosReader.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldInfosReader.java @@ -26,8 +26,8 @@ import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.FieldInfo.IndexOptions; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.codecs.FieldInfosReader; -import org.apache.lucene.index.values.ValueType; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -98,12 +98,12 @@ public class SimpleTextFieldInfosReader extends FieldInfosReader { SimpleTextUtil.readLine(input, scratch); assert StringHelper.startsWith(scratch, DOCVALUES); String dvType = readString(DOCVALUES.length, scratch); - final ValueType docValuesType; + final DocValues.Type docValuesType; if ("false".equals(dvType)) { docValuesType = null; } else { - docValuesType = ValueType.valueOf(dvType); + docValuesType = DocValues.Type.valueOf(dvType); } SimpleTextUtil.readLine(input, scratch); diff --git a/lucene/src/java/org/apache/lucene/index/values/IndexDocValues.java b/lucene/src/java/org/apache/lucene/index/values/IndexDocValues.java deleted file mode 100644 index 5bd1d0f3da9..00000000000 --- a/lucene/src/java/org/apache/lucene/index/values/IndexDocValues.java +++ /dev/null @@ -1,425 +0,0 @@ -package org.apache.lucene.index.values; - -/** - * 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. - */ -import java.io.Closeable; -import java.io.IOException; -import java.util.Comparator; - -import org.apache.lucene.document.IndexDocValuesField; -import org.apache.lucene.index.Fields; -import org.apache.lucene.index.FieldsEnum; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.codecs.DocValuesFormat; -import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.packed.PackedInts; - -/** - * {@link IndexDocValues} provides a dense per-document typed storage for fast - * value access based on the lucene internal document id. {@link IndexDocValues} - * exposes two distinct APIs: - *

    - *
  • via {@link #getSource()} providing RAM resident random access
  • - *
  • via {@link #getDirectSource()} providing on disk random access
  • - *
{@link IndexDocValues} are exposed via - * {@link IndexReader#perDocValues()} on a per-segment basis. For best - * performance {@link IndexDocValues} should be consumed per-segment just like - * IndexReader. - *

- * {@link IndexDocValues} are fully integrated into the {@link DocValuesFormat} API. - * - * @see ValueType for limitations and default implementation documentation - * @see IndexDocValuesField for adding values to the index - * @see DocValuesFormat#docsConsumer(org.apache.lucene.index.PerDocWriteState) for - * customization - * @lucene.experimental - */ -public abstract class IndexDocValues implements Closeable { - - public static final IndexDocValues[] EMPTY_ARRAY = new IndexDocValues[0]; - - private volatile SourceCache cache = new SourceCache.DirectSourceCache(); - private final Object cacheLock = new Object(); - - /** - * Loads a new {@link Source} instance for this {@link IndexDocValues} field - * instance. Source instances returned from this method are not cached. It is - * the callers responsibility to maintain the instance and release its - * resources once the source is not needed anymore. - *

- * For managed {@link Source} instances see {@link #getSource()}. - * - * @see #getSource() - * @see #setCache(SourceCache) - */ - public abstract Source load() throws IOException; - - /** - * Returns a {@link Source} instance through the current {@link SourceCache}. - * Iff no {@link Source} has been loaded into the cache so far the source will - * be loaded through {@link #load()} and passed to the {@link SourceCache}. - * The caller of this method should not close the obtained {@link Source} - * instance unless it is not needed for the rest of its life time. - *

- * {@link Source} instances obtained from this method are closed / released - * from the cache once this {@link IndexDocValues} instance is closed by the - * {@link IndexReader}, {@link Fields} or {@link FieldsEnum} the - * {@link IndexDocValues} was created from. - */ - public Source getSource() throws IOException { - return cache.load(this); - } - - /** - * Returns a disk resident {@link Source} instance. Direct Sources are not - * cached in the {@link SourceCache} and should not be shared between threads. - */ - public abstract Source getDirectSource() throws IOException; - - /** - * Returns the {@link ValueType} of this {@link IndexDocValues} instance - */ - public abstract ValueType type(); - - /** - * Closes this {@link IndexDocValues} instance. This method should only be called - * by the creator of this {@link IndexDocValues} instance. API users should not - * close {@link IndexDocValues} instances. - */ - public void close() throws IOException { - cache.close(this); - } - - /** - * Returns the size per value in bytes or -1 iff size per value - * is variable. - * - * @return the size per value in bytes or -1 iff size per value - * is variable. - */ - public int getValueSize() { - return -1; - } - - /** - * Sets the {@link SourceCache} used by this {@link IndexDocValues} instance. This - * method should be called before {@link #load()} is called. All {@link Source} instances in the currently used cache will be closed - * before the new cache is installed. - *

- * Note: All instances previously obtained from {@link #load()} will be lost. - * - * @throws IllegalArgumentException - * if the given cache is null - * - */ - public void setCache(SourceCache cache) { - if (cache == null) - throw new IllegalArgumentException("cache must not be null"); - synchronized (cacheLock) { - SourceCache toClose = this.cache; - this.cache = cache; - toClose.close(this); - } - } - - /** - * Source of per document values like long, double or {@link BytesRef} - * depending on the {@link IndexDocValues} fields {@link ValueType}. Source - * implementations provide random access semantics similar to array lookups - *

- * @see IndexDocValues#getSource() - * @see IndexDocValues#getDirectSource() - */ - public static abstract class Source { - - protected final ValueType type; - - protected Source(ValueType type) { - this.type = type; - } - /** - * Returns a long for the given document id or throws an - * {@link UnsupportedOperationException} if this source doesn't support - * long values. - * - * @throws UnsupportedOperationException - * if this source doesn't support long values. - */ - public long getInt(int docID) { - throw new UnsupportedOperationException("ints are not supported"); - } - - /** - * Returns a double for the given document id or throws an - * {@link UnsupportedOperationException} if this source doesn't support - * double values. - * - * @throws UnsupportedOperationException - * if this source doesn't support double values. - */ - public double getFloat(int docID) { - throw new UnsupportedOperationException("floats are not supported"); - } - - /** - * Returns a {@link BytesRef} for the given document id or throws an - * {@link UnsupportedOperationException} if this source doesn't support - * byte[] values. - * @throws IOException - * - * @throws UnsupportedOperationException - * if this source doesn't support byte[] values. - */ - public BytesRef getBytes(int docID, BytesRef ref) { - throw new UnsupportedOperationException("bytes are not supported"); - } - - /** - * Returns the {@link ValueType} of this source. - * - * @return the {@link ValueType} of this source. - */ - public ValueType type() { - return type; - } - - /** - * Returns true iff this {@link Source} exposes an array via - * {@link #getArray()} otherwise false. - * - * @return true iff this {@link Source} exposes an array via - * {@link #getArray()} otherwise false. - */ - public boolean hasArray() { - return false; - } - - /** - * Returns the internal array representation iff this {@link Source} uses an - * array as its inner representation, otherwise UOE. - */ - public Object getArray() { - throw new UnsupportedOperationException("getArray is not supported"); - } - - /** - * If this {@link Source} is sorted this method will return an instance of - * {@link SortedSource} otherwise UOE - */ - public SortedSource asSortedSource() { - throw new UnsupportedOperationException("asSortedSource is not supported"); - } - } - - /** - * A sorted variant of {@link Source} for byte[] values per document. - *

- */ - public static abstract class SortedSource extends Source { - - private final Comparator comparator; - - protected SortedSource(ValueType type, Comparator comparator) { - super(type); - this.comparator = comparator; - } - - @Override - public BytesRef getBytes(int docID, BytesRef bytesRef) { - final int ord = ord(docID); - if (ord < 0) { - bytesRef.length = 0; - } else { - getByOrd(ord , bytesRef); - } - return bytesRef; - } - - /** - * Returns ord for specified docID. Ord is dense, ie, starts at 0, then increments by 1 - * for the next (as defined by {@link Comparator} value. - */ - public abstract int ord(int docID); - - /** Returns value for specified ord. */ - public abstract BytesRef getByOrd(int ord, BytesRef bytesRef); - - /** Return true if it's safe to call {@link - * #getDocToOrd}. */ - public boolean hasPackedDocToOrd() { - return false; - } - - /** - * Returns the PackedInts.Reader impl that maps document to ord. - */ - public abstract PackedInts.Reader getDocToOrd(); - - /** - * Returns the comparator used to order the BytesRefs. - */ - public Comparator getComparator() { - return comparator; - } - - /** - * Performs a lookup by value. - * - * @param value - * the value to look up - * @param spare - * a spare {@link BytesRef} instance used to compare internal - * values to the given value. Must not be null - * @return the given values ordinal if found or otherwise - * (-(ord)-1), defined as the ordinal of the first - * element that is greater than the given value. This guarantees - * that the return value will always be >= 0 if the given value - * is found. - */ - public int getByValue(BytesRef value, BytesRef spare) { - return binarySearch(value, spare, 0, getValueCount() - 1); - } - - private int binarySearch(BytesRef b, BytesRef bytesRef, int low, - int high) { - int mid = 0; - while (low <= high) { - mid = (low + high) >>> 1; - getByOrd(mid, bytesRef); - final int cmp = comparator.compare(bytesRef, b); - if (cmp < 0) { - low = mid + 1; - } else if (cmp > 0) { - high = mid - 1; - } else { - return mid; - } - } - assert comparator.compare(bytesRef, b) != 0; - return -(low + 1); - } - - @Override - public SortedSource asSortedSource() { - return this; - } - - /** - * Returns the number of unique values in this sorted source - */ - public abstract int getValueCount(); - } - - /** Returns a Source that always returns default (missing) - * values for all documents. */ - public static Source getDefaultSource(final ValueType type) { - return new Source(type) { - @Override - public long getInt(int docID) { - return 0; - } - - @Override - public double getFloat(int docID) { - return 0.0; - } - - @Override - public BytesRef getBytes(int docID, BytesRef ref) { - ref.length = 0; - return ref; - } - }; - } - - /** Returns a SortedSource that always returns default (missing) - * values for all documents. */ - public static SortedSource getDefaultSortedSource(final ValueType type, final int size) { - - final PackedInts.Reader docToOrd = new PackedInts.Reader() { - @Override - public long get(int index) { - return 0; - } - - @Override - public int getBitsPerValue() { - return 0; - } - - @Override - public int size() { - return size; - } - - @Override - public boolean hasArray() { - return false; - } - - @Override - public Object getArray() { - return null; - } - }; - - return new SortedSource(type, BytesRef.getUTF8SortedAsUnicodeComparator()) { - - @Override - public BytesRef getBytes(int docID, BytesRef ref) { - ref.length = 0; - return ref; - } - - @Override - public int ord(int docID) { - return 0; - } - - @Override - public BytesRef getByOrd(int ord, BytesRef bytesRef) { - assert ord == 0; - bytesRef.length = 0; - return bytesRef; - } - - @Override - public boolean hasPackedDocToOrd() { - return true; - } - - @Override - public PackedInts.Reader getDocToOrd() { - return docToOrd; - } - - @Override - public int getByValue(BytesRef value, BytesRef spare) { - if (value.length == 0) { - return 0; - } else { - return -1; - } - } - - @Override - public int getValueCount() { - return 1; - } - }; - } -} diff --git a/lucene/src/java/org/apache/lucene/index/values/SourceCache.java b/lucene/src/java/org/apache/lucene/index/values/SourceCache.java deleted file mode 100644 index 13f6dab3123..00000000000 --- a/lucene/src/java/org/apache/lucene/index/values/SourceCache.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.apache.lucene.index.values; - -/** - * 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. - */ - -import java.io.IOException; - -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.values.IndexDocValues.Source; - -/** - * Abstract base class for {@link IndexDocValues} {@link Source} cache. - *

- * {@link Source} instances loaded via {@link IndexDocValues#load()} are entirely memory resident - * and need to be maintained by the caller. Each call to - * {@link IndexDocValues#load()} will cause an entire reload of - * the underlying data. Source instances obtained from - * {@link IndexDocValues#getSource()} and {@link IndexDocValues#getSource()} - * respectively are maintained by a {@link SourceCache} that is closed ( - * {@link #close(IndexDocValues)}) once the {@link IndexReader} that created the - * {@link IndexDocValues} instance is closed. - *

- * Unless {@link Source} instances are managed by another entity it is - * recommended to use the cached variants to obtain a source instance. - *

- * Implementation of this API must be thread-safe. - * - * @see IndexDocValues#setCache(SourceCache) - * @see IndexDocValues#getSource() - * - * @lucene.experimental - */ -public abstract class SourceCache { - - /** - * Atomically loads a {@link Source} into the cache from the given - * {@link IndexDocValues} and returns it iff no other {@link Source} has already - * been cached. Otherwise the cached source is returned. - *

- * This method will not return null - */ - public abstract Source load(IndexDocValues values) throws IOException; - - /** - * Atomically invalidates the cached {@link Source} - * instances if any and empties the cache. - */ - public abstract void invalidate(IndexDocValues values); - - /** - * Atomically closes the cache and frees all resources. - */ - public synchronized void close(IndexDocValues values) { - invalidate(values); - } - - /** - * Simple per {@link IndexDocValues} instance cache implementation that holds a - * {@link Source} a member variable. - *

- * If a {@link DirectSourceCache} instance is closed or invalidated the cached - * reference are simply set to null - */ - public static final class DirectSourceCache extends SourceCache { - private Source ref; - - public synchronized Source load(IndexDocValues values) throws IOException { - if (ref == null) { - ref = values.load(); - } - return ref; - } - - public synchronized void invalidate(IndexDocValues values) { - ref = null; - } - } - -} diff --git a/lucene/src/java/org/apache/lucene/index/values/ValueType.java b/lucene/src/java/org/apache/lucene/index/values/ValueType.java deleted file mode 100644 index 5a267eb9d3e..00000000000 --- a/lucene/src/java/org/apache/lucene/index/values/ValueType.java +++ /dev/null @@ -1,220 +0,0 @@ -package org.apache.lucene.index.values; - -/** - * 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. - */ - -import org.apache.lucene.index.codecs.DocValuesFormat; -import org.apache.lucene.index.values.IndexDocValues.SortedSource; -import org.apache.lucene.index.values.IndexDocValues.Source; -import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.packed.PackedInts; - -/** - * ValueType specifies the {@link IndexDocValues} type for a - * certain field. A ValueType only defines the data type for a field - * while the actual implementation used to encode and decode the values depends - * on the the {@link DocValuesFormat#docsConsumer} and {@link DocValuesFormat#docsProducer} methods. - * - * @lucene.experimental - */ -public enum ValueType { - - /** - * A variable bit signed integer value. By default this type uses - * {@link PackedInts} to compress the values, as an offset - * from the minimum value, as long as the value range - * fits into 263-1. Otherwise, - * the default implementation falls back to fixed size 64bit - * integers ({@link #FIXED_INTS_64}). - *

- * NOTE: this type uses 0 as the default value without any - * distinction between provided 0 values during indexing. All - * documents without an explicit value will use 0 instead. - * Custom default values must be assigned explicitly. - *

- */ - VAR_INTS, - - /** - * A 8 bit signed integer value. {@link Source} instances of - * this type return a byte array from {@link Source#getArray()} - *

- * NOTE: this type uses 0 as the default value without any - * distinction between provided 0 values during indexing. All - * documents without an explicit value will use 0 instead. - * Custom default values must be assigned explicitly. - *

- */ - FIXED_INTS_8, - - /** - * A 16 bit signed integer value. {@link Source} instances of - * this type return a short array from {@link Source#getArray()} - *

- * NOTE: this type uses 0 as the default value without any - * distinction between provided 0 values during indexing. All - * documents without an explicit value will use 0 instead. - * Custom default values must be assigned explicitly. - *

- */ - FIXED_INTS_16, - - /** - * A 32 bit signed integer value. {@link Source} instances of - * this type return a int array from {@link Source#getArray()} - *

- * NOTE: this type uses 0 as the default value without any - * distinction between provided 0 values during indexing. All - * documents without an explicit value will use 0 instead. - * Custom default values must be assigned explicitly. - *

- */ - FIXED_INTS_32, - - /** - * A 64 bit signed integer value. {@link Source} instances of - * this type return a long array from {@link Source#getArray()} - *

- * NOTE: this type uses 0 as the default value without any - * distinction between provided 0 values during indexing. All - * documents without an explicit value will use 0 instead. - * Custom default values must be assigned explicitly. - *

- */ - FIXED_INTS_64, - /** - * A 32 bit floating point value. By default there is no compression - * applied. To fit custom float values into less than 32bit either a custom - * implementation is needed or values must be encoded into a - * {@link #BYTES_FIXED_STRAIGHT} type. {@link Source} instances of - * this type return a float array from {@link Source#getArray()} - *

- * NOTE: this type uses 0.0f as the default value without any - * distinction between provided 0.0f values during indexing. All - * documents without an explicit value will use 0.0f instead. - * Custom default values must be assigned explicitly. - *

- */ - FLOAT_32, - /** - * - * A 64 bit floating point value. By default there is no compression - * applied. To fit custom float values into less than 64bit either a custom - * implementation is needed or values must be encoded into a - * {@link #BYTES_FIXED_STRAIGHT} type. {@link Source} instances of - * this type return a double array from {@link Source#getArray()} - *

- * NOTE: this type uses 0.0d as the default value without any - * distinction between provided 0.0d values during indexing. All - * documents without an explicit value will use 0.0d instead. - * Custom default values must be assigned explicitly. - *

- */ - FLOAT_64, - - // TODO(simonw): -- shouldn't lucene decide/detect straight vs - // deref, as well fixed vs var? - /** - * A fixed length straight byte[]. All values added to - * such a field must be of the same length. All bytes are stored sequentially - * for fast offset access. - *

- * NOTE: this type uses 0 byte filled byte[] based on the length of the first seen - * value as the default value without any distinction between explicitly - * provided values during indexing. All documents without an explicit value - * will use the default instead.Custom default values must be assigned explicitly. - *

- */ - BYTES_FIXED_STRAIGHT, - - /** - * A fixed length dereferenced byte[] variant. Fields with - * this type only store distinct byte values and store an additional offset - * pointer per document to dereference the shared byte[]. - * Use this type if your documents may share the same byte[]. - *

- * NOTE: Fields of this type will not store values for documents without and - * explicitly provided value. If a documents value is accessed while no - * explicit value is stored the returned {@link BytesRef} will be a 0-length - * reference. Custom default values must be assigned explicitly. - *

- */ - BYTES_FIXED_DEREF, - - /** - * Variable length straight stored byte[] variant. All bytes are - * stored sequentially for compactness. Usage of this type via the - * disk-resident API might yield performance degradation since no additional - * index is used to advance by more than one document value at a time. - *

- * NOTE: Fields of this type will not store values for documents without an - * explicitly provided value. If a documents value is accessed while no - * explicit value is stored the returned {@link BytesRef} will be a 0-length - * byte[] reference. Custom default values must be assigned explicitly. - *

- */ - BYTES_VAR_STRAIGHT, - - /** - * A variable length dereferenced byte[]. Just like - * {@link #BYTES_FIXED_DEREF}, but allowing each - * document's value to be a different length. - *

- * NOTE: Fields of this type will not store values for documents without and - * explicitly provided value. If a documents value is accessed while no - * explicit value is stored the returned {@link BytesRef} will be a 0-length - * reference. Custom default values must be assigned explicitly. - *

- */ - BYTES_VAR_DEREF, - - - /** - * A variable length pre-sorted byte[] variant. Just like - * {@link #BYTES_FIXED_SORTED}, but allowing each - * document's value to be a different length. - *

- * NOTE: Fields of this type will not store values for documents without and - * explicitly provided value. If a documents value is accessed while no - * explicit value is stored the returned {@link BytesRef} will be a 0-length - * reference.Custom default values must be assigned explicitly. - *

- * - * @see SortedSource - */ - BYTES_VAR_SORTED, - - /** - * A fixed length pre-sorted byte[] variant. Fields with this type only - * store distinct byte values and store an additional offset pointer per - * document to dereference the shared byte[]. The stored - * byte[] is presorted, by default by unsigned byte order, - * and allows access via document id, ordinal and by-value. - * Use this type if your documents may share the same byte[]. - *

- * NOTE: Fields of this type will not store values for documents without and - * explicitly provided value. If a documents value is accessed while no - * explicit value is stored the returned {@link BytesRef} will be a 0-length - * reference. Custom default values must be assigned - * explicitly. - *

- * - * @see SortedSource - */ - BYTES_FIXED_SORTED - -} diff --git a/lucene/src/java/org/apache/lucene/search/FieldComparator.java b/lucene/src/java/org/apache/lucene/search/FieldComparator.java index bd7a0083939..9359f25affd 100644 --- a/lucene/src/java/org/apache/lucene/search/FieldComparator.java +++ b/lucene/src/java/org/apache/lucene/search/FieldComparator.java @@ -21,11 +21,8 @@ import java.io.IOException; import java.util.Comparator; import org.apache.lucene.index.IndexReader.AtomicReaderContext; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.values.IndexDocValues.SortedSource; -import org.apache.lucene.index.values.IndexDocValues.Source; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.ValueType; import org.apache.lucene.search.FieldCache.ByteParser; import org.apache.lucene.search.FieldCache.DocTerms; import org.apache.lucene.search.FieldCache.DocTermsIndex; @@ -360,7 +357,7 @@ public abstract class FieldComparator { public static final class FloatDocValuesComparator extends FieldComparator { private final double[] values; private final String field; - private Source currentReaderValues; + private DocValues.Source currentReaderValues; private double bottom; FloatDocValuesComparator(int numHits, String field) { @@ -400,11 +397,11 @@ public abstract class FieldComparator { @Override public FieldComparator setNextReader(AtomicReaderContext context) throws IOException { - final IndexDocValues docValues = context.reader.docValues(field); + final DocValues docValues = context.reader.docValues(field); if (docValues != null) { currentReaderValues = docValues.getSource(); } else { - currentReaderValues = IndexDocValues.getDefaultSource(ValueType.FLOAT_64); + currentReaderValues = DocValues.getDefaultSource(DocValues.Type.FLOAT_64); } return this; } @@ -648,7 +645,7 @@ public abstract class FieldComparator { /** Loads int index values and sorts by ascending value. */ public static final class IntDocValuesComparator extends FieldComparator { private final long[] values; - private Source currentReaderValues; + private DocValues.Source currentReaderValues; private final String field; private long bottom; @@ -693,11 +690,11 @@ public abstract class FieldComparator { @Override public FieldComparator setNextReader(AtomicReaderContext context) throws IOException { - IndexDocValues docValues = context.reader.docValues(field); + DocValues docValues = context.reader.docValues(field); if (docValues != null) { currentReaderValues = docValues.getSource(); } else { - currentReaderValues = IndexDocValues.getDefaultSource(ValueType.FIXED_INTS_64); + currentReaderValues = DocValues.getDefaultSource(DocValues.Type.FIXED_INTS_64); } return this; } @@ -1382,7 +1379,7 @@ public abstract class FieldComparator { /* Current reader's doc ord/values. @lucene.internal */ - SortedSource termsIndex; + DocValues.SortedSource termsIndex; /* Comparator for comparing by value. @lucene.internal */ @@ -1490,10 +1487,10 @@ public abstract class FieldComparator { // Used per-segment when bit width of doc->ord is 8: private final class ByteOrdComparator extends PerSegmentComparator { private final byte[] readerOrds; - private final SortedSource termsIndex; + private final DocValues.SortedSource termsIndex; private final int docBase; - public ByteOrdComparator(byte[] readerOrds, SortedSource termsIndex, int docBase) { + public ByteOrdComparator(byte[] readerOrds, DocValues.SortedSource termsIndex, int docBase) { this.readerOrds = readerOrds; this.termsIndex = termsIndex; this.docBase = docBase; @@ -1535,10 +1532,10 @@ public abstract class FieldComparator { // Used per-segment when bit width of doc->ord is 16: private final class ShortOrdComparator extends PerSegmentComparator { private final short[] readerOrds; - private final SortedSource termsIndex; + private final DocValues.SortedSource termsIndex; private final int docBase; - public ShortOrdComparator(short[] readerOrds, SortedSource termsIndex, int docBase) { + public ShortOrdComparator(short[] readerOrds, DocValues.SortedSource termsIndex, int docBase) { this.readerOrds = readerOrds; this.termsIndex = termsIndex; this.docBase = docBase; @@ -1580,10 +1577,10 @@ public abstract class FieldComparator { // Used per-segment when bit width of doc->ord is 32: private final class IntOrdComparator extends PerSegmentComparator { private final int[] readerOrds; - private final SortedSource termsIndex; + private final DocValues.SortedSource termsIndex; private final int docBase; - public IntOrdComparator(int[] readerOrds, SortedSource termsIndex, int docBase) { + public IntOrdComparator(int[] readerOrds, DocValues.SortedSource termsIndex, int docBase) { this.readerOrds = readerOrds; this.termsIndex = termsIndex; this.docBase = docBase; @@ -1709,12 +1706,12 @@ public abstract class FieldComparator { public FieldComparator setNextReader(AtomicReaderContext context) throws IOException { final int docBase = context.docBase; - final IndexDocValues dv = context.reader.docValues(field); + final DocValues dv = context.reader.docValues(field); if (dv == null) { // This may mean entire segment had no docs with // this DV field; use default field value (empty // byte[]) in this case: - termsIndex = IndexDocValues.getDefaultSortedSource(ValueType.BYTES_VAR_SORTED, context.reader.maxDoc()); + termsIndex = DocValues.getDefaultSortedSource(DocValues.Type.BYTES_VAR_SORTED, context.reader.maxDoc()); } else { termsIndex = dv.getSource().asSortedSource(); if (termsIndex == null) { @@ -1892,7 +1889,7 @@ public abstract class FieldComparator { public static final class TermValDocValuesComparator extends FieldComparator { private BytesRef[] values; - private Source docTerms; + private DocValues.Source docTerms; private final String field; private BytesRef bottom; private final BytesRef tempBR = new BytesRef(); @@ -1925,11 +1922,11 @@ public abstract class FieldComparator { @Override public FieldComparator setNextReader(AtomicReaderContext context) throws IOException { - final IndexDocValues dv = context.reader.docValues(field); + final DocValues dv = context.reader.docValues(field); if (dv != null) { docTerms = dv.getSource(); } else { - docTerms = IndexDocValues.getDefaultSource(ValueType.BYTES_VAR_DEREF); + docTerms = DocValues.getDefaultSource(DocValues.Type.BYTES_VAR_DEREF); } return this; } diff --git a/lucene/src/java/org/apache/lucene/search/similarities/Similarity.java b/lucene/src/java/org/apache/lucene/search/similarities/Similarity.java index 48ffa230d0c..c0bae971677 100644 --- a/lucene/src/java/org/apache/lucene/search/similarities/Similarity.java +++ b/lucene/src/java/org/apache/lucene/search/similarities/Similarity.java @@ -20,7 +20,7 @@ package org.apache.lucene.search.similarities; import java.io.IOException; -import org.apache.lucene.document.IndexDocValuesField; // javadoc +import org.apache.lucene.document.DocValuesField; // javadoc import org.apache.lucene.index.FieldInvertState; import org.apache.lucene.index.IndexReader; // javadoc import org.apache.lucene.index.IndexReader.AtomicReaderContext; @@ -71,11 +71,11 @@ import org.apache.lucene.util.TermContext; *

* Because index-time boost is handled entirely at the application level anyway, * an application can alternatively store the index-time boost separately using an - * {@link IndexDocValuesField}, and access this at query-time with + * {@link DocValuesField}, and access this at query-time with * {@link IndexReader#docValues(String)}. *

* Finally, using index-time boosts (either via folding into the normalization byte or - * via IndexDocValues), is an inefficient way to boost the scores of different fields if the + * via DocValues), is an inefficient way to boost the scores of different fields if the * boost will be the same for every document, instead the Similarity can simply take a constant * boost parameter C, and the SimilarityProvider can return different instances with * different boosts depending upon field name. diff --git a/lucene/src/test-framework/java/org/apache/lucene/index/RandomIndexWriter.java b/lucene/src/test-framework/java/org/apache/lucene/index/RandomIndexWriter.java index 58ff0e764f4..ce6a5f1da40 100644 --- a/lucene/src/test-framework/java/org/apache/lucene/index/RandomIndexWriter.java +++ b/lucene/src/test-framework/java/org/apache/lucene/index/RandomIndexWriter.java @@ -24,11 +24,11 @@ import java.util.Random; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; -import org.apache.lucene.document.IndexDocValuesField; +import org.apache.lucene.document.DocValuesField; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexWriter; // javadoc import org.apache.lucene.index.codecs.Codec; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues; import org.apache.lucene.search.Query; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; @@ -167,12 +167,12 @@ public class RandomIndexWriter implements Closeable { private void randomPerDocFieldValues(Random random, Document doc) { - ValueType[] values = ValueType.values(); - ValueType type = values[random.nextInt(values.length)]; + DocValues.Type[] values = DocValues.Type.values(); + DocValues.Type type = values[random.nextInt(values.length)]; String name = "random_" + type.name() + "" + docValuesFieldPrefix; if ("Lucene3x".equals(codec.getName()) || doc.getField(name) != null) return; - IndexDocValuesField docValuesField = new IndexDocValuesField(name); + DocValuesField docValuesField = new DocValuesField(name); switch (type) { case BYTES_FIXED_DEREF: case BYTES_FIXED_STRAIGHT: diff --git a/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mocksep/MockSepDocValuesFormat.java b/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mocksep/MockSepDocValuesFormat.java index 790bca1c96c..698b8bf37ca 100644 --- a/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mocksep/MockSepDocValuesFormat.java +++ b/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mocksep/MockSepDocValuesFormat.java @@ -20,12 +20,12 @@ package org.apache.lucene.index.codecs.mocksep; import java.io.IOException; import java.util.Set; +import org.apache.lucene.index.PerDocValues; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.index.codecs.DocValuesFormat; import org.apache.lucene.index.codecs.PerDocConsumer; -import org.apache.lucene.index.codecs.PerDocValues; import org.apache.lucene.index.codecs.sep.SepDocValuesConsumer; import org.apache.lucene.index.codecs.sep.SepDocValuesProducer; import org.apache.lucene.store.Directory; diff --git a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java index b03bf69fab2..ab0b586a36e 100755 --- a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java +++ b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java @@ -27,7 +27,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.IndexDocValuesField; +import org.apache.lucene.document.DocValuesField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig.OpenMode; @@ -47,7 +47,6 @@ import org.apache.lucene.index.codecs.lucene40.Lucene40SegmentInfosFormat; import org.apache.lucene.index.codecs.lucene40.Lucene40StoredFieldsFormat; import org.apache.lucene.index.codecs.lucene40.Lucene40TermVectorsFormat; import org.apache.lucene.index.codecs.pulsing.Pulsing40PostingsFormat; -import org.apache.lucene.index.values.IndexDocValues; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.store.AlreadyClosedException; @@ -1254,7 +1253,7 @@ public class TestAddIndexes extends LuceneTestCase { RandomIndexWriter w = new RandomIndexWriter(random, d1); Document doc = new Document(); doc.add(newField("id", "1", StringField.TYPE_STORED)); - IndexDocValuesField dv = new IndexDocValuesField("dv"); + DocValuesField dv = new DocValuesField("dv"); dv.setInt(1); doc.add(dv); w.addDocument(doc); @@ -1265,7 +1264,7 @@ public class TestAddIndexes extends LuceneTestCase { w = new RandomIndexWriter(random, d2); doc = new Document(); doc.add(newField("id", "2", StringField.TYPE_STORED)); - dv = new IndexDocValuesField("dv"); + dv = new DocValuesField("dv"); dv.setInt(2); doc.add(dv); w.addDocument(doc); @@ -1285,7 +1284,7 @@ public class TestAddIndexes extends LuceneTestCase { w.close(); IndexReader sr = getOnlySegmentReader(r3); assertEquals(2, sr.numDocs()); - IndexDocValues docValues = sr.perDocValues().docValues("dv"); + DocValues docValues = sr.perDocValues().docValues("dv"); assertNotNull(docValues); r3.close(); d3.close(); diff --git a/lucene/src/test/org/apache/lucene/index/TestDuelingCodecs.java b/lucene/src/test/org/apache/lucene/index/TestDuelingCodecs.java index 13172e2171c..b9313fce97e 100644 --- a/lucene/src/test/org/apache/lucene/index/TestDuelingCodecs.java +++ b/lucene/src/test/org/apache/lucene/index/TestDuelingCodecs.java @@ -25,10 +25,6 @@ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.index.codecs.Codec; -import org.apache.lucene.index.codecs.PerDocValues; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.IndexDocValues.Source; -import org.apache.lucene.index.values.ValueType; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.store.Directory; import org.apache.lucene.util.Bits; @@ -536,8 +532,8 @@ public class TestDuelingCodecs extends LuceneTestCase { FieldsEnum fieldsEnum = leftFields.iterator(); String field; while ((field = fieldsEnum.next()) != null) { - IndexDocValues leftDocValues = leftPerDoc.docValues(field); - IndexDocValues rightDocValues = rightPerDoc.docValues(field); + DocValues leftDocValues = leftPerDoc.docValues(field); + DocValues rightDocValues = rightPerDoc.docValues(field); if (leftDocValues == null || rightDocValues == null) { assertNull(info, leftDocValues); assertNull(info, rightDocValues); @@ -551,8 +547,8 @@ public class TestDuelingCodecs extends LuceneTestCase { /** * checks source API */ - public void assertDocValuesSource(Source left, Source right) throws Exception { - ValueType leftType = left.type(); + public void assertDocValuesSource(DocValues.Source left, DocValues.Source right) throws Exception { + DocValues.Type leftType = left.type(); assertEquals(info, leftType, right.type()); switch(leftType) { case VAR_INTS: diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexableField.java b/lucene/src/test/org/apache/lucene/index/TestIndexableField.java index 5a42dfd2d8c..1e170f332e0 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexableField.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexableField.java @@ -28,8 +28,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.NumericField.DataType; import org.apache.lucene.document.NumericField; import org.apache.lucene.document.StringField; -import org.apache.lucene.index.values.PerDocFieldValues; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.IndexSearcher; @@ -162,7 +161,7 @@ public class TestIndexableField extends LuceneTestCase { } @Override - public ValueType docValuesType() { + public DocValues.Type docValuesType() { return null; } diff --git a/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java b/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java index 0c326655f7e..ff0aa7bc600 100644 --- a/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java +++ b/lucene/src/test/org/apache/lucene/index/values/TestDocValues.java @@ -20,12 +20,14 @@ package org.apache.lucene.index.values; import java.io.IOException; import java.util.Comparator; +import org.apache.lucene.index.DocValues; +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.codecs.lucene40.values.Bytes; import org.apache.lucene.index.codecs.lucene40.values.Floats; import org.apache.lucene.index.codecs.lucene40.values.Ints; import org.apache.lucene.index.codecs.lucene40.values.Writer; -import org.apache.lucene.index.values.IndexDocValues.SortedSource; -import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.Counter; @@ -33,6 +35,7 @@ import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.UnicodeUtil; import org.apache.lucene.util._TestUtil; +// TODO: some of this should be under lucene40 codec tests? is talking to codec directly?f public class TestDocValues extends LuceneTestCase { private static final Comparator COMP = BytesRef.getUTF8SortedAsUnicodeComparator(); // TODO -- for sorted test, do our own Sort of the @@ -80,12 +83,12 @@ public class TestDocValues extends LuceneTestCase { w.finish(maxDoc); assertEquals(0, trackBytes.get()); - IndexDocValues r = Bytes.getValues(dir, "test", mode, fixedSize, maxDoc, COMP, newIOContext(random)); + DocValues r = Bytes.getValues(dir, "test", mode, fixedSize, maxDoc, COMP, newIOContext(random)); // Verify we can load source twice: for (int iter = 0; iter < 2; iter++) { Source s; - IndexDocValues.SortedSource ss; + DocValues.SortedSource ss; if (mode == Bytes.Mode.SORTED) { // default is unicode so we can simply pass null here s = ss = getSortedSource(r); @@ -159,19 +162,19 @@ public class TestDocValues extends LuceneTestCase { { Long.MIN_VALUE + 1, 1 }, { -1, Long.MAX_VALUE }, { Long.MIN_VALUE, -1 }, { 1, Long.MAX_VALUE }, { -1, Long.MAX_VALUE - 1 }, { Long.MIN_VALUE + 2, 1 }, }; - ValueType[] expectedTypes = new ValueType[] { ValueType.FIXED_INTS_64, - ValueType.FIXED_INTS_64, ValueType.FIXED_INTS_64, - ValueType.FIXED_INTS_64, ValueType.VAR_INTS, ValueType.VAR_INTS, - ValueType.VAR_INTS, }; + Type[] expectedTypes = new Type[] { Type.FIXED_INTS_64, + Type.FIXED_INTS_64, Type.FIXED_INTS_64, + Type.FIXED_INTS_64, Type.VAR_INTS, Type.VAR_INTS, + Type.VAR_INTS, }; for (int i = 0; i < minMax.length; i++) { Directory dir = newDirectory(); final Counter trackBytes = Counter.newCounter(); - Writer w = Ints.getWriter(dir, "test", trackBytes, ValueType.VAR_INTS, newIOContext(random)); + Writer w = Ints.getWriter(dir, "test", trackBytes, Type.VAR_INTS, newIOContext(random)); w.add(0, minMax[i][0]); w.add(1, minMax[i][1]); w.finish(2); assertEquals(0, trackBytes.get()); - IndexDocValues r = Ints.getValues(dir, "test", 2, ValueType.VAR_INTS, newIOContext(random)); + DocValues r = Ints.getValues(dir, "test", 2, Type.VAR_INTS, newIOContext(random)); Source source = getSource(r); assertEquals(i + " with min: " + minMax[i][0] + " max: " + minMax[i][1], expectedTypes[i], source.type()); @@ -184,14 +187,14 @@ public class TestDocValues extends LuceneTestCase { } public void testVInts() throws IOException { - testInts(ValueType.VAR_INTS, 63); + testInts(Type.VAR_INTS, 63); } public void testFixedInts() throws IOException { - testInts(ValueType.FIXED_INTS_64, 63); - testInts(ValueType.FIXED_INTS_32, 31); - testInts(ValueType.FIXED_INTS_16, 15); - testInts(ValueType.FIXED_INTS_8, 7); + testInts(Type.FIXED_INTS_64, 63); + testInts(Type.FIXED_INTS_32, 31); + testInts(Type.FIXED_INTS_16, 15); + testInts(Type.FIXED_INTS_8, 7); } @@ -199,12 +202,12 @@ public class TestDocValues extends LuceneTestCase { byte[] sourceArray = new byte[] {1,2,3}; Directory dir = newDirectory(); final Counter trackBytes = Counter.newCounter(); - Writer w = Ints.getWriter(dir, "test", trackBytes, ValueType.FIXED_INTS_8, newIOContext(random)); + Writer w = Ints.getWriter(dir, "test", trackBytes, Type.FIXED_INTS_8, newIOContext(random)); for (int i = 0; i < sourceArray.length; i++) { w.add(i, (long) sourceArray[i]); } w.finish(sourceArray.length); - IndexDocValues r = Ints.getValues(dir, "test", sourceArray.length, ValueType.FIXED_INTS_8, newIOContext(random)); + DocValues r = Ints.getValues(dir, "test", sourceArray.length, Type.FIXED_INTS_8, newIOContext(random)); Source source = r.getSource(); assertTrue(source.hasArray()); byte[] loaded = ((byte[])source.getArray()); @@ -220,12 +223,12 @@ public class TestDocValues extends LuceneTestCase { short[] sourceArray = new short[] {1,2,3}; Directory dir = newDirectory(); final Counter trackBytes = Counter.newCounter(); - Writer w = Ints.getWriter(dir, "test", trackBytes, ValueType.FIXED_INTS_16, newIOContext(random)); + Writer w = Ints.getWriter(dir, "test", trackBytes, Type.FIXED_INTS_16, newIOContext(random)); for (int i = 0; i < sourceArray.length; i++) { w.add(i, (long) sourceArray[i]); } w.finish(sourceArray.length); - IndexDocValues r = Ints.getValues(dir, "test", sourceArray.length, ValueType.FIXED_INTS_16, newIOContext(random)); + DocValues r = Ints.getValues(dir, "test", sourceArray.length, Type.FIXED_INTS_16, newIOContext(random)); Source source = r.getSource(); assertTrue(source.hasArray()); short[] loaded = ((short[])source.getArray()); @@ -241,12 +244,12 @@ public class TestDocValues extends LuceneTestCase { long[] sourceArray = new long[] {1,2,3}; Directory dir = newDirectory(); final Counter trackBytes = Counter.newCounter(); - Writer w = Ints.getWriter(dir, "test", trackBytes, ValueType.FIXED_INTS_64, newIOContext(random)); + Writer w = Ints.getWriter(dir, "test", trackBytes, Type.FIXED_INTS_64, newIOContext(random)); for (int i = 0; i < sourceArray.length; i++) { w.add(i, sourceArray[i]); } w.finish(sourceArray.length); - IndexDocValues r = Ints.getValues(dir, "test", sourceArray.length, ValueType.FIXED_INTS_64, newIOContext(random)); + DocValues r = Ints.getValues(dir, "test", sourceArray.length, Type.FIXED_INTS_64, newIOContext(random)); Source source = r.getSource(); assertTrue(source.hasArray()); long[] loaded = ((long[])source.getArray()); @@ -262,12 +265,12 @@ public class TestDocValues extends LuceneTestCase { int[] sourceArray = new int[] {1,2,3}; Directory dir = newDirectory(); final Counter trackBytes = Counter.newCounter(); - Writer w = Ints.getWriter(dir, "test", trackBytes, ValueType.FIXED_INTS_32, newIOContext(random)); + Writer w = Ints.getWriter(dir, "test", trackBytes, Type.FIXED_INTS_32, newIOContext(random)); for (int i = 0; i < sourceArray.length; i++) { w.add(i, (long) sourceArray[i]); } w.finish(sourceArray.length); - IndexDocValues r = Ints.getValues(dir, "test", sourceArray.length, ValueType.FIXED_INTS_32, newIOContext(random)); + DocValues r = Ints.getValues(dir, "test", sourceArray.length, Type.FIXED_INTS_32, newIOContext(random)); Source source = r.getSource(); assertTrue(source.hasArray()); int[] loaded = ((int[])source.getArray()); @@ -283,12 +286,12 @@ public class TestDocValues extends LuceneTestCase { float[] sourceArray = new float[] {1,2,3}; Directory dir = newDirectory(); final Counter trackBytes = Counter.newCounter(); - Writer w = Floats.getWriter(dir, "test", trackBytes, newIOContext(random), ValueType.FLOAT_32); + Writer w = Floats.getWriter(dir, "test", trackBytes, newIOContext(random), Type.FLOAT_32); for (int i = 0; i < sourceArray.length; i++) { w.add(i, sourceArray[i]); } w.finish(sourceArray.length); - IndexDocValues r = Floats.getValues(dir, "test", 3, newIOContext(random), ValueType.FLOAT_32); + DocValues r = Floats.getValues(dir, "test", 3, newIOContext(random), Type.FLOAT_32); Source source = r.getSource(); assertTrue(source.hasArray()); float[] loaded = ((float[])source.getArray()); @@ -304,12 +307,12 @@ public class TestDocValues extends LuceneTestCase { double[] sourceArray = new double[] {1,2,3}; Directory dir = newDirectory(); final Counter trackBytes = Counter.newCounter(); - Writer w = Floats.getWriter(dir, "test", trackBytes, newIOContext(random), ValueType.FLOAT_64); + Writer w = Floats.getWriter(dir, "test", trackBytes, newIOContext(random), Type.FLOAT_64); for (int i = 0; i < sourceArray.length; i++) { w.add(i, sourceArray[i]); } w.finish(sourceArray.length); - IndexDocValues r = Floats.getValues(dir, "test", 3, newIOContext(random), ValueType.FLOAT_64); + DocValues r = Floats.getValues(dir, "test", 3, newIOContext(random), Type.FLOAT_64); Source source = r.getSource(); assertTrue(source.hasArray()); double[] loaded = ((double[])source.getArray()); @@ -321,7 +324,7 @@ public class TestDocValues extends LuceneTestCase { dir.close(); } - private void testInts(ValueType type, int maxBit) throws IOException { + private void testInts(Type type, int maxBit) throws IOException { long maxV = 1; final int NUM_VALUES = 333 + random.nextInt(333); final long[] values = new long[NUM_VALUES]; @@ -338,7 +341,7 @@ public class TestDocValues extends LuceneTestCase { w.finish(NUM_VALUES + additionalDocs); assertEquals(0, trackBytes.get()); - IndexDocValues r = Ints.getValues(dir, "test", NUM_VALUES + additionalDocs, type, newIOContext(random)); + DocValues r = Ints.getValues(dir, "test", NUM_VALUES + additionalDocs, type, newIOContext(random)); for (int iter = 0; iter < 2; iter++) { Source s = getSource(r); assertEquals(type, s.type()); @@ -354,17 +357,17 @@ public class TestDocValues extends LuceneTestCase { } public void testFloats4() throws IOException { - runTestFloats(ValueType.FLOAT_32, 0.00001); + runTestFloats(Type.FLOAT_32, 0.00001); } - private void runTestFloats(ValueType type, double delta) throws IOException { + private void runTestFloats(Type type, double delta) throws IOException { Directory dir = newDirectory(); final Counter trackBytes = Counter.newCounter(); Writer w = Floats.getWriter(dir, "test", trackBytes, newIOContext(random), type); final int NUM_VALUES = 777 + random.nextInt(777);; final double[] values = new double[NUM_VALUES]; for (int i = 0; i < NUM_VALUES; i++) { - final double v = type == ValueType.FLOAT_32 ? random.nextFloat() : random + final double v = type == Type.FLOAT_32 ? random.nextFloat() : random .nextDouble(); values[i] = v; w.add(i, v); @@ -373,7 +376,7 @@ public class TestDocValues extends LuceneTestCase { w.finish(NUM_VALUES + additionalValues); assertEquals(0, trackBytes.get()); - IndexDocValues r = Floats.getValues(dir, "test", NUM_VALUES + additionalValues, newIOContext(random), type); + DocValues r = Floats.getValues(dir, "test", NUM_VALUES + additionalValues, newIOContext(random), type); for (int iter = 0; iter < 2; iter++) { Source s = getSource(r); for (int i = 0; i < NUM_VALUES; i++) { @@ -385,11 +388,11 @@ public class TestDocValues extends LuceneTestCase { } public void testFloats8() throws IOException { - runTestFloats(ValueType.FLOAT_64, 0.0); + runTestFloats(Type.FLOAT_64, 0.0); } - private Source getSource(IndexDocValues values) throws IOException { + private Source getSource(DocValues values) throws IOException { // getSource uses cache internally switch(random.nextInt(5)) { case 3: @@ -403,7 +406,7 @@ public class TestDocValues extends LuceneTestCase { } } - private SortedSource getSortedSource(IndexDocValues values) throws IOException { + private SortedSource getSortedSource(DocValues values) throws IOException { return getSource(values).asSortedSource(); } diff --git a/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java b/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java index 2550bba3de0..ac867ace604 100644 --- a/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java +++ b/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java @@ -27,21 +27,23 @@ import java.util.List; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.IndexDocValuesField; +import org.apache.lucene.document.DocValuesField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.LogDocMergePolicy; import org.apache.lucene.index.LogMergePolicy; import org.apache.lucene.index.MultiPerDocValues; +import org.apache.lucene.index.PerDocValues; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; +import org.apache.lucene.index.DocValues.Source; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.codecs.Codec; -import org.apache.lucene.index.codecs.PerDocValues; -import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockObtainFailedException; @@ -76,7 +78,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { IndexWriter writer = new IndexWriter(dir, writerConfig(false)); for (int i = 0; i < 5; i++) { Document doc = new Document(); - IndexDocValuesField valuesField = new IndexDocValuesField("docId"); + DocValuesField valuesField = new DocValuesField("docId"); valuesField.setInt(i); doc.add(valuesField); doc.add(new TextField("docId", "" + i)); @@ -102,7 +104,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { TopDocs search = searcher.search(query, 10); assertEquals(5, search.totalHits); ScoreDoc[] scoreDocs = search.scoreDocs; - IndexDocValues docValues = MultiPerDocValues.getPerDocs(reader).docValues("docId"); + DocValues docValues = MultiPerDocValues.getPerDocs(reader).docValues("docId"); Source source = docValues.getSource(); for (int i = 0; i < scoreDocs.length; i++) { assertEquals(i, scoreDocs[i].doc); @@ -130,10 +132,10 @@ public class TestDocValuesIndexing extends LuceneTestCase { public void testAddIndexes() throws IOException { int valuesPerIndex = 10; - List values = Arrays.asList(ValueType.values()); + List values = Arrays.asList(Type.values()); Collections.shuffle(values, random); - ValueType first = values.get(0); - ValueType second = values.get(1); + Type first = values.get(0); + Type second = values.get(1); // index first index Directory d_1 = newDirectory(); IndexWriter w_1 = new IndexWriter(d_1, writerConfig(random.nextBoolean())); @@ -256,11 +258,11 @@ public class TestDocValuesIndexing extends LuceneTestCase { Directory d = newDirectory(); IndexWriter w = new IndexWriter(d, cfg); final int numValues = 50 + atLeast(10); - final List numVariantList = new ArrayList(NUMERICS); + final List numVariantList = new ArrayList(NUMERICS); // run in random order to test if fill works correctly during merges Collections.shuffle(numVariantList, random); - for (ValueType val : numVariantList) { + for (Type val : numVariantList) { FixedBitSet deleted = indexValues(w, numValues, val, numVariantList, withDeletions, 7); List closeables = new ArrayList(); @@ -277,7 +279,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { case FIXED_INTS_32: case FIXED_INTS_64: case VAR_INTS: { - IndexDocValues intsReader = getDocValues(r, val.name()); + DocValues intsReader = getDocValues(r, val.name()); assertNotNull(intsReader); Source ints = getSource(intsReader); @@ -298,7 +300,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { break; case FLOAT_32: case FLOAT_64: { - IndexDocValues floatReader = getDocValues(r, val.name()); + DocValues floatReader = getDocValues(r, val.name()); assertNotNull(floatReader); Source floats = getSource(floatReader); for (int i = 0; i < base; i++) { @@ -333,11 +335,11 @@ public class TestDocValuesIndexing extends LuceneTestCase { throws CorruptIndexException, LockObtainFailedException, IOException { final Directory d = newDirectory(); IndexWriter w = new IndexWriter(d, cfg); - final List byteVariantList = new ArrayList(BYTES); + final List byteVariantList = new ArrayList(BYTES); // run in random order to test if fill works correctly during merges Collections.shuffle(byteVariantList, random); final int numValues = 50 + atLeast(10); - for (ValueType byteIndexValue : byteVariantList) { + for (Type byteIndexValue : byteVariantList) { List closeables = new ArrayList(); final int bytesSize = 1 + atLeast(50); FixedBitSet deleted = indexValues(w, numValues, byteIndexValue, @@ -346,7 +348,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { assertEquals(0, r.numDeletedDocs()); final int numRemainingValues = numValues - deleted.cardinality(); final int base = r.numDocs() - numRemainingValues; - IndexDocValues bytesReader = getDocValues(r, byteIndexValue.name()); + DocValues bytesReader = getDocValues(r, byteIndexValue.name()); assertNotNull("field " + byteIndexValue.name() + " returned null reader - maybe merged failed", bytesReader); Source bytes = getSource(bytesReader); @@ -416,7 +418,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { d.close(); } - private IndexDocValues getDocValues(IndexReader reader, String field) + private DocValues getDocValues(IndexReader reader, String field) throws IOException { boolean singleSeg = reader.getSequentialSubReaders().length == 1; PerDocValues perDoc = singleSeg ? reader.getSequentialSubReaders()[0].perDocValues() @@ -425,7 +427,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { case 0: return perDoc.docValues(field); case 1: - IndexDocValues docValues = perDoc.docValues(field); + DocValues docValues = perDoc.docValues(field); if (docValues != null) { return docValues; } @@ -436,7 +438,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { throw new RuntimeException(); } - private Source getSource(IndexDocValues values) throws IOException { + private Source getSource(DocValues values) throws IOException { // getSource uses cache internally switch(random.nextInt(5)) { case 3: @@ -451,24 +453,24 @@ public class TestDocValuesIndexing extends LuceneTestCase { } - private static EnumSet BYTES = EnumSet.of(ValueType.BYTES_FIXED_DEREF, - ValueType.BYTES_FIXED_STRAIGHT, ValueType.BYTES_VAR_DEREF, - ValueType.BYTES_VAR_STRAIGHT, ValueType.BYTES_FIXED_SORTED, ValueType.BYTES_VAR_SORTED); + private static EnumSet BYTES = EnumSet.of(Type.BYTES_FIXED_DEREF, + Type.BYTES_FIXED_STRAIGHT, Type.BYTES_VAR_DEREF, + Type.BYTES_VAR_STRAIGHT, Type.BYTES_FIXED_SORTED, Type.BYTES_VAR_SORTED); - private static EnumSet NUMERICS = EnumSet.of(ValueType.VAR_INTS, - ValueType.FIXED_INTS_16, ValueType.FIXED_INTS_32, - ValueType.FIXED_INTS_64, - ValueType.FIXED_INTS_8, - ValueType.FLOAT_32, - ValueType.FLOAT_64); + private static EnumSet NUMERICS = EnumSet.of(Type.VAR_INTS, + Type.FIXED_INTS_16, Type.FIXED_INTS_32, + Type.FIXED_INTS_64, + Type.FIXED_INTS_8, + Type.FLOAT_32, + Type.FLOAT_64); - private FixedBitSet indexValues(IndexWriter w, int numValues, ValueType value, - List valueVarList, boolean withDeletions, int bytesSize) + private FixedBitSet indexValues(IndexWriter w, int numValues, Type value, + List valueVarList, boolean withDeletions, int bytesSize) throws CorruptIndexException, IOException { final boolean isNumeric = NUMERICS.contains(value); FixedBitSet deleted = new FixedBitSet(numValues); Document doc = new Document(); - IndexDocValuesField valField = new IndexDocValuesField(value.name()); + DocValuesField valField = new DocValuesField(value.name()); doc.add(valField); final BytesRef bytesRef = new BytesRef(); @@ -522,7 +524,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { if (i % 7 == 0) { if (withDeletions && random.nextBoolean()) { - ValueType val = valueVarList.get(random.nextInt(1 + valueVarList + Type val = valueVarList.get(random.nextInt(1 + valueVarList .indexOf(value))); final int randInt = val == value ? random.nextInt(1 + i) : random .nextInt(numValues); @@ -545,11 +547,11 @@ public class TestDocValuesIndexing extends LuceneTestCase { return deleted; } - public void testMultiValuedIndexDocValuesField() throws Exception { + public void testMultiValuedDocValuesField() throws Exception { Directory d = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random, d); Document doc = new Document(); - IndexDocValuesField f = new IndexDocValuesField("field"); + DocValuesField f = new DocValuesField("field"); f.setInt(17); // Index doc values are single-valued so we should not // be able to add same field more than once: @@ -577,12 +579,12 @@ public class TestDocValuesIndexing extends LuceneTestCase { Directory d = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random, d); Document doc = new Document(); - IndexDocValuesField f = new IndexDocValuesField("field"); + DocValuesField f = new DocValuesField("field"); f.setInt(17); // Index doc values are single-valued so we should not // be able to add same field more than once: doc.add(f); - IndexDocValuesField f2 = new IndexDocValuesField("field"); + DocValuesField f2 = new DocValuesField("field"); f2.setFloat(22.0); doc.add(f2); try { diff --git a/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java b/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java index 4799f4b10e6..412f8cd8040 100644 --- a/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java +++ b/lucene/src/test/org/apache/lucene/index/values/TestTypePromotion.java @@ -7,18 +7,20 @@ 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.IndexDocValuesField; +import org.apache.lucene.document.DocValuesField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader.ReaderContext; +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.DocValues.Source; +import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.NoMergePolicy; import org.apache.lucene.index.SlowMultiReaderWrapper; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.lucene40.values.BytesRefUtils; -import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; @@ -47,22 +49,22 @@ public class TestTypePromotion extends LuceneTestCase { assumeFalse("cannot work with preflex codec", Codec.getDefault().getName().equals("Lucene3x")); } - private static EnumSet INTEGERS = EnumSet.of(ValueType.VAR_INTS, - ValueType.FIXED_INTS_16, ValueType.FIXED_INTS_32, - ValueType.FIXED_INTS_64, ValueType.FIXED_INTS_8); + private static EnumSet INTEGERS = EnumSet.of(Type.VAR_INTS, + Type.FIXED_INTS_16, Type.FIXED_INTS_32, + Type.FIXED_INTS_64, Type.FIXED_INTS_8); - private static EnumSet FLOATS = EnumSet.of(ValueType.FLOAT_32, - ValueType.FLOAT_64); + private static EnumSet FLOATS = EnumSet.of(Type.FLOAT_32, + Type.FLOAT_64); - private static EnumSet UNSORTED_BYTES = EnumSet.of( - ValueType.BYTES_FIXED_DEREF, ValueType.BYTES_FIXED_STRAIGHT, - ValueType.BYTES_VAR_STRAIGHT, ValueType.BYTES_VAR_DEREF); + private static EnumSet UNSORTED_BYTES = EnumSet.of( + Type.BYTES_FIXED_DEREF, Type.BYTES_FIXED_STRAIGHT, + Type.BYTES_VAR_STRAIGHT, Type.BYTES_VAR_DEREF); - private static EnumSet SORTED_BYTES = EnumSet.of( - ValueType.BYTES_FIXED_SORTED, ValueType.BYTES_VAR_SORTED); + private static EnumSet SORTED_BYTES = EnumSet.of( + Type.BYTES_FIXED_SORTED, Type.BYTES_VAR_SORTED); - public ValueType randomValueType(EnumSet typeEnum, Random random) { - ValueType[] array = typeEnum.toArray(new ValueType[0]); + public Type randomValueType(EnumSet typeEnum, Random random) { + Type[] array = typeEnum.toArray(new Type[0]); return array[random.nextInt(array.length)]; } @@ -70,7 +72,7 @@ public class TestTypePromotion extends LuceneTestCase { Int, Float, Byte } - private void runTest(EnumSet types, TestType type) + private void runTest(EnumSet types, TestType type) throws CorruptIndexException, IOException { Directory dir = newDirectory(); IndexWriter writer = new IndexWriter(dir, @@ -79,11 +81,11 @@ public class TestTypePromotion extends LuceneTestCase { int num_2 = atLeast(200); int num_3 = atLeast(200); long[] values = new long[num_1 + num_2 + num_3]; - index(writer, new IndexDocValuesField("promote"), + index(writer, new DocValuesField("promote"), randomValueType(types, random), values, 0, num_1); writer.commit(); - index(writer, new IndexDocValuesField("promote"), + index(writer, new DocValuesField("promote"), randomValueType(types, random), values, num_1, num_2); writer.commit(); @@ -94,7 +96,7 @@ public class TestTypePromotion extends LuceneTestCase { Directory dir_2 = newDirectory() ; IndexWriter writer_2 = new IndexWriter(dir_2, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))); - index(writer_2, new IndexDocValuesField("promote"), + index(writer_2, new DocValuesField("promote"), randomValueType(types, random), values, num_1 + num_2, num_3); writer_2.commit(); writer_2.close(); @@ -110,7 +112,7 @@ public class TestTypePromotion extends LuceneTestCase { } dir_2.close(); } else { - index(writer, new IndexDocValuesField("promote"), + index(writer, new DocValuesField("promote"), randomValueType(types, random), values, num_1 + num_2, num_3); } @@ -127,7 +129,7 @@ public class TestTypePromotion extends LuceneTestCase { assertEquals(1, reader.getSequentialSubReaders().length); ReaderContext topReaderContext = reader.getTopReaderContext(); ReaderContext[] children = topReaderContext.children(); - IndexDocValues docValues = children[0].reader.docValues("promote"); + DocValues docValues = children[0].reader.docValues("promote"); assertEquals(1, children.length); Source directSource = docValues.getDirectSource(); for (int i = 0; i < values.length; i++) { @@ -172,8 +174,8 @@ public class TestTypePromotion extends LuceneTestCase { reader.close(); } - public void index(IndexWriter writer, IndexDocValuesField valField, - ValueType valueType, long[] values, int offset, int num) + public void index(IndexWriter writer, DocValuesField valField, + Type valueType, long[] values, int offset, int num) throws CorruptIndexException, IOException { BytesRef ref = new BytesRef(new byte[] { 1, 2, 3, 4 }); for (int i = offset; i < offset + num; i++) { @@ -267,7 +269,7 @@ public class TestTypePromotion extends LuceneTestCase { int num_1 = atLeast(200); int num_2 = atLeast(200); long[] values = new long[num_1 + num_2]; - index(writer, new IndexDocValuesField("promote"), + index(writer, new DocValuesField("promote"), randomValueType(INTEGERS, random), values, 0, num_1); writer.commit(); @@ -276,7 +278,7 @@ public class TestTypePromotion extends LuceneTestCase { Directory dir_2 = newDirectory() ; IndexWriter writer_2 = new IndexWriter(dir_2, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))); - index(writer_2, new IndexDocValuesField("promote"), + index(writer_2, new DocValuesField("promote"), randomValueType(random.nextBoolean() ? UNSORTED_BYTES : SORTED_BYTES, random), values, num_1, num_2); writer_2.commit(); writer_2.close(); @@ -290,7 +292,7 @@ public class TestTypePromotion extends LuceneTestCase { } dir_2.close(); } else { - index(writer, new IndexDocValuesField("promote"), + index(writer, new DocValuesField("promote"), randomValueType(random.nextBoolean() ? UNSORTED_BYTES : SORTED_BYTES, random), values, num_1, num_2); writer.commit(); } @@ -307,10 +309,10 @@ public class TestTypePromotion extends LuceneTestCase { assertEquals(1, reader.getSequentialSubReaders().length); ReaderContext topReaderContext = reader.getTopReaderContext(); ReaderContext[] children = topReaderContext.children(); - IndexDocValues docValues = children[0].reader.docValues("promote"); + DocValues docValues = children[0].reader.docValues("promote"); assertNotNull(docValues); assertValues(TestType.Byte, dir, values); - assertEquals(ValueType.BYTES_VAR_STRAIGHT, docValues.type()); + assertEquals(Type.BYTES_VAR_STRAIGHT, docValues.type()); reader.close(); dir.close(); } diff --git a/lucene/src/test/org/apache/lucene/search/TestDocValuesScoring.java b/lucene/src/test/org/apache/lucene/search/TestDocValuesScoring.java index 5fedea83927..4c1fb39fb41 100644 --- a/lucene/src/test/org/apache/lucene/search/TestDocValuesScoring.java +++ b/lucene/src/test/org/apache/lucene/search/TestDocValuesScoring.java @@ -21,15 +21,15 @@ import java.io.IOException; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.IndexDocValuesField; +import org.apache.lucene.document.DocValuesField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.FieldInvertState; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; +import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.IndexReader.AtomicReaderContext; import org.apache.lucene.index.codecs.Codec; -import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.search.similarities.DefaultSimilarityProvider; import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.search.similarities.SimilarityProvider; @@ -48,7 +48,7 @@ public class TestDocValuesScoring extends LuceneTestCase { private static final float SCORE_EPSILON = 0.001f; /* for comparing floats */ public void testSimple() throws Exception { - assumeFalse("PreFlex codec cannot work with IndexDocValues!", + assumeFalse("PreFlex codec cannot work with DocValues!", "Lucene3x".equals(Codec.getDefault().getName())); Directory dir = newDirectory(); @@ -56,7 +56,7 @@ public class TestDocValuesScoring extends LuceneTestCase { Document doc = new Document(); Field field = newField("foo", "", TextField.TYPE_UNSTORED); doc.add(field); - IndexDocValuesField dvField = new IndexDocValuesField("foo_boost"); + DocValuesField dvField = new DocValuesField("foo_boost"); doc.add(dvField); Field field2 = newField("bar", "", TextField.TYPE_UNSTORED); doc.add(field2); diff --git a/lucene/src/test/org/apache/lucene/search/TestSort.java b/lucene/src/test/org/apache/lucene/search/TestSort.java index 6f7e8266b45..8cf20a11054 100644 --- a/lucene/src/test/org/apache/lucene/search/TestSort.java +++ b/lucene/src/test/org/apache/lucene/search/TestSort.java @@ -28,7 +28,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.IndexDocValuesField; +import org.apache.lucene.document.DocValuesField; import org.apache.lucene.document.StringField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.CorruptIndexException; @@ -42,7 +42,7 @@ import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.SlowMultiReaderWrapper; import org.apache.lucene.index.Term; import org.apache.lucene.index.codecs.Codec; -import org.apache.lucene.index.values.ValueType; +import org.apache.lucene.index.DocValues; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.FieldValueHitQueue.Entry; import org.apache.lucene.store.Directory; @@ -121,18 +121,18 @@ public class TestSort extends LuceneTestCase { dirs.add(indexStore); RandomIndexWriter writer = new RandomIndexWriter(random, indexStore, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setMergePolicy(newLogMergePolicy())); - final ValueType stringDVType; + final DocValues.Type stringDVType; if (dvStringSorted) { // Index sorted - stringDVType = random.nextBoolean() ? ValueType.BYTES_VAR_SORTED : ValueType.BYTES_FIXED_SORTED; + stringDVType = random.nextBoolean() ? DocValues.Type.BYTES_VAR_SORTED : DocValues.Type.BYTES_FIXED_SORTED; } else { // Index non-sorted if (random.nextBoolean()) { // Fixed - stringDVType = random.nextBoolean() ? ValueType.BYTES_FIXED_STRAIGHT : ValueType.BYTES_FIXED_DEREF; + stringDVType = random.nextBoolean() ? DocValues.Type.BYTES_FIXED_STRAIGHT : DocValues.Type.BYTES_FIXED_DEREF; } else { // Var - stringDVType = random.nextBoolean() ? ValueType.BYTES_VAR_STRAIGHT : ValueType.BYTES_VAR_DEREF; + stringDVType = random.nextBoolean() ? DocValues.Type.BYTES_VAR_STRAIGHT : DocValues.Type.BYTES_VAR_DEREF; } } @@ -148,21 +148,21 @@ public class TestSort extends LuceneTestCase { if (data[i][2] != null) { Field f = new StringField ("int", data[i][2]); if (supportsDocValues) { - f = IndexDocValuesField.build(f, ValueType.VAR_INTS); + f = DocValuesField.build(f, DocValues.Type.VAR_INTS); } doc.add(f); } if (data[i][3] != null) { Field f = new StringField ("float", data[i][3]); if (supportsDocValues) { - f = IndexDocValuesField.build(f, ValueType.FLOAT_32); + f = DocValuesField.build(f, DocValues.Type.FLOAT_32); } doc.add(f); } if (data[i][4] != null) { Field f = new StringField ("string", data[i][4]); if (supportsDocValues) { - f = IndexDocValuesField.build(f, stringDVType); + f = DocValuesField.build(f, stringDVType); } doc.add(f); } @@ -172,7 +172,7 @@ public class TestSort extends LuceneTestCase { if (data[i][8] != null) { Field f = new StringField ("double", data[i][8]); if (supportsDocValues) { - f = IndexDocValuesField.build(f, ValueType.FLOAT_64); + f = DocValuesField.build(f, DocValues.Type.FLOAT_64); } doc.add(f); } @@ -219,13 +219,13 @@ public class TestSort extends LuceneTestCase { //doc.add (new Field ("contents", Integer.toString(i), Field.Store.NO, Field.Index.ANALYZED)); Field f = new StringField("string", num); if (supportsDocValues) { - f = IndexDocValuesField.build(f, ValueType.BYTES_VAR_SORTED); + f = DocValuesField.build(f, DocValues.Type.BYTES_VAR_SORTED); } doc.add (f); String num2 = getRandomCharString(getRandomNumber(1, 4), 48, 50); f = new StringField ("string2", num2); if (supportsDocValues) { - f = IndexDocValuesField.build(f, ValueType.BYTES_VAR_SORTED); + f = DocValuesField.build(f, DocValues.Type.BYTES_VAR_SORTED); } doc.add (f); doc.add (new Field ("tracer2", num2, onlyStored)); @@ -238,13 +238,13 @@ public class TestSort extends LuceneTestCase { //doc.add (new Field ("contents", Integer.toString(i), Field.Store.NO, Field.Index.ANALYZED)); f = new StringField("string_fixed", numFixed); if (supportsDocValues) { - f = IndexDocValuesField.build(f, ValueType.BYTES_FIXED_SORTED); + f = DocValuesField.build(f, DocValues.Type.BYTES_FIXED_SORTED); } doc.add (f); String num2Fixed = getRandomCharString(fixedLen2, 48, 52); f = new StringField ("string2_fixed", num2Fixed); if (supportsDocValues) { - f = IndexDocValuesField.build(f, ValueType.BYTES_FIXED_SORTED); + f = DocValuesField.build(f, DocValues.Type.BYTES_FIXED_SORTED); } doc.add (f); doc.add (new Field ("tracer2_fixed", num2Fixed, onlyStored)); diff --git a/modules/grouping/CHANGES.txt b/modules/grouping/CHANGES.txt index 3c6d1c35754..b80e94f7030 100644 --- a/modules/grouping/CHANGES.txt +++ b/modules/grouping/CHANGES.txt @@ -17,4 +17,4 @@ LUCENE-3483: Move Function grouping collectors from Solr to New features -LUCENE-3496: Support grouping by IndexDocValues. (Martijn van Groningen) \ No newline at end of file +LUCENE-3496: Support grouping by DocValues. (Martijn van Groningen) \ No newline at end of file diff --git a/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVAllGroupHeadsCollector.java b/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVAllGroupHeadsCollector.java index ab14d414003..1886ff86936 100644 --- a/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVAllGroupHeadsCollector.java +++ b/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVAllGroupHeadsCollector.java @@ -17,9 +17,9 @@ package org.apache.lucene.search.grouping.dv; * limitations under the License. */ +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.DocValues.Type; // javadocs import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.ValueType; import org.apache.lucene.search.*; import org.apache.lucene.search.grouping.AbstractAllGroupHeadsCollector; import org.apache.lucene.util.BytesRef; @@ -40,13 +40,13 @@ public abstract class DVAllGroupHeadsCollectorAbstractAllGroupHeadsCollector instance based on the supplied arguments * @throws IOException If I/O related errors occur */ - public static AbstractAllGroupHeadsCollector create(String groupField, Sort sortWithinGroup, ValueType type, boolean diskResident) throws IOException { + public static AbstractAllGroupHeadsCollector create(String groupField, Sort sortWithinGroup, DocValues.Type type, boolean diskResident) throws IOException { switch (type) { case VAR_INTS: case FIXED_INTS_8: @@ -126,8 +126,8 @@ public abstract class DVAllGroupHeadsCollector groups; - GeneralAllGroupHeadsCollector(String groupField, ValueType valueType, Sort sortWithinGroup, boolean diskResident) throws IOException { + GeneralAllGroupHeadsCollector(String groupField, DocValues.Type valueType, Sort sortWithinGroup, boolean diskResident) throws IOException { super(groupField, valueType, sortWithinGroup.getSort().length, diskResident); this.sortWithinGroup = sortWithinGroup; groups = new HashMap(); @@ -211,9 +211,9 @@ public abstract class DVAllGroupHeadsCollector extends AbstractAll /** * Expert: Constructs a {@link DVAllGroupsCollector}. - * Selects and constructs the most optimal all groups collector implementation for grouping by {@link IndexDocValues}. + * Selects and constructs the most optimal all groups collector implementation for grouping by {@link DocValues}. * * * @param groupField The field to group by - * @param type The {@link ValueType} which is used to select a concrete implementation. + * @param type The {@link Type} which is used to select a concrete implementation. * @param diskResident Whether the values to group by should be disk resident * @param initialSize The initial allocation size of the * internal int set and group list * which should roughly match the total * number of expected unique groups. Be aware that the * heap usage is 4 bytes * initialSize. Not all concrete implementions use this! - * @return the most optimal all groups collector implementation for grouping by {@link IndexDocValues} + * @return the most optimal all groups collector implementation for grouping by {@link DocValues} */ - public static DVAllGroupsCollector create(String groupField, ValueType type, boolean diskResident, int initialSize) { + public static DVAllGroupsCollector create(String groupField, DocValues.Type type, boolean diskResident, int initialSize) { switch (type) { case VAR_INTS: case FIXED_INTS_8: @@ -78,25 +78,25 @@ public abstract class DVAllGroupsCollector extends AbstractAll /** * Constructs a {@link DVAllGroupsCollector}. - * Selects and constructs the most optimal all groups collector implementation for grouping by {@link IndexDocValues}. + * Selects and constructs the most optimal all groups collector implementation for grouping by {@link DocValues}. * If implementations require an initial allocation size then this will be set to 128. * * * @param groupField The field to group by - * @param type The {@link ValueType} which is used to select a concrete implementation. + * @param type The {@link Type} which is used to select a concrete implementation. * @param diskResident Wether the values to group by should be disk resident - * @return the most optimal all groups collector implementation for grouping by {@link IndexDocValues} + * @return the most optimal all groups collector implementation for grouping by {@link DocValues} */ - public static DVAllGroupsCollector create(String groupField, ValueType type, boolean diskResident) { + public static DVAllGroupsCollector create(String groupField, DocValues.Type type, boolean diskResident) { return create(groupField, type, diskResident, DEFAULT_INITIAL_SIZE); } final String groupField; - final ValueType valueType; + final DocValues.Type valueType; final boolean diskResident; final Collection groups; - DVAllGroupsCollector(String groupField, ValueType valueType, boolean diskResident, Collection groups) { + DVAllGroupsCollector(String groupField, DocValues.Type valueType, boolean diskResident, Collection groups) { this.groupField = groupField; this.valueType = valueType; this.diskResident = diskResident; @@ -105,8 +105,8 @@ public abstract class DVAllGroupsCollector extends AbstractAll @Override public void setNextReader(IndexReader.AtomicReaderContext readerContext) throws IOException { - final IndexDocValues dv = readerContext.reader.docValues(groupField); - final IndexDocValues.Source dvSource; + final DocValues dv = readerContext.reader.docValues(groupField); + final DocValues.Source dvSource; if (dv != null) { dvSource = diskResident ? dv.getDirectSource() : dv.getSource(); } else { @@ -121,21 +121,21 @@ public abstract class DVAllGroupsCollector extends AbstractAll * @param source The idv source to be used by concrete implementations * @param readerContext The current reader context */ - protected abstract void setDocValuesSources(IndexDocValues.Source source, IndexReader.AtomicReaderContext readerContext); + protected abstract void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext); /** * @return The default source when no doc values are available. * @param readerContext The current reader context */ - protected IndexDocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { - return IndexDocValues.getDefaultSource(valueType); + protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { + return DocValues.getDefaultSource(valueType); } static class Lng extends DVAllGroupsCollector { - private IndexDocValues.Source source; + private DocValues.Source source; - Lng(String groupField, ValueType valueType, boolean diskResident) { + Lng(String groupField, DocValues.Type valueType, boolean diskResident) { super(groupField, valueType, diskResident, new TreeSet()); } @@ -150,7 +150,7 @@ public abstract class DVAllGroupsCollector extends AbstractAll return groups; } - protected void setDocValuesSources(IndexDocValues.Source source, IndexReader.AtomicReaderContext readerContext) { + protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) { this.source = source; } @@ -158,9 +158,9 @@ public abstract class DVAllGroupsCollector extends AbstractAll static class Dbl extends DVAllGroupsCollector { - private IndexDocValues.Source source; + private DocValues.Source source; - Dbl(String groupField, ValueType valueType, boolean diskResident) { + Dbl(String groupField, DocValues.Type valueType, boolean diskResident) { super(groupField, valueType, diskResident, new TreeSet()); } @@ -175,7 +175,7 @@ public abstract class DVAllGroupsCollector extends AbstractAll return groups; } - protected void setDocValuesSources(IndexDocValues.Source source, IndexReader.AtomicReaderContext readerContext) { + protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) { this.source = source; } @@ -185,9 +185,9 @@ public abstract class DVAllGroupsCollector extends AbstractAll private final BytesRef spare = new BytesRef(); - private IndexDocValues.Source source; + private DocValues.Source source; - BR(String groupField, ValueType valueType, boolean diskResident) { + BR(String groupField, DocValues.Type valueType, boolean diskResident) { super(groupField, valueType, diskResident, new TreeSet()); } @@ -202,7 +202,7 @@ public abstract class DVAllGroupsCollector extends AbstractAll return groups; } - protected void setDocValuesSources(IndexDocValues.Source source, IndexReader.AtomicReaderContext readerContext) { + protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) { this.source = source; } @@ -213,9 +213,9 @@ public abstract class DVAllGroupsCollector extends AbstractAll private final SentinelIntSet ordSet; private final BytesRef spare = new BytesRef(); - private IndexDocValues.SortedSource source; + private DocValues.SortedSource source; - SortedBR(String groupField, ValueType valueType, boolean diskResident, int initialSize) { + SortedBR(String groupField, DocValues.Type valueType, boolean diskResident, int initialSize) { super(groupField, valueType, diskResident, new ArrayList(initialSize)); ordSet = new SentinelIntSet(initialSize, -1); } @@ -233,7 +233,7 @@ public abstract class DVAllGroupsCollector extends AbstractAll return groups; } - protected void setDocValuesSources(IndexDocValues.Source source, IndexReader.AtomicReaderContext readerContext) { + protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) { this.source = source.asSortedSource(); ordSet.clear(); @@ -246,8 +246,8 @@ public abstract class DVAllGroupsCollector extends AbstractAll } @Override - protected IndexDocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { - return IndexDocValues.getDefaultSortedSource(valueType, readerContext.reader.maxDoc()); + protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { + return DocValues.getDefaultSortedSource(valueType, readerContext.reader.maxDoc()); } } diff --git a/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVFirstPassGroupingCollector.java b/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVFirstPassGroupingCollector.java index d5b70355c15..3750582c6b8 100644 --- a/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVFirstPassGroupingCollector.java +++ b/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVFirstPassGroupingCollector.java @@ -17,9 +17,9 @@ package org.apache.lucene.search.grouping.dv; * limitations under the License. */ +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.DocValues.Type; // javadocs import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.ValueType; import org.apache.lucene.search.Sort; import org.apache.lucene.search.grouping.AbstractFirstPassGroupingCollector; import org.apache.lucene.util.BytesRef; @@ -35,9 +35,9 @@ public abstract class DVFirstPassGroupingCollector extends Abs final String groupField; final boolean diskResident; - final ValueType valueType; + final DocValues.Type valueType; - public static DVFirstPassGroupingCollector create(Sort groupSort, int topNGroups, String groupField, ValueType type, boolean diskResident) throws IOException { + public static DVFirstPassGroupingCollector create(Sort groupSort, int topNGroups, String groupField, DocValues.Type type, boolean diskResident) throws IOException { switch (type) { case VAR_INTS: case FIXED_INTS_8: @@ -61,7 +61,7 @@ public abstract class DVFirstPassGroupingCollector extends Abs } } - DVFirstPassGroupingCollector(Sort groupSort, int topNGroups, String groupField, boolean diskResident, ValueType valueType) throws IOException { + DVFirstPassGroupingCollector(Sort groupSort, int topNGroups, String groupField, boolean diskResident, DocValues.Type valueType) throws IOException { super(groupSort, topNGroups); this.groupField = groupField; this.diskResident = diskResident; @@ -72,8 +72,8 @@ public abstract class DVFirstPassGroupingCollector extends Abs public void setNextReader(IndexReader.AtomicReaderContext readerContext) throws IOException { super.setNextReader(readerContext); - final IndexDocValues dv = readerContext.reader.docValues(groupField); - final IndexDocValues.Source dvSource; + final DocValues dv = readerContext.reader.docValues(groupField); + final DocValues.Source dvSource; if (dv != null) { dvSource = diskResident ? dv.getDirectSource() : dv.getSource(); } else { @@ -87,21 +87,21 @@ public abstract class DVFirstPassGroupingCollector extends Abs * * @param source The idv source to be used by concrete implementations */ - protected abstract void setDocValuesSources(IndexDocValues.Source source); + protected abstract void setDocValuesSources(DocValues.Source source); /** * @return The default source when no doc values are available. * @param readerContext The current reader context */ - protected IndexDocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { - return IndexDocValues.getDefaultSource(valueType); + protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { + return DocValues.getDefaultSource(valueType); } static class Lng extends DVFirstPassGroupingCollector { - private IndexDocValues.Source source; + private DocValues.Source source; - Lng(Sort groupSort, int topNGroups, String groupField, boolean diskResident, ValueType type) throws IOException { + Lng(Sort groupSort, int topNGroups, String groupField, boolean diskResident, DocValues.Type type) throws IOException { super(groupSort, topNGroups, groupField, diskResident, type); } @@ -113,16 +113,16 @@ public abstract class DVFirstPassGroupingCollector extends Abs return groupValue; } - protected void setDocValuesSources(IndexDocValues.Source source) { + protected void setDocValuesSources(DocValues.Source source) { this.source = source; } } static class Dbl extends DVFirstPassGroupingCollector { - private IndexDocValues.Source source; + private DocValues.Source source; - Dbl(Sort groupSort, int topNGroups, String groupField, boolean diskResident, ValueType type) throws IOException { + Dbl(Sort groupSort, int topNGroups, String groupField, boolean diskResident, DocValues.Type type) throws IOException { super(groupSort, topNGroups, groupField, diskResident, type); } @@ -134,17 +134,17 @@ public abstract class DVFirstPassGroupingCollector extends Abs return groupValue; } - protected void setDocValuesSources(IndexDocValues.Source source) { + protected void setDocValuesSources(DocValues.Source source) { this.source = source; } } static class BR extends DVFirstPassGroupingCollector { - private IndexDocValues.Source source; + private DocValues.Source source; private final BytesRef spare = new BytesRef(); - BR(Sort groupSort, int topNGroups, String groupField, boolean diskResident, ValueType type) throws IOException { + BR(Sort groupSort, int topNGroups, String groupField, boolean diskResident, DocValues.Type type) throws IOException { super(groupSort, topNGroups, groupField, diskResident, type); } @@ -162,17 +162,17 @@ public abstract class DVFirstPassGroupingCollector extends Abs } @Override - protected void setDocValuesSources(IndexDocValues.Source source) { + protected void setDocValuesSources(DocValues.Source source) { this.source = source; } } static class SortedBR extends DVFirstPassGroupingCollector { - private IndexDocValues.SortedSource sortedSource; + private DocValues.SortedSource sortedSource; private final BytesRef spare = new BytesRef(); - SortedBR(Sort groupSort, int topNGroups, String groupField, boolean diskResident, ValueType type) throws IOException { + SortedBR(Sort groupSort, int topNGroups, String groupField, boolean diskResident, DocValues.Type type) throws IOException { super(groupSort, topNGroups, groupField, diskResident, type); } @@ -192,13 +192,13 @@ public abstract class DVFirstPassGroupingCollector extends Abs } @Override - protected void setDocValuesSources(IndexDocValues.Source source) { + protected void setDocValuesSources(DocValues.Source source) { this.sortedSource = source.asSortedSource(); } @Override - protected IndexDocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { - return IndexDocValues.getDefaultSortedSource(valueType, readerContext.reader.maxDoc()); + protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { + return DocValues.getDefaultSortedSource(valueType, readerContext.reader.maxDoc()); } } diff --git a/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVSecondPassGroupingCollector.java b/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVSecondPassGroupingCollector.java index b3797f5f1b0..4f0d41d87a4 100644 --- a/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVSecondPassGroupingCollector.java +++ b/modules/grouping/src/java/org/apache/lucene/search/grouping/dv/DVSecondPassGroupingCollector.java @@ -17,9 +17,9 @@ package org.apache.lucene.search.grouping.dv; * limitations under the License. */ +import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.DocValues.Type; // javadocs import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.values.IndexDocValues; -import org.apache.lucene.index.values.ValueType; import org.apache.lucene.search.Sort; import org.apache.lucene.search.grouping.AbstractSecondPassGroupingCollector; import org.apache.lucene.search.grouping.SearchGroup; @@ -38,11 +38,11 @@ public abstract class DVSecondPassGroupingCollector extends Abstrac /** * Constructs a {@link DVSecondPassGroupingCollector}. - * Selects and constructs the most optimal second pass collector implementation for grouping by {@link IndexDocValues}. + * Selects and constructs the most optimal second pass collector implementation for grouping by {@link DocValues}. * * @param groupField The field to group by * @param diskResident Whether the values to group by should be disk resident - * @param type The {@link org.apache.lucene.index.values.ValueType} which is used to select a concrete implementation. + * @param type The {@link Type} which is used to select a concrete implementation. * @param searchGroups The groups from the first phase search * @param groupSort The sort used for the groups * @param withinGroupSort The sort used for documents inside a group @@ -50,13 +50,13 @@ public abstract class DVSecondPassGroupingCollector extends Abstrac * @param getScores Whether to include scores for the documents inside a group * @param getMaxScores Whether to keep track of the higest score per group * @param fillSortFields Whether to include the sort values - * @return the most optimal second pass collector implementation for grouping by {@link IndexDocValues} + * @return the most optimal second pass collector implementation for grouping by {@link DocValues} * @throws IOException If I/O related errors occur */ @SuppressWarnings("unchecked") public static DVSecondPassGroupingCollector create(String groupField, boolean diskResident, - ValueType type, + DocValues.Type type, Collection searchGroups, Sort groupSort, Sort withinGroupSort, @@ -92,10 +92,10 @@ public abstract class DVSecondPassGroupingCollector extends Abstrac } final String groupField; - final ValueType valueType; + final DocValues.Type valueType; final boolean diskResident; - DVSecondPassGroupingCollector(String groupField, ValueType valueType, boolean diskResident, Collection> searchGroups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields) throws IOException { + DVSecondPassGroupingCollector(String groupField, DocValues.Type valueType, boolean diskResident, Collection> searchGroups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields) throws IOException { super(searchGroups, groupSort, withinGroupSort, maxDocsPerGroup, getScores, getMaxScores, fillSortFields); this.groupField = groupField; this.valueType = valueType; @@ -106,8 +106,8 @@ public abstract class DVSecondPassGroupingCollector extends Abstrac public void setNextReader(IndexReader.AtomicReaderContext readerContext) throws IOException { super.setNextReader(readerContext); - final IndexDocValues dv = readerContext.reader.docValues(groupField); - final IndexDocValues.Source dvSource; + final DocValues dv = readerContext.reader.docValues(groupField); + final DocValues.Source dvSource; if (dv != null) { dvSource = diskResident ? dv.getDirectSource() : dv.getSource(); } else { @@ -122,21 +122,21 @@ public abstract class DVSecondPassGroupingCollector extends Abstrac * @param source The idv source to be used by concrete implementations * @param readerContext The current reader context */ - protected abstract void setDocValuesSources(IndexDocValues.Source source, IndexReader.AtomicReaderContext readerContext); + protected abstract void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext); /** * @return The default source when no doc values are available. * @param readerContext The current reader context */ - protected IndexDocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { - return IndexDocValues.getDefaultSource(valueType); + protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { + return DocValues.getDefaultSource(valueType); } static class Lng extends DVSecondPassGroupingCollector { - private IndexDocValues.Source source; + private DocValues.Source source; - Lng(String groupField, ValueType valueType, boolean diskResident, Collection> searchGroups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields) throws IOException { + Lng(String groupField, DocValues.Type valueType, boolean diskResident, Collection> searchGroups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields) throws IOException { super(groupField, valueType, diskResident, searchGroups, groupSort, withinGroupSort, maxDocsPerGroup, getScores, getMaxScores, fillSortFields); } @@ -144,16 +144,16 @@ public abstract class DVSecondPassGroupingCollector extends Abstrac return groupMap.get(source.getInt(doc)); } - protected void setDocValuesSources(IndexDocValues.Source source, IndexReader.AtomicReaderContext readerContext) { + protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) { this.source = source; } } static class Dbl extends DVSecondPassGroupingCollector { - private IndexDocValues.Source source; + private DocValues.Source source; - Dbl(String groupField, ValueType valueType, boolean diskResident, Collection> searchGroups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields) throws IOException { + Dbl(String groupField, DocValues.Type valueType, boolean diskResident, Collection> searchGroups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields) throws IOException { super(groupField, valueType, diskResident, searchGroups, groupSort, withinGroupSort, maxDocsPerGroup, getScores, getMaxScores, fillSortFields); } @@ -161,17 +161,17 @@ public abstract class DVSecondPassGroupingCollector extends Abstrac return groupMap.get(source.getFloat(doc)); } - protected void setDocValuesSources(IndexDocValues.Source source, IndexReader.AtomicReaderContext readerContext) { + protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) { this.source = source; } } static class BR extends DVSecondPassGroupingCollector { - private IndexDocValues.Source source; + private DocValues.Source source; private final BytesRef spare = new BytesRef(); - BR(String groupField, ValueType valueType, boolean diskResident, Collection> searchGroups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields) throws IOException { + BR(String groupField, DocValues.Type valueType, boolean diskResident, Collection> searchGroups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields) throws IOException { super(groupField, valueType, diskResident, searchGroups, groupSort, withinGroupSort, maxDocsPerGroup, getScores, getMaxScores, fillSortFields); } @@ -180,7 +180,7 @@ public abstract class DVSecondPassGroupingCollector extends Abstrac } @Override - protected void setDocValuesSources(IndexDocValues.Source source, IndexReader.AtomicReaderContext readerContext) { + protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) { this.source = source; } @@ -188,12 +188,12 @@ public abstract class DVSecondPassGroupingCollector extends Abstrac static class SortedBR extends DVSecondPassGroupingCollector { - private IndexDocValues.SortedSource source; + private DocValues.SortedSource source; private final BytesRef spare = new BytesRef(); private final SentinelIntSet ordSet; @SuppressWarnings("unchecked") - SortedBR(String groupField, ValueType valueType, boolean diskResident, Collection> searchGroups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields) throws IOException { + SortedBR(String groupField, DocValues.Type valueType, boolean diskResident, Collection> searchGroups, Sort groupSort, Sort withinGroupSort, int maxDocsPerGroup, boolean getScores, boolean getMaxScores, boolean fillSortFields) throws IOException { super(groupField, valueType, diskResident, searchGroups, groupSort, withinGroupSort, maxDocsPerGroup, getScores, getMaxScores, fillSortFields); ordSet = new SentinelIntSet(groupMap.size(), -1); groupDocs = (SearchGroupDocs[]) new SearchGroupDocs[ordSet.keys.length]; @@ -209,7 +209,7 @@ public abstract class DVSecondPassGroupingCollector extends Abstrac } @Override - protected void setDocValuesSources(IndexDocValues.Source source, IndexReader.AtomicReaderContext readerContext) { + protected void setDocValuesSources(DocValues.Source source, IndexReader.AtomicReaderContext readerContext) { this.source = source.asSortedSource(); ordSet.clear(); @@ -222,8 +222,8 @@ public abstract class DVSecondPassGroupingCollector extends Abstrac } @Override - protected IndexDocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { - return IndexDocValues.getDefaultSortedSource(valueType, readerContext.reader.maxDoc()); + protected DocValues.Source getDefaultSource(IndexReader.AtomicReaderContext readerContext) { + return DocValues.getDefaultSortedSource(valueType, readerContext.reader.maxDoc()); } } diff --git a/modules/grouping/src/java/org/apache/lucene/search/grouping/package.html b/modules/grouping/src/java/org/apache/lucene/search/grouping/package.html index eb893c9021d..0b5d5e7f14c 100644 --- a/modules/grouping/src/java/org/apache/lucene/search/grouping/package.html +++ b/modules/grouping/src/java/org/apache/lucene/search/grouping/package.html @@ -186,14 +186,14 @@ fields, FieldCache, etc.).

- There are also IndexDocValues based implementations available for the group collectors. There are factory methods - available for creating idv based instances. A typical example using idv based grouping collectors: + There are also DocValues based implementations available for the group collectors. There are factory methods + available for creating dv based instances. A typical example using dv based grouping collectors:

   boolean diskResident = true; // Whether values should fetched directly from disk by passing the Java heap space.
   AbstractFirstPassGroupingCollector c1 = DVFirstPassGroupingCollector.create(
-        groupSort, groupOffset+topNGroups, "author", ValueType.BYTES_VAR_SORTED, diskResident
+        groupSort, groupOffset+topNGroups, "author", DocValues.Type.BYTES_VAR_SORTED, diskResident
   );
 
   s.search(new TermQuery(new Term("content", searchTerm)), c1);
@@ -209,7 +209,7 @@ fields, FieldCache, etc.).
   boolean getMaxScores = true;
   boolean fillFields = true;
   AbstractSecondPassGroupingCollector<BytesRef> c2 = DVSecondPassGroupingCollector.create(
-        "author", diskResident, ValueType.BYTES_VAR_SORTED, topGroups, groupSort, docSort,
+        "author", diskResident, DocValues.Type.BYTES_VAR_SORTED, topGroups, groupSort, docSort,
         docOffset+docsPerGroup, getScores, getMaxScores, fillFields
   );
 
diff --git a/modules/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java b/modules/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java
index cbb6f6ba9c2..362a3422807 100644
--- a/modules/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java
+++ b/modules/grouping/src/test/org/apache/lucene/search/grouping/AllGroupHeadsCollectorTest.java
@@ -23,7 +23,7 @@ import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.SlowMultiReaderWrapper;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.index.values.ValueType;
+import org.apache.lucene.index.DocValues.Type;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
 import org.apache.lucene.search.*;
@@ -41,8 +41,8 @@ import java.util.*;
 
 public class AllGroupHeadsCollectorTest extends LuceneTestCase {
 
-  private static final ValueType[] vts = new ValueType[]{
-      ValueType.BYTES_VAR_DEREF, ValueType.BYTES_VAR_STRAIGHT, ValueType.BYTES_VAR_SORTED
+  private static final Type[] vts = new Type[]{
+      Type.BYTES_VAR_DEREF, Type.BYTES_VAR_STRAIGHT, Type.BYTES_VAR_SORTED
   };
 
   public void testBasic() throws Exception {
@@ -54,7 +54,7 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
         newIndexWriterConfig(TEST_VERSION_CURRENT,
             new MockAnalyzer(random)).setMergePolicy(newLogMergePolicy()));
     boolean canUseIDV = !"Lucene3x".equals(w.w.getConfig().getCodec().getName());
-    ValueType valueType = vts[random.nextInt(vts.length)];
+    Type valueType = vts[random.nextInt(vts.length)];
 
     // 0
     Document doc = new Document();
@@ -203,15 +203,15 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
               new MockAnalyzer(random)));
       boolean preFlex = "Lucene3x".equals(w.w.getConfig().getCodec().getName());
       boolean canUseIDV = !preFlex;
-      ValueType valueType = vts[random.nextInt(vts.length)];
+      Type valueType = vts[random.nextInt(vts.length)];
 
       Document doc = new Document();
       Document docNoGroup = new Document();
       Field group = newField("group", "", StringField.TYPE_UNSTORED);
       doc.add(group);
-      IndexDocValuesField valuesField = null;
+      DocValuesField valuesField = null;
       if (canUseIDV) {
-        valuesField = new IndexDocValuesField("group");
+        valuesField = new DocValuesField("group");
         doc.add(valuesField);
       }
       Field sort1 = newField("sort1", "", StringField.TYPE_UNSTORED);
@@ -506,7 +506,7 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
     };
   }
 
-  private AbstractAllGroupHeadsCollector createRandomCollector(String groupField, Sort sortWithinGroup, boolean canUseIDV, ValueType valueType) throws IOException {
+  private AbstractAllGroupHeadsCollector createRandomCollector(String groupField, Sort sortWithinGroup, boolean canUseIDV, Type valueType) throws IOException {
     AbstractAllGroupHeadsCollector collector;
     if (random.nextBoolean()) {
       ValueSource vs = new BytesRefFieldSource(groupField);
@@ -525,10 +525,10 @@ public class AllGroupHeadsCollectorTest extends LuceneTestCase {
     return collector;
   }
 
-  private void addGroupField(Document doc, String groupField, String value, boolean canUseIDV, ValueType valueType) {
+  private void addGroupField(Document doc, String groupField, String value, boolean canUseIDV, Type valueType) {
     doc.add(new Field(groupField, value, TextField.TYPE_STORED));
     if (canUseIDV) {
-      IndexDocValuesField valuesField = new IndexDocValuesField(groupField);
+      DocValuesField valuesField = new DocValuesField(groupField);
       valuesField.setBytes(new BytesRef(value), valueType);
       doc.add(valuesField);
     }
diff --git a/modules/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java b/modules/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java
index bf740885690..adb3cfcbc9e 100644
--- a/modules/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java
+++ b/modules/grouping/src/test/org/apache/lucene/search/grouping/AllGroupsCollectorTest.java
@@ -21,7 +21,7 @@ import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.*;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.index.values.ValueType;
+import org.apache.lucene.index.DocValues.Type;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
 import org.apache.lucene.search.IndexSearcher;
@@ -123,8 +123,8 @@ public class AllGroupsCollectorTest extends LuceneTestCase {
   private void addGroupField(Document doc, String groupField, String value, boolean canUseIDV) {
     doc.add(new Field(groupField, value, TextField.TYPE_STORED));
     if (canUseIDV) {
-      IndexDocValuesField valuesField = new IndexDocValuesField(groupField);
-      valuesField.setBytes(new BytesRef(value), ValueType.BYTES_VAR_SORTED);
+      DocValuesField valuesField = new DocValuesField(groupField);
+      valuesField.setBytes(new BytesRef(value), Type.BYTES_VAR_SORTED);
       doc.add(valuesField);
     }
   }
@@ -133,7 +133,7 @@ public class AllGroupsCollectorTest extends LuceneTestCase {
     AbstractAllGroupsCollector selected;
     if (random.nextBoolean() && canUseIDV) {
       boolean diskResident = random.nextBoolean();
-      selected = DVAllGroupsCollector.create(groupField, ValueType.BYTES_VAR_SORTED, diskResident);
+      selected = DVAllGroupsCollector.create(groupField, Type.BYTES_VAR_SORTED, diskResident);
     } else if (random.nextBoolean()) {
       selected = new TermAllGroupsCollector(groupField);
     } else {
diff --git a/modules/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java b/modules/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
index 216eea907d9..1aa8b2a27aa 100644
--- a/modules/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
+++ b/modules/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
@@ -24,7 +24,7 @@ import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.SlowMultiReaderWrapper;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.index.values.ValueType;
+import org.apache.lucene.index.DocValues.Type;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.queries.function.valuesource.BytesRefFieldSource;
 import org.apache.lucene.search.*;
@@ -171,8 +171,8 @@ public class TestGrouping extends LuceneTestCase {
   private void addGroupField(Document doc, String groupField, String value, boolean canUseIDV) {
     doc.add(new Field(groupField, value, TextField.TYPE_STORED));
     if (canUseIDV) {
-      IndexDocValuesField valuesField = new IndexDocValuesField(groupField);
-      valuesField.setBytes(new BytesRef(value), ValueType.BYTES_VAR_SORTED);
+      DocValuesField valuesField = new DocValuesField(groupField);
+      valuesField.setBytes(new BytesRef(value), Type.BYTES_VAR_SORTED);
       doc.add(valuesField);
     }
   }
@@ -181,7 +181,7 @@ public class TestGrouping extends LuceneTestCase {
     AbstractFirstPassGroupingCollector selected;
     if (canUseIDV && random.nextBoolean()) {
       boolean diskResident = random.nextBoolean();
-      selected = DVFirstPassGroupingCollector.create(groupSort, topDocs, groupField, ValueType.BYTES_VAR_SORTED, diskResident);
+      selected = DVFirstPassGroupingCollector.create(groupSort, topDocs, groupField, Type.BYTES_VAR_SORTED, diskResident);
     } else if (random.nextBoolean()) {
       ValueSource vs = new BytesRefFieldSource(groupField);
       selected = new FunctionFirstPassGroupingCollector(vs, new HashMap(), groupSort, topDocs);
@@ -197,7 +197,7 @@ public class TestGrouping extends LuceneTestCase {
   private AbstractFirstPassGroupingCollector createFirstPassCollector(String groupField, Sort groupSort, int topDocs, AbstractFirstPassGroupingCollector firstPassGroupingCollector) throws IOException {
     if (DVFirstPassGroupingCollector.class.isAssignableFrom(firstPassGroupingCollector.getClass())) {
       boolean diskResident = random.nextBoolean();
-      return DVFirstPassGroupingCollector.create(groupSort, topDocs, groupField, ValueType.BYTES_VAR_SORTED, diskResident);
+      return DVFirstPassGroupingCollector.create(groupSort, topDocs, groupField, Type.BYTES_VAR_SORTED, diskResident);
     } else if (TermFirstPassGroupingCollector.class.isAssignableFrom(firstPassGroupingCollector.getClass())) {
       ValueSource vs = new BytesRefFieldSource(groupField);
       return new FunctionFirstPassGroupingCollector(vs, new HashMap(), groupSort, topDocs);
@@ -220,7 +220,7 @@ public class TestGrouping extends LuceneTestCase {
     if (DVFirstPassGroupingCollector.class.isAssignableFrom(firstPassGroupingCollector.getClass())) {
       boolean diskResident = random.nextBoolean();
       Collection searchGroups = firstPassGroupingCollector.getTopGroups(groupOffset, fillSortFields);
-      return DVSecondPassGroupingCollector.create(groupField, diskResident, ValueType.BYTES_VAR_SORTED, searchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields);
+      return DVSecondPassGroupingCollector.create(groupField, diskResident, Type.BYTES_VAR_SORTED, searchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields);
     } else if (TermFirstPassGroupingCollector.class.isAssignableFrom(firstPassGroupingCollector.getClass())) {
       Collection> searchGroups = firstPassGroupingCollector.getTopGroups(groupOffset, fillSortFields);
       return new TermSecondPassGroupingCollector(groupField, searchGroups, groupSort, sortWithinGroup, maxDocsPerGroup , getScores, getMaxScores, fillSortFields);
@@ -244,7 +244,7 @@ public class TestGrouping extends LuceneTestCase {
                                                                         boolean fillSortFields) throws IOException {
     if (DVFirstPassGroupingCollector.class.isAssignableFrom(firstPassGroupingCollector.getClass())) {
       boolean diskResident = random.nextBoolean();
-      return DVSecondPassGroupingCollector.create(groupField, diskResident, ValueType.BYTES_VAR_SORTED, (Collection) searchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields);
+      return DVSecondPassGroupingCollector.create(groupField, diskResident, Type.BYTES_VAR_SORTED, (Collection) searchGroups, groupSort, sortWithinGroup, maxDocsPerGroup, getScores, getMaxScores, fillSortFields);
     } else if (firstPassGroupingCollector.getClass().isAssignableFrom(TermFirstPassGroupingCollector.class)) {
       return new TermSecondPassGroupingCollector(groupField, searchGroups, groupSort, sortWithinGroup, maxDocsPerGroup , getScores, getMaxScores, fillSortFields);
     } else {
@@ -274,7 +274,7 @@ public class TestGrouping extends LuceneTestCase {
       return new TermAllGroupsCollector(groupField);
     } else if (firstPassGroupingCollector.getClass().isAssignableFrom(DVFirstPassGroupingCollector.class)) {
       boolean diskResident = random.nextBoolean();
-      return DVAllGroupsCollector.create(groupField, ValueType.BYTES_VAR_SORTED, diskResident);
+      return DVAllGroupsCollector.create(groupField, Type.BYTES_VAR_SORTED, diskResident);
     } else {
       ValueSource vs = new BytesRefFieldSource(groupField);
       return new FunctionAllGroupsCollector(vs, new HashMap());
@@ -705,7 +705,7 @@ public class TestGrouping extends LuceneTestCase {
 
       Document doc = new Document();
       Document docNoGroup = new Document();
-      IndexDocValuesField idvGroupField = new IndexDocValuesField("group");
+      DocValuesField idvGroupField = new DocValuesField("group");
       if (canUseIDV) {
         doc.add(idvGroupField);
       }
@@ -747,7 +747,7 @@ public class TestGrouping extends LuceneTestCase {
         if (groupDoc.group != null) {
           group.setValue(groupDoc.group.utf8ToString());
           if (canUseIDV) {
-            idvGroupField.setBytes(BytesRef.deepCopyOf(groupDoc.group), ValueType.BYTES_VAR_SORTED);
+            idvGroupField.setBytes(BytesRef.deepCopyOf(groupDoc.group), Type.BYTES_VAR_SORTED);
           }
         }
         sort1.setValue(groupDoc.sort1.utf8ToString());
diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericIndexDocValueSource.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericIndexDocValueSource.java
index d1135f6be87..2c95813dfca 100644
--- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericIndexDocValueSource.java
+++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericIndexDocValueSource.java
@@ -19,16 +19,16 @@ package org.apache.lucene.queries.function.valuesource;
 import java.io.IOException;
 import java.util.Map;
 
+import org.apache.lucene.index.DocValues.Source;
+import org.apache.lucene.index.DocValues.Type;
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
-import org.apache.lucene.index.values.IndexDocValues;
-import org.apache.lucene.index.values.ValueType;
 import org.apache.lucene.queries.function.DocValues;
 import org.apache.lucene.queries.function.ValueSource;
 
 /**
- * Expert: obtains numeric field values from a {@link IndexDocValues} field.
+ * Expert: obtains numeric field values from a {@link DocValues} field.
  * This {@link ValueSource} is compatible with all numerical
- * {@link IndexDocValues}
+ * {@link DocValues}
  * 
  * @lucene.experimental
  * 
@@ -43,9 +43,9 @@ public class NumericIndexDocValueSource extends ValueSource {
 
   @Override
   public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException {
-    final IndexDocValues.Source source = readerContext.reader.docValues(field)
+    final Source source = readerContext.reader.docValues(field)
         .getSource();
-    ValueType type = source.type();
+    Type type = source.type();
     switch (type) {
     case FLOAT_32:
     case FLOAT_64:

From 75d62170915a92672bc7df625f7d7043c94b12a6 Mon Sep 17 00:00:00 2001
From: Robert Muir 
Date: Sat, 10 Dec 2011 17:43:00 +0000
Subject: [PATCH 13/19] LUCENE-3622: PerDocValues -> PerDocProducer (privately
 used only by SegmentCoreReaders), simplify IR API and MultiDocValues, remove
 MultiPerDocValues

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1212828 13f79535-47bb-0310-9956-ffa450edef68
---
 .../lucene/index/memory/MemoryIndex.java      |   4 +-
 .../org/apache/lucene/index/CheckIndex.java   |   5 +-
 .../apache/lucene/index/DirectoryReader.java  |   7 +-
 .../lucene/index/FilterIndexReader.java       |   4 +-
 .../org/apache/lucene/index/IndexReader.java  |  52 ++-----
 .../apache/lucene/index/MultiDocValues.java   | 130 ++++++++++------
 .../apache/lucene/index/MultiFieldsEnum.java  |   9 --
 .../lucene/index/MultiPerDocValues.java       | 147 ------------------
 .../org/apache/lucene/index/MultiReader.java  |   5 +-
 .../apache/lucene/index/ParallelReader.java   |  35 +----
 .../lucene/index/SegmentCoreReaders.java      |   3 +-
 .../apache/lucene/index/SegmentReader.java    |   9 +-
 .../lucene/index/SlowMultiReaderWrapper.java  |  11 +-
 .../lucene/index/codecs/DocValuesFormat.java  |   3 +-
 .../index/codecs/DocValuesReaderBase.java     |   5 +-
 .../lucene/index/codecs/PerDocConsumer.java   |  17 +-
 .../PerDocProducer.java}                      |  11 +-
 .../index/codecs/lucene3x/Lucene3xCodec.java  |   4 +-
 .../lucene40/Lucene40DocValuesFormat.java     |   4 +-
 .../lucene40/Lucene40DocValuesProducer.java   |   2 +-
 .../codecs/sep/SepDocValuesProducer.java      |   2 +-
 .../mocksep/MockSepDocValuesFormat.java       |   4 +-
 .../apache/lucene/index/TestAddIndexes.java   |   2 +-
 .../lucene/index/TestDuelingCodecs.java       |  35 ++---
 .../index/values/TestDocValuesIndexing.java   |  30 +---
 25 files changed, 167 insertions(+), 373 deletions(-)
 delete mode 100644 lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java
 rename lucene/src/java/org/apache/lucene/index/{PerDocValues.java => codecs/PerDocProducer.java} (83%)

diff --git a/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java b/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
index 6f1869329ed..c38a9b7f52d 100644
--- a/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
+++ b/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
@@ -40,8 +40,8 @@ import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.FieldInvertState;
 import org.apache.lucene.index.Fields;
 import org.apache.lucene.index.FieldsEnum;
-import org.apache.lucene.index.PerDocValues;
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
+import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.OrdTermState;
 import org.apache.lucene.index.StoredFieldVisitor;
@@ -1159,7 +1159,7 @@ public class MemoryIndex {
     }
 
     @Override
-    public PerDocValues perDocValues() throws IOException {
+    public DocValues docValues(String field) throws IOException {
       return null;
     }
   }
diff --git a/lucene/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/src/java/org/apache/lucene/index/CheckIndex.java
index 2e6c7002396..6be57d5c09a 100644
--- a/lucene/src/java/org/apache/lucene/index/CheckIndex.java
+++ b/lucene/src/java/org/apache/lucene/index/CheckIndex.java
@@ -27,6 +27,8 @@ import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.DocValues.Source;
 import org.apache.lucene.index.codecs.Codec;
+import org.apache.lucene.index.codecs.PerDocProducer;
+
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
@@ -1130,8 +1132,7 @@ public class CheckIndex {
       for (FieldInfo fieldInfo : fieldInfos) {
         if (fieldInfo.hasDocValues()) {
           status.totalValueFields++;
-          final PerDocValues perDocValues = reader.perDocValues();
-          final DocValues docValues = perDocValues.docValues(fieldInfo.name);
+          final DocValues docValues = reader.docValues(fieldInfo.name);
           if (docValues == null) {
             continue;
           }
diff --git a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
index e1468b75624..64c02c837b4 100644
--- a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
+++ b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
@@ -31,11 +31,8 @@ import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.IOContext;
-import org.apache.lucene.store.Lock;
-import org.apache.lucene.store.LockObtainFailedException;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.InfoStream;
 import org.apache.lucene.util.MapBackedSet;
 
 /** 
@@ -716,7 +713,7 @@ class DirectoryReader extends IndexReader implements Cloneable {
   }
 
   @Override
-  public PerDocValues perDocValues() throws IOException {
-    throw new UnsupportedOperationException("please use MultiPerDocValues#getPerDocs, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level Fields");
+  public DocValues docValues(String field) throws IOException {
+    throw new UnsupportedOperationException("please use MultiDocValues#getDocValues, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level DocValues");
   }
 }
diff --git a/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java b/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java
index 3c64cbeccd7..cdeb70c91fa 100644
--- a/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java
+++ b/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java
@@ -421,9 +421,9 @@ public class FilterIndexReader extends IndexReader {
   }
 
   @Override
-  public PerDocValues perDocValues() throws IOException {
+  public DocValues docValues(String field) throws IOException {
     ensureOpen();
-    return in.perDocValues();
+    return in.docValues(field);
   }
 
   @Override
diff --git a/lucene/src/java/org/apache/lucene/index/IndexReader.java b/lucene/src/java/org/apache/lucene/index/IndexReader.java
index 592e66dd09e..edc2142927c 100644
--- a/lucene/src/java/org/apache/lucene/index/IndexReader.java
+++ b/lucene/src/java/org/apache/lucene/index/IndexReader.java
@@ -773,21 +773,6 @@ public abstract class IndexReader implements Cloneable,Closeable {
    * through them yourself. */
   public abstract Fields fields() throws IOException;
   
-  /**
-   * Returns {@link PerDocValues} for this reader.
-   * This method may return null if the reader has no per-document
-   * values stored.
-   *
-   * 

NOTE: if this is a multi reader ({@link - * #getSequentialSubReaders} is not null) then this - * method will throw UnsupportedOperationException. If - * you really need {@link PerDocValues} for such a reader, - * use {@link MultiPerDocValues#getPerDocs(IndexReader)}. However, for - * performance reasons, it's best to get all sub-readers - * using {@link ReaderUtil#gatherSubReaders} and iterate - * through them yourself. */ - public abstract PerDocValues perDocValues() throws IOException; - public final int docFreq(Term term) throws IOException { return docFreq(term.field(), term.bytes()); } @@ -1146,14 +1131,20 @@ public abstract class IndexReader implements Cloneable,Closeable { throw new UnsupportedOperationException("This reader does not support this method."); } - public final DocValues docValues(String field) throws IOException { - ensureOpen(); - final PerDocValues perDoc = perDocValues(); - if (perDoc == null) { - return null; - } - return perDoc.docValues(field); - } + /** + * Returns {@link DocValues} for this field. + * This method may return null if the reader has no per-document + * values stored. + * + *

NOTE: if this is a multi reader ({@link + * #getSequentialSubReaders} is not null) then this + * method will throw UnsupportedOperationException. If + * you really need {@link DocValues} for such a reader, + * use {@link MultiDocValues#getDocValues(IndexReader,String)}. However, for + * performance reasons, it's best to get all sub-readers + * using {@link ReaderUtil#gatherSubReaders} and iterate + * through them yourself. */ + public abstract DocValues docValues(String field) throws IOException; private volatile Fields fields; @@ -1169,21 +1160,6 @@ public abstract class IndexReader implements Cloneable,Closeable { return fields; } - private volatile PerDocValues perDocValues; - - /** @lucene.internal */ - void storePerDoc(PerDocValues perDocValues) { - ensureOpen(); - this.perDocValues = perDocValues; - } - - /** @lucene.internal */ - PerDocValues retrievePerDoc() { - ensureOpen(); - return perDocValues; - } - - /** * A struct like class that represents a hierarchical relationship between * {@link IndexReader} instances. diff --git a/lucene/src/java/org/apache/lucene/index/MultiDocValues.java b/lucene/src/java/org/apache/lucene/index/MultiDocValues.java index 529058e8362..9f1d16fa2a5 100644 --- a/lucene/src/java/org/apache/lucene/index/MultiDocValues.java +++ b/lucene/src/java/org/apache/lucene/index/MultiDocValues.java @@ -17,10 +17,13 @@ package org.apache.lucene.index; * limitations under the License. */ import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.ReaderUtil; +import org.apache.lucene.util.ReaderUtil.Gather; /** * A wrapper for compound IndexReader providing access to per segment @@ -31,59 +34,92 @@ import org.apache.lucene.util.ReaderUtil; */ public class MultiDocValues extends DocValues { - public static class DocValuesIndex { - public final static DocValuesIndex[] EMPTY_ARRAY = new DocValuesIndex[0]; + public static class DocValuesSlice { + public final static DocValuesSlice[] EMPTY_ARRAY = new DocValuesSlice[0]; final int start; final int length; - final DocValues docValues; + DocValues docValues; - public DocValuesIndex(DocValues docValues, int start, int length) { + public DocValuesSlice(DocValues docValues, int start, int length) { this.docValues = docValues; this.start = start; this.length = length; } } - private DocValuesIndex[] docValuesIdx; + private DocValuesSlice[] slices; private int[] starts; private Type type; private int valueSize; - public MultiDocValues() { - starts = new int[0]; - docValuesIdx = new DocValuesIndex[0]; + private MultiDocValues(DocValuesSlice[] slices, int[] starts, TypePromoter promotedType) { + this.starts = starts; + this.slices = slices; + this.type = promotedType.type(); + this.valueSize = promotedType.getValueSize(); } - - public MultiDocValues(DocValuesIndex[] docValuesIdx) { - reset(docValuesIdx); + + /** + * Returns a single {@link DocValues} instance for this field, merging + * their values on the fly. + * + *

+ * NOTE: this is a slow way to access DocValues. It's better to get the + * sub-readers (using {@link Gather}) and iterate through them yourself. + */ + public static DocValues getDocValues(IndexReader r, final String field) throws IOException { + final IndexReader[] subs = r.getSequentialSubReaders(); + if (subs == null) { + // already an atomic reader + return r.docValues(field); + } else if (subs.length == 0) { + // no fields + return null; + } else if (subs.length == 1) { + return getDocValues(subs[0], field); + } else { + final List slices = new ArrayList(); + + final TypePromoter promotedType[] = new TypePromoter[1]; + promotedType[0] = TypePromoter.getIdentityPromoter(); + + // gather all docvalues fields, accumulating a promoted type across + // potentially incompatible types + + new ReaderUtil.Gather(r) { + @Override + protected void add(int base, IndexReader r) throws IOException { + final DocValues d = r.docValues(field); + if (d != null) { + TypePromoter incoming = TypePromoter.create(d.type(), d.getValueSize()); + promotedType[0] = promotedType[0].promote(incoming); + } + slices.add(new DocValuesSlice(d, base, r.maxDoc())); + } + }.run(); + + // return null if no docvalues encountered anywhere + if (promotedType[0] == TypePromoter.getIdentityPromoter()) { + return null; + } + + // populate starts and fill gaps with empty docvalues + int starts[] = new int[slices.size()]; + for (int i = 0; i < slices.size(); i++) { + DocValuesSlice slice = slices.get(i); + starts[i] = slice.start; + if (slice.docValues == null) { + slice.docValues = new EmptyDocValues(slice.length, promotedType[0].type()); + } + } + + return new MultiDocValues(slices.toArray(new DocValuesSlice[slices.size()]), starts, promotedType[0]); + } } @Override public Source load() throws IOException { - return new MultiSource(docValuesIdx, starts, false); - } - - public DocValues reset(DocValuesIndex[] docValuesIdx) { - final int[] start = new int[docValuesIdx.length]; - TypePromoter promoter = TypePromoter.getIdentityPromoter(); - for (int i = 0; i < docValuesIdx.length; i++) { - start[i] = docValuesIdx[i].start; - if (!(docValuesIdx[i].docValues instanceof EmptyDocValues)) { - // only promote if not a dummy - final TypePromoter incomingPromoter = TypePromoter.create( - docValuesIdx[i].docValues.type(), - docValuesIdx[i].docValues.getValueSize()); - promoter = promoter.promote(incomingPromoter); - if (promoter == null) { - throw new IllegalStateException("Can not promote " + incomingPromoter); - } - } - } - this.type = promoter.type(); - this.valueSize = promoter.getValueSize(); - this.starts = start; - this.docValuesIdx = docValuesIdx; - return this; + return new MultiSource(slices, starts, false, type); } public static class EmptyDocValues extends DocValues { @@ -117,14 +153,14 @@ public class MultiDocValues extends DocValues { private int start = 0; private Source current; private final int[] starts; - private final DocValuesIndex[] docValuesIdx; + private final DocValuesSlice[] slices; private boolean direct; - public MultiSource(DocValuesIndex[] docValuesIdx, int[] starts, boolean direct) { - super(docValuesIdx[0].docValues.type()); - this.docValuesIdx = docValuesIdx; + public MultiSource(DocValuesSlice[] slices, int[] starts, boolean direct, Type type) { + super(type); + this.slices = slices; this.starts = starts; - assert docValuesIdx.length != 0; + assert slices.length != 0; this.direct = direct; } @@ -138,22 +174,22 @@ public class MultiDocValues extends DocValues { return docID - start; } else { final int idx = ReaderUtil.subIndex(docID, starts); - assert idx >= 0 && idx < docValuesIdx.length : "idx was " + idx + assert idx >= 0 && idx < slices.length : "idx was " + idx + " for doc id: " + docID + " slices : " + Arrays.toString(starts); - assert docValuesIdx[idx] != null; + assert slices[idx] != null; try { if (direct) { - current = docValuesIdx[idx].docValues.getDirectSource(); + current = slices[idx].docValues.getDirectSource(); } else { - current = docValuesIdx[idx].docValues.getSource(); + current = slices[idx].docValues.getSource(); } } catch (IOException e) { throw new RuntimeException("load failed", e); // TODO how should we // handle this } - start = docValuesIdx[idx].start; - numDocs = docValuesIdx[idx].length; + start = slices[idx].start; + numDocs = slices[idx].length; return docID - start; } } @@ -206,6 +242,6 @@ public class MultiDocValues extends DocValues { @Override public Source getDirectSource() throws IOException { - return new MultiSource(docValuesIdx, starts, true); + return new MultiSource(slices, starts, true, type); } } diff --git a/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java b/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java index 2411f5dca63..7db5f02fac5 100644 --- a/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java +++ b/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java @@ -38,14 +38,9 @@ public final class MultiFieldsEnum extends FieldsEnum { // Holds sub-readers containing field we are currently // on, popped from queue. private final FieldsEnumWithSlice[] top; - private final FieldsEnumWithSlice[] enumWithSlices; private int numTop; - // Re-used TermsEnum - private final MultiTermsEnum terms; - private final MultiDocValues docValues; - private final Fields fields; private String currentField; @@ -54,9 +49,7 @@ public final class MultiFieldsEnum extends FieldsEnum { * (ie, {@link FieldsEnum#next} has not been called. */ public MultiFieldsEnum(MultiFields fields, FieldsEnum[] subs, ReaderUtil.Slice[] subSlices) throws IOException { this.fields = fields; - terms = new MultiTermsEnum(subSlices); queue = new FieldMergeQueue(subs.length); - docValues = new MultiDocValues(); top = new FieldsEnumWithSlice[subs.length]; List enumWithSlices = new ArrayList(); @@ -72,8 +65,6 @@ public final class MultiFieldsEnum extends FieldsEnum { queue.add(sub); } } - this.enumWithSlices = enumWithSlices.toArray(FieldsEnumWithSlice.EMPTY_ARRAY); - } @Override diff --git a/lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java b/lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java deleted file mode 100644 index 8f7a6a7d9e7..00000000000 --- a/lucene/src/java/org/apache/lucene/index/MultiPerDocValues.java +++ /dev/null @@ -1,147 +0,0 @@ -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. - */ -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.lucene.index.MultiDocValues.DocValuesIndex; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.util.IOUtils; -import org.apache.lucene.util.ReaderUtil; -import org.apache.lucene.util.ReaderUtil.Gather; - -/** - * Exposes per-document values, merged from per-document values API of - * sub-segments. This is useful when you're interacting with an {@link IndexReader} - * implementation that consists of sequential sub-readers (eg DirectoryReader - * or {@link MultiReader}). - * - *

- * NOTE: for multi readers, you'll get better performance by gathering - * the sub readers using {@link ReaderUtil#gatherSubReaders} and then operate - * per-reader, instead of using this class. - * - * @lucene.experimental - */ -public class MultiPerDocValues extends PerDocValues { - private final PerDocValues[] subs; - private final ReaderUtil.Slice[] subSlices; - private final Map docValues = new ConcurrentHashMap(); - - public MultiPerDocValues(PerDocValues[] subs, ReaderUtil.Slice[] subSlices) { - this.subs = subs; - this.subSlices = subSlices; - } - - /** - * Returns a single {@link PerDocValues} instance for this reader, merging - * their values on the fly. This method will not return null. - * - *

- * NOTE: this is a slow way to access postings. It's better to get the - * sub-readers (using {@link Gather}) and iterate through them yourself. - */ - public static PerDocValues getPerDocs(IndexReader r) throws IOException { - final IndexReader[] subs = r.getSequentialSubReaders(); - if (subs == null) { - // already an atomic reader - return r.perDocValues(); - } else if (subs.length == 0) { - // no fields - return null; - } else if (subs.length == 1) { - return getPerDocs(subs[0]); - } - PerDocValues perDocValues = r.retrievePerDoc(); - if (perDocValues == null) { - - final List producer = new ArrayList(); - final List slices = new ArrayList(); - - new ReaderUtil.Gather(r) { - @Override - protected void add(int base, IndexReader r) throws IOException { - final PerDocValues f = r.perDocValues(); - if (f != null) { - producer.add(f); - slices - .add(new ReaderUtil.Slice(base, r.maxDoc(), producer.size() - 1)); - } - } - }.run(); - - if (producer.size() == 0) { - return null; - } else if (producer.size() == 1) { - perDocValues = producer.get(0); - } else { - perDocValues = new MultiPerDocValues( - producer.toArray(PerDocValues.EMPTY_ARRAY), - slices.toArray(ReaderUtil.Slice.EMPTY_ARRAY)); - } - r.storePerDoc(perDocValues); - } - return perDocValues; - } - - public DocValues docValues(String field) throws IOException { - DocValues result = docValues.get(field); - if (result == null) { - // Lazy init: first time this field is requested, we - // create & add to docValues: - final List docValuesIndex = new ArrayList(); - int docsUpto = 0; - DocValues.Type type = null; - // Gather all sub-readers that share this field - for (int i = 0; i < subs.length; i++) { - DocValues values = subs[i].docValues(field); - final int start = subSlices[i].start; - final int length = subSlices[i].length; - if (values != null) { - if (docsUpto != start) { - type = values.type(); - docValuesIndex.add(new MultiDocValues.DocValuesIndex( - new MultiDocValues.EmptyDocValues(start, type), docsUpto, start - - docsUpto)); - } - docValuesIndex.add(new MultiDocValues.DocValuesIndex(values, start, - length)); - docsUpto = start + length; - - } else if (i + 1 == subs.length && !docValuesIndex.isEmpty()) { - docValuesIndex.add(new MultiDocValues.DocValuesIndex( - new MultiDocValues.EmptyDocValues(start, type), docsUpto, start - - docsUpto)); - } - } - if (docValuesIndex.isEmpty()) { - return null; - } - result = new MultiDocValues( - docValuesIndex.toArray(DocValuesIndex.EMPTY_ARRAY)); - docValues.put(field, result); - } - return result; - } - - public void close() throws IOException { - IOUtils.close(this.subs); - } -} diff --git a/lucene/src/java/org/apache/lucene/index/MultiReader.java b/lucene/src/java/org/apache/lucene/index/MultiReader.java index 6eb41266918..21d075ee8cd 100644 --- a/lucene/src/java/org/apache/lucene/index/MultiReader.java +++ b/lucene/src/java/org/apache/lucene/index/MultiReader.java @@ -22,6 +22,7 @@ import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.apache.lucene.index.codecs.PerDocProducer; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.ReaderUtil; @@ -330,7 +331,7 @@ public class MultiReader extends IndexReader implements Cloneable { } @Override - public PerDocValues perDocValues() throws IOException { - throw new UnsupportedOperationException("please use MultiPerDocValues#getPerDocs, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level Fields"); + public DocValues docValues(String field) throws IOException { + throw new UnsupportedOperationException("please use MultiDocValues#getDocValues, or wrap your IndexReader with SlowMultiReaderWrapper, if you really need a top level DocValues"); } } diff --git a/lucene/src/java/org/apache/lucene/index/ParallelReader.java b/lucene/src/java/org/apache/lucene/index/ParallelReader.java index 6b3d9eaf9f8..6582b65b4bd 100644 --- a/lucene/src/java/org/apache/lucene/index/ParallelReader.java +++ b/lucene/src/java/org/apache/lucene/index/ParallelReader.java @@ -57,7 +57,6 @@ public class ParallelReader extends IndexReader { private boolean hasDeletions; private final ParallelFields fields = new ParallelFields(); - private final ParallelPerDocs perDocs = new ParallelPerDocs(); /** Construct a ParallelReader. *

Note that all subreaders are closed if this ParallelReader is closed.

@@ -130,7 +129,6 @@ public class ParallelReader extends IndexReader { if (fieldToReader.get(field) == null) { fieldToReader.put(field, reader); this.fields.addField(field, MultiFields.getFields(reader).terms(field)); - this.perDocs.addField(field, reader); } } @@ -463,35 +461,8 @@ public class ParallelReader extends IndexReader { } @Override - public PerDocValues perDocValues() throws IOException { - ensureOpen(); - return perDocs; - } - - // Single instance of this, per ParallelReader instance - private static final class ParallelPerDocs extends PerDocValues { - final TreeMap fields = new TreeMap(); - - void addField(String field, IndexReader r) throws IOException { - PerDocValues perDocs = MultiPerDocValues.getPerDocs(r); - if (perDocs != null) { - fields.put(field, perDocs.docValues(field)); - } - } - - @Override - public void close() throws IOException { - // nothing to do here - } - - @Override - public DocValues docValues(String field) throws IOException { - return fields.get(field); - } + public DocValues docValues(String field) throws IOException { + IndexReader reader = fieldToReader.get(field); + return reader == null ? null : reader.docValues(field); } } - - - - - diff --git a/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java b/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java index 65755b43a28..6f6d7d1cf88 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentCoreReaders.java @@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.NormsReader; +import org.apache.lucene.index.codecs.PerDocProducer; import org.apache.lucene.index.codecs.PostingsFormat; import org.apache.lucene.index.codecs.FieldsProducer; import org.apache.lucene.index.codecs.StoredFieldsReader; @@ -47,7 +48,7 @@ final class SegmentCoreReaders { final FieldInfos fieldInfos; final FieldsProducer fields; - final PerDocValues perDocProducer; + final PerDocProducer perDocProducer; final NormsReader norms; final Directory dir; diff --git a/lucene/src/java/org/apache/lucene/index/SegmentReader.java b/lucene/src/java/org/apache/lucene/index/SegmentReader.java index 7eb54687616..2b26fc6f57a 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentReader.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentReader.java @@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.store.Directory; import org.apache.lucene.index.FieldInfo.IndexOptions; +import org.apache.lucene.index.codecs.PerDocProducer; import org.apache.lucene.index.codecs.StoredFieldsReader; import org.apache.lucene.index.codecs.TermVectorsReader; import org.apache.lucene.store.IOContext; @@ -424,9 +425,13 @@ public final class SegmentReader extends IndexReader implements Cloneable { } @Override - public PerDocValues perDocValues() throws IOException { + public DocValues docValues(String field) throws IOException { ensureOpen(); - return core.perDocProducer; + final PerDocProducer perDoc = core.perDocProducer; + if (perDoc == null) { + return null; + } + return perDoc.docValues(field); } /** diff --git a/lucene/src/java/org/apache/lucene/index/SlowMultiReaderWrapper.java b/lucene/src/java/org/apache/lucene/index/SlowMultiReaderWrapper.java index f945f5e4976..1d021db3579 100644 --- a/lucene/src/java/org/apache/lucene/index/SlowMultiReaderWrapper.java +++ b/lucene/src/java/org/apache/lucene/index/SlowMultiReaderWrapper.java @@ -34,11 +34,12 @@ import org.apache.lucene.index.MultiReader; // javadoc * IndexReader#getSequentialSubReaders}) to emulate an * atomic reader. This requires implementing the postings * APIs on-the-fly, using the static methods in {@link - * MultiFields}, by stepping through the sub-readers to - * merge fields/terms, appending docs, etc. + * MultiFields}, {@link MultiNorms}, {@link MultiDocValues}, + * by stepping through the sub-readers to merge fields/terms, + * appending docs, etc. * *

If you ever hit an UnsupportedOperationException saying - * "please use MultiFields.XXX instead", the simple + * "please use MultiXXX.YYY instead", the simple * but non-performant workaround is to wrap your reader * using this class.

* @@ -71,9 +72,9 @@ public final class SlowMultiReaderWrapper extends FilterIndexReader { } @Override - public PerDocValues perDocValues() throws IOException { + public DocValues docValues(String field) throws IOException { ensureOpen(); - return MultiPerDocValues.getPerDocs(in); + return MultiDocValues.getDocValues(in, field); } @Override diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesFormat.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesFormat.java index 1e269470e9d..466f458a653 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesFormat.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesFormat.java @@ -20,7 +20,6 @@ package org.apache.lucene.index.codecs; import java.io.IOException; import java.util.Set; -import org.apache.lucene.index.PerDocValues; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentReadState; @@ -28,6 +27,6 @@ import org.apache.lucene.store.Directory; public abstract class DocValuesFormat { public abstract PerDocConsumer docsConsumer(PerDocWriteState state) throws IOException; - public abstract PerDocValues docsProducer(SegmentReadState state) throws IOException; + public abstract PerDocProducer docsProducer(SegmentReadState state) throws IOException; public abstract void files(Directory dir, SegmentInfo info, Set files) throws IOException; } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java index 4530acf99aa..92f07b2b161 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesReaderBase.java @@ -28,7 +28,6 @@ import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.DocValues.Type; // javadocs -import org.apache.lucene.index.PerDocValues; import org.apache.lucene.index.codecs.lucene40.values.Bytes; import org.apache.lucene.index.codecs.lucene40.values.Floats; import org.apache.lucene.index.codecs.lucene40.values.Ints; @@ -37,11 +36,11 @@ import org.apache.lucene.store.IOContext; import org.apache.lucene.util.BytesRef; /** - * Abstract base class for PerDocValues implementations + * Abstract base class for PerDocProducer implementations * @lucene.experimental */ // TODO: this needs to go under lucene40 codec (its specific to its impl) -public abstract class DocValuesReaderBase extends PerDocValues { +public abstract class DocValuesReaderBase extends PerDocProducer { protected abstract void closeInternal(Collection closeables) throws IOException; protected abstract Map docValues(); diff --git a/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java index f2d1f814be9..5b99ce062c3 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/PerDocConsumer.java @@ -21,7 +21,6 @@ import java.io.IOException; import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.MergeState; -import org.apache.lucene.index.PerDocValues; /** * Abstract API that consumes per document values. Concrete implementations of @@ -39,30 +38,22 @@ public abstract class PerDocConsumer implements Closeable{ throws IOException; /** - * Consumes and merges the given {@link PerDocValues} producer + * Consumes and merges the given {@link PerDocProducer} producer * into this consumers format. */ public void merge(MergeState mergeState) throws IOException { final DocValues[] docValues = new DocValues[mergeState.readers.size()]; - final PerDocValues[] perDocValues = new PerDocValues[mergeState.readers.size()]; - // pull all PerDocValues - for (int i = 0; i < perDocValues.length; i++) { - perDocValues[i] = mergeState.readers.get(i).reader.perDocValues(); - } + for (FieldInfo fieldInfo : mergeState.fieldInfos) { mergeState.fieldInfo = fieldInfo; // set the field we are merging if (fieldInfo.hasDocValues()) { - for (int i = 0; i < perDocValues.length; i++) { - if (perDocValues[i] != null) { // get all IDV to merge - docValues[i] = perDocValues[i].docValues(fieldInfo.name); - } + for (int i = 0; i < docValues.length; i++) { + docValues[i] = mergeState.readers.get(i).reader.docValues(fieldInfo.name); } final DocValuesConsumer docValuesConsumer = addValuesField(fieldInfo.getDocValuesType(), fieldInfo); assert docValuesConsumer != null; docValuesConsumer.merge(mergeState, docValues); } } - /* NOTE: don't close the perDocProducers here since they are private segment producers - * and will be closed once the SegmentReader goes out of scope */ } } diff --git a/lucene/src/java/org/apache/lucene/index/PerDocValues.java b/lucene/src/java/org/apache/lucene/index/codecs/PerDocProducer.java similarity index 83% rename from lucene/src/java/org/apache/lucene/index/PerDocValues.java rename to lucene/src/java/org/apache/lucene/index/codecs/PerDocProducer.java index 08a91577d02..ff2827d8c72 100644 --- a/lucene/src/java/org/apache/lucene/index/PerDocValues.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/PerDocProducer.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index; +package org.apache.lucene.index.codecs; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -18,8 +18,7 @@ package org.apache.lucene.index; import java.io.Closeable; import java.io.IOException; -import org.apache.lucene.index.codecs.PerDocConsumer; -import org.apache.lucene.index.codecs.PostingsFormat; +import org.apache.lucene.index.DocValues; /** * Abstract API that provides access to one or more per-document storage @@ -27,13 +26,13 @@ import org.apache.lucene.index.codecs.PostingsFormat; * storage on a per-document basis corresponding to their actual * {@link PerDocConsumer} counterpart. *

- * The {@link PerDocValues} API is accessible through the + * The {@link PerDocProducer} API is accessible through the * {@link PostingsFormat} - API providing per field consumers and producers for inverted * data (terms, postings) as well as per-document data. * * @lucene.experimental */ -public abstract class PerDocValues implements Closeable { +public abstract class PerDocProducer implements Closeable { /** * Returns {@link DocValues} for the current field. * @@ -45,5 +44,5 @@ public abstract class PerDocValues implements Closeable { */ public abstract DocValues docValues(String field) throws IOException; - public static final PerDocValues[] EMPTY_ARRAY = new PerDocValues[0]; + public static final PerDocProducer[] EMPTY_ARRAY = new PerDocProducer[0]; } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xCodec.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xCodec.java index 19689788375..4ad0b8b4e9d 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xCodec.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xCodec.java @@ -20,7 +20,6 @@ package org.apache.lucene.index.codecs.lucene3x; import java.io.IOException; import java.util.Set; -import org.apache.lucene.index.PerDocValues; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentReadState; @@ -28,6 +27,7 @@ import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.DocValuesFormat; import org.apache.lucene.index.codecs.FieldInfosFormat; import org.apache.lucene.index.codecs.NormsFormat; +import org.apache.lucene.index.codecs.PerDocProducer; import org.apache.lucene.index.codecs.StoredFieldsFormat; import org.apache.lucene.index.codecs.PerDocConsumer; import org.apache.lucene.index.codecs.PostingsFormat; @@ -75,7 +75,7 @@ public class Lucene3xCodec extends Codec { } @Override - public PerDocValues docsProducer(SegmentReadState state) throws IOException { + public PerDocProducer docsProducer(SegmentReadState state) throws IOException { return null; } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesFormat.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesFormat.java index 0257e8ba9bf..28bd0b25362 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesFormat.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesFormat.java @@ -20,12 +20,12 @@ package org.apache.lucene.index.codecs.lucene40; import java.io.IOException; import java.util.Set; -import org.apache.lucene.index.PerDocValues; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.index.codecs.DocValuesFormat; import org.apache.lucene.index.codecs.PerDocConsumer; +import org.apache.lucene.index.codecs.PerDocProducer; import org.apache.lucene.store.Directory; public class Lucene40DocValuesFormat extends DocValuesFormat { @@ -36,7 +36,7 @@ public class Lucene40DocValuesFormat extends DocValuesFormat { } @Override - public PerDocValues docsProducer(SegmentReadState state) throws IOException { + public PerDocProducer docsProducer(SegmentReadState state) throws IOException { return new Lucene40DocValuesProducer(state); } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesProducer.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesProducer.java index c737486d610..c9baf1fa505 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesProducer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/Lucene40DocValuesProducer.java @@ -33,7 +33,7 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.util.IOUtils; /** - * Default PerDocValues implementation that uses compound file. + * Default PerDocProducer implementation that uses compound file. * @lucene.experimental */ public class Lucene40DocValuesProducer extends DocValuesReaderBase { diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesProducer.java b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesProducer.java index 82daa2ee41e..349417effc1 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesProducer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepDocValuesProducer.java @@ -28,7 +28,7 @@ import org.apache.lucene.index.codecs.DocValuesReaderBase; import org.apache.lucene.util.IOUtils; /** - * Implementation of PerDocValues that uses separate files. + * Implementation of PerDocProducer that uses separate files. * @lucene.experimental */ public class SepDocValuesProducer extends DocValuesReaderBase { diff --git a/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mocksep/MockSepDocValuesFormat.java b/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mocksep/MockSepDocValuesFormat.java index 698b8bf37ca..595f6b6c770 100644 --- a/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mocksep/MockSepDocValuesFormat.java +++ b/lucene/src/test-framework/java/org/apache/lucene/index/codecs/mocksep/MockSepDocValuesFormat.java @@ -20,12 +20,12 @@ package org.apache.lucene.index.codecs.mocksep; import java.io.IOException; import java.util.Set; -import org.apache.lucene.index.PerDocValues; import org.apache.lucene.index.PerDocWriteState; import org.apache.lucene.index.SegmentInfo; import org.apache.lucene.index.SegmentReadState; import org.apache.lucene.index.codecs.DocValuesFormat; import org.apache.lucene.index.codecs.PerDocConsumer; +import org.apache.lucene.index.codecs.PerDocProducer; import org.apache.lucene.index.codecs.sep.SepDocValuesConsumer; import org.apache.lucene.index.codecs.sep.SepDocValuesProducer; import org.apache.lucene.store.Directory; @@ -43,7 +43,7 @@ public class MockSepDocValuesFormat extends DocValuesFormat { } @Override - public PerDocValues docsProducer(SegmentReadState state) throws IOException { + public PerDocProducer docsProducer(SegmentReadState state) throws IOException { return new SepDocValuesProducer(state); } diff --git a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java index ab0b586a36e..0ab5a28657d 100755 --- a/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java +++ b/lucene/src/test/org/apache/lucene/index/TestAddIndexes.java @@ -1284,7 +1284,7 @@ public class TestAddIndexes extends LuceneTestCase { w.close(); IndexReader sr = getOnlySegmentReader(r3); assertEquals(2, sr.numDocs()); - DocValues docValues = sr.perDocValues().docValues("dv"); + DocValues docValues = sr.docValues("dv"); assertNotNull(docValues); r3.close(); d3.close(); diff --git a/lucene/src/test/org/apache/lucene/index/TestDuelingCodecs.java b/lucene/src/test/org/apache/lucene/index/TestDuelingCodecs.java index b9313fce97e..e7b483b8a96 100644 --- a/lucene/src/test/org/apache/lucene/index/TestDuelingCodecs.java +++ b/lucene/src/test/org/apache/lucene/index/TestDuelingCodecs.java @@ -18,12 +18,15 @@ package org.apache.lucene.index; */ import java.io.IOException; +import java.util.HashSet; import java.util.Iterator; import java.util.Random; +import java.util.Set; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.document.Document; +import org.apache.lucene.index.IndexReader.FieldOption; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.store.Directory; @@ -516,29 +519,15 @@ public class TestDuelingCodecs extends LuceneTestCase { * checks that docvalues across all fields are equivalent */ public void assertDocValues(IndexReader leftReader, IndexReader rightReader) throws Exception { - PerDocValues leftPerDoc = MultiPerDocValues.getPerDocs(leftReader); - PerDocValues rightPerDoc = MultiPerDocValues.getPerDocs(rightReader); - - Fields leftFields = MultiFields.getFields(leftReader); - Fields rightFields = MultiFields.getFields(rightReader); - // Fields could be null if there are no postings, - // but then it must be null for both - if (leftFields == null || rightFields == null) { - assertNull(info, leftFields); - assertNull(info, rightFields); - return; - } - - FieldsEnum fieldsEnum = leftFields.iterator(); - String field; - while ((field = fieldsEnum.next()) != null) { - DocValues leftDocValues = leftPerDoc.docValues(field); - DocValues rightDocValues = rightPerDoc.docValues(field); - if (leftDocValues == null || rightDocValues == null) { - assertNull(info, leftDocValues); - assertNull(info, rightDocValues); - continue; - } + Set leftValues = new HashSet(leftReader.getFieldNames(FieldOption.DOC_VALUES)); + Set rightValues = new HashSet(rightReader.getFieldNames(FieldOption.DOC_VALUES)); + assertEquals(info, leftValues, rightValues); + + for (String field : leftValues) { + DocValues leftDocValues = MultiDocValues.getDocValues(leftReader, field); + DocValues rightDocValues = MultiDocValues.getDocValues(rightReader, field); + assertNotNull(info, leftDocValues); + assertNotNull(info, rightDocValues); assertDocValuesSource(leftDocValues.getDirectSource(), rightDocValues.getDirectSource()); assertDocValuesSource(leftDocValues.getSource(), rightDocValues.getSource()); } diff --git a/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java b/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java index ac867ace604..35fa90f4c10 100644 --- a/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java +++ b/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java @@ -37,13 +37,13 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.LogDocMergePolicy; import org.apache.lucene.index.LogMergePolicy; -import org.apache.lucene.index.MultiPerDocValues; -import org.apache.lucene.index.PerDocValues; +import org.apache.lucene.index.MultiDocValues; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.codecs.Codec; +import org.apache.lucene.index.codecs.PerDocProducer; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockObtainFailedException; @@ -104,7 +104,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { TopDocs search = searcher.search(query, 10); assertEquals(5, search.totalHits); ScoreDoc[] scoreDocs = search.scoreDocs; - DocValues docValues = MultiPerDocValues.getPerDocs(reader).docValues("docId"); + DocValues docValues = MultiDocValues.getDocValues(reader, "docId"); Source source = docValues.getSource(); for (int i = 0; i < scoreDocs.length; i++) { assertEquals(i, scoreDocs[i].doc); @@ -418,24 +418,8 @@ public class TestDocValuesIndexing extends LuceneTestCase { d.close(); } - private DocValues getDocValues(IndexReader reader, String field) - throws IOException { - boolean singleSeg = reader.getSequentialSubReaders().length == 1; - PerDocValues perDoc = singleSeg ? reader.getSequentialSubReaders()[0].perDocValues() - : MultiPerDocValues.getPerDocs(reader); - switch (random.nextInt(singleSeg ? 3 : 2)) { // case 2 only if single seg - case 0: - return perDoc.docValues(field); - case 1: - DocValues docValues = perDoc.docValues(field); - if (docValues != null) { - return docValues; - } - throw new RuntimeException("no such field " + field); - case 2:// this only works if we are on a single seg index! - return reader.getSequentialSubReaders()[0].docValues(field); - } - throw new RuntimeException(); + private DocValues getDocValues(IndexReader reader, String field) throws IOException { + return MultiDocValues.getDocValues(reader, field); } private Source getSource(DocValues values) throws IOException { @@ -570,7 +554,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { w.forceMerge(1); IndexReader r = w.getReader(); w.close(); - assertEquals(17, r.getSequentialSubReaders()[0].perDocValues().docValues("field").load().getInt(0)); + assertEquals(17, r.getSequentialSubReaders()[0].docValues("field").load().getInt(0)); r.close(); d.close(); } @@ -600,7 +584,7 @@ public class TestDocValuesIndexing extends LuceneTestCase { w.forceMerge(1); IndexReader r = w.getReader(); w.close(); - assertEquals(17, r.getSequentialSubReaders()[0].perDocValues().docValues("field").load().getInt(0)); + assertEquals(17, r.getSequentialSubReaders()[0].docValues("field").load().getInt(0)); r.close(); d.close(); } From d0453d820c4b8c4ba8e674fff20ff93c176e0ac9 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 10 Dec 2011 17:54:46 +0000 Subject: [PATCH 14/19] LUCENE-3606: use MultiDocValues in PR git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1212829 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/src/java/org/apache/lucene/index/ParallelReader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lucene/src/java/org/apache/lucene/index/ParallelReader.java b/lucene/src/java/org/apache/lucene/index/ParallelReader.java index 6582b65b4bd..8ac8325e548 100644 --- a/lucene/src/java/org/apache/lucene/index/ParallelReader.java +++ b/lucene/src/java/org/apache/lucene/index/ParallelReader.java @@ -460,9 +460,10 @@ public class ParallelReader extends IndexReader { } } + // TODO: I suspect this is completely untested!!!!! @Override public DocValues docValues(String field) throws IOException { IndexReader reader = fieldToReader.get(field); - return reader == null ? null : reader.docValues(field); + return reader == null ? null : MultiDocValues.getDocValues(reader, field); } } From 124728c97487911ab225397878e15c5469ba0360 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 10 Dec 2011 18:17:34 +0000 Subject: [PATCH 15/19] LUCENE-3622: PerFieldDocValues -> DocValue git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1212833 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/document/LazyDocument.java | 14 +++++++------- .../apache/lucene/document/DocValuesField.java | 8 ++++---- .../java/org/apache/lucene/document/Field.java | 12 ++++++------ .../apache/lucene/index/DocFieldProcessor.java | 6 +++--- .../{PerDocFieldValues.java => DocValue.java} | 4 ++-- .../apache/lucene/index/IndexableField.java | 6 +++--- .../lucene/index/codecs/DocValuesConsumer.java | 18 +++++++++--------- .../index/codecs/lucene40/values/Bytes.java | 6 +++--- .../index/codecs/lucene40/values/Floats.java | 6 +++--- .../index/codecs/lucene40/values/Ints.java | 6 +++--- .../lucene40/values/PackedIntValues.java | 6 +++--- .../lucene/index/TestIndexableField.java | 4 ++-- 12 files changed, 48 insertions(+), 48 deletions(-) rename lucene/src/java/org/apache/lucene/index/{PerDocFieldValues.java => DocValue.java} (97%) diff --git a/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java b/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java index edaf7f52329..b7217086328 100644 --- a/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java +++ b/lucene/contrib/misc/src/java/org/apache/lucene/document/LazyDocument.java @@ -28,7 +28,7 @@ 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.PerDocFieldValues; +import org.apache.lucene.index.DocValue; import org.apache.lucene.index.DocValues; import org.apache.lucene.util.BytesRef; @@ -157,20 +157,20 @@ public class LazyDocument { } @Override - public PerDocFieldValues docValues() { + public DocValue docValue() { if (num == 0) { - return getDocument().getField(name).docValues(); + return getDocument().getField(name).docValue(); } else { - return getDocument().getFields(name)[num].docValues(); + return getDocument().getFields(name)[num].docValue(); } } @Override - public DocValues.Type docValuesType() { + public DocValues.Type docValueType() { if (num == 0) { - return getDocument().getField(name).docValuesType(); + return getDocument().getField(name).docValueType(); } else { - return getDocument().getFields(name)[num].docValuesType(); + return getDocument().getFields(name)[num].docValueType(); } } diff --git a/lucene/src/java/org/apache/lucene/document/DocValuesField.java b/lucene/src/java/org/apache/lucene/document/DocValuesField.java index 097a8814b2e..2cb494c2e43 100644 --- a/lucene/src/java/org/apache/lucene/document/DocValuesField.java +++ b/lucene/src/java/org/apache/lucene/document/DocValuesField.java @@ -20,7 +20,7 @@ import java.io.Reader; import java.util.Comparator; import org.apache.lucene.index.IndexableFieldType; -import org.apache.lucene.index.PerDocFieldValues; +import org.apache.lucene.index.DocValue; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.DocValues.Type; // javadocs import org.apache.lucene.util.BytesRef; @@ -69,7 +69,7 @@ import org.apache.lucene.util.BytesRef; *

* * */ -public class DocValuesField extends Field implements PerDocFieldValues { +public class DocValuesField extends Field implements DocValue { protected BytesRef bytes; protected double doubleValue; @@ -94,7 +94,7 @@ public class DocValuesField extends Field implements PerDocFieldValues { } @Override - public PerDocFieldValues docValues() { + public DocValue docValue() { return this; } @@ -307,7 +307,7 @@ public class DocValuesField extends Field implements PerDocFieldValues { } @Override - public DocValues.Type docValuesType() { + public DocValues.Type docValueType() { return type; } diff --git a/lucene/src/java/org/apache/lucene/document/Field.java b/lucene/src/java/org/apache/lucene/document/Field.java index 45b9a5a2ff1..26b26be4aa6 100644 --- a/lucene/src/java/org/apache/lucene/document/Field.java +++ b/lucene/src/java/org/apache/lucene/document/Field.java @@ -28,7 +28,7 @@ import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexableFieldType; import org.apache.lucene.index.IndexableField; -import org.apache.lucene.index.PerDocFieldValues; +import org.apache.lucene.index.DocValue; import org.apache.lucene.util.BytesRef; /** @@ -51,7 +51,7 @@ public class Field implements IndexableField { // pre-analyzed tokenStream for indexed fields protected TokenStream tokenStream; // length/offset for all primitive types - protected PerDocFieldValues docValues; + protected DocValue docValue; protected float boost = 1.0f; @@ -292,17 +292,17 @@ public class Field implements IndexableField { return result.toString(); } - public void setDocValues(PerDocFieldValues docValues) { - this.docValues = docValues; + public void setDocValue(DocValue docValue) { + this.docValue = docValue; } @Override - public PerDocFieldValues docValues() { + public DocValue docValue() { return null; } @Override - public DocValues.Type docValuesType() { + public DocValues.Type docValueType() { return null; } diff --git a/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java b/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java index df3f4202d2a..8610887dcde 100644 --- a/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java +++ b/lucene/src/java/org/apache/lucene/index/DocFieldProcessor.java @@ -259,9 +259,9 @@ final class DocFieldProcessor extends DocConsumer { if (field.fieldType().stored()) { fieldsWriter.addField(field, fp.fieldInfo); } - final PerDocFieldValues docValues = field.docValues(); - if (docValues != null) { - docValuesConsumer(field.docValuesType(), docState, fp.fieldInfo).add(docState.docID, docValues); + final DocValue docValue = field.docValue(); + if (docValue != null) { + docValuesConsumer(field.docValueType(), docState, fp.fieldInfo).add(docState.docID, docValue); } } diff --git a/lucene/src/java/org/apache/lucene/index/PerDocFieldValues.java b/lucene/src/java/org/apache/lucene/index/DocValue.java similarity index 97% rename from lucene/src/java/org/apache/lucene/index/PerDocFieldValues.java rename to lucene/src/java/org/apache/lucene/index/DocValue.java index c82545eed6d..dacb7f6fba5 100644 --- a/lucene/src/java/org/apache/lucene/index/PerDocFieldValues.java +++ b/lucene/src/java/org/apache/lucene/index/DocValue.java @@ -30,7 +30,7 @@ import org.apache.lucene.util.BytesRef; * * @lucene.experimental */ -public interface PerDocFieldValues { +public interface DocValue { /** * Sets the given long value. @@ -96,5 +96,5 @@ public interface PerDocFieldValues { /** * Returns the {@link Type} */ - public DocValues.Type docValuesType(); + public DocValues.Type docValueType(); } diff --git a/lucene/src/java/org/apache/lucene/index/IndexableField.java b/lucene/src/java/org/apache/lucene/index/IndexableField.java index 4a2c8a95073..54ffca44497 100644 --- a/lucene/src/java/org/apache/lucene/index/IndexableField.java +++ b/lucene/src/java/org/apache/lucene/index/IndexableField.java @@ -76,10 +76,10 @@ public interface IndexableField { public IndexableFieldType fieldType(); /** Non-null if doc values should be indexed */ - public PerDocFieldValues docValues(); + public DocValue docValue(); - /** DocValues type; only used if docValues is non-null */ - public DocValues.Type docValuesType(); + /** DocValues type; only used if docValue is non-null */ + public DocValues.Type docValueType(); /** * Creates the TokenStream used for indexing this field. If appropriate, diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java index e8ddee5088e..f189badc756 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java @@ -21,14 +21,14 @@ import java.io.IOException; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.MergeState; -import org.apache.lucene.index.PerDocFieldValues; +import org.apache.lucene.index.DocValue; import org.apache.lucene.util.Bits; /** - * Abstract API that consumes {@link PerDocFieldValues}. + * Abstract API that consumes {@link DocValue}s. * {@link DocValuesConsumer} are always associated with a specific field and * segments. Concrete implementations of this API write the given - * {@link PerDocFieldValues} into a implementation specific format depending on + * {@link DocValue} into a implementation specific format depending on * the fields meta-data. * * @lucene.experimental @@ -36,28 +36,28 @@ import org.apache.lucene.util.Bits; public abstract class DocValuesConsumer { /** - * Adds the given {@link PerDocFieldValues} instance to this + * Adds the given {@link DocValue} instance to this * {@link DocValuesConsumer} * * @param docID * the document ID to add the value for. The docID must always * increase or be 0 if it is the first call to this method. - * @param docValues - * the values to add + * @param docValue + * the value to add * @throws IOException * if an {@link IOException} occurs */ - public abstract void add(int docID, PerDocFieldValues docValues) + public abstract void add(int docID, DocValue docValue) throws IOException; /** * Called when the consumer of this API is doc with adding - * {@link PerDocFieldValues} to this {@link DocValuesConsumer} + * {@link DocValue} to this {@link 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, PerDocFieldValues)}. + * {@link #add(int, DocValue)}. * @throws IOException */ public abstract void finish(int docCount) throws IOException; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java index 2b227e32d8a..789d3aab49e 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Bytes.java @@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicLong; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexFileNames; -import org.apache.lucene.index.PerDocFieldValues; +import org.apache.lucene.index.DocValue; import org.apache.lucene.index.DocValues.SortedSource; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; @@ -302,9 +302,9 @@ public final class Bytes { } @Override - public void add(int docID, PerDocFieldValues docValues) throws IOException { + public void add(int docID, DocValue docValue) throws IOException { final BytesRef ref; - if ((ref = docValues.getBytes()) != null) { + if ((ref = docValue.getBytes()) != null) { add(docID, ref); } } diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Floats.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Floats.java index b2ed4ea0abb..0a552276e50 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Floats.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Floats.java @@ -19,7 +19,7 @@ package org.apache.lucene.index.codecs.lucene40.values; import java.io.IOException; import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.PerDocFieldValues; +import org.apache.lucene.index.DocValue; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.store.Directory; @@ -85,8 +85,8 @@ public class Floats { } @Override - public void add(int docID, PerDocFieldValues docValues) throws IOException { - add(docID, docValues.getFloat()); + public void add(int docID, DocValue docValue) throws IOException { + add(docID, docValue.getFloat()); } @Override diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Ints.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Ints.java index 5da35ab299d..bc5de345e85 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Ints.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/Ints.java @@ -21,7 +21,7 @@ import java.io.IOException; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.DocValues.Type; -import org.apache.lucene.index.PerDocFieldValues; +import org.apache.lucene.index.DocValue; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; @@ -109,8 +109,8 @@ public final class Ints { } @Override - public void add(int docID, PerDocFieldValues docValues) throws IOException { - add(docID, docValues.getInt()); + public void add(int docID, DocValue docValue) throws IOException { + add(docID, docValue.getInt()); } @Override diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/PackedIntValues.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/PackedIntValues.java index 10983e4bf37..2670510b4c9 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/PackedIntValues.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/PackedIntValues.java @@ -20,7 +20,7 @@ import java.io.IOException; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexFileNames; -import org.apache.lucene.index.PerDocFieldValues; +import org.apache.lucene.index.DocValue; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.codecs.lucene40.values.FixedStraightBytesImpl.FixedBytesWriterBase; @@ -151,8 +151,8 @@ class PackedIntValues { } @Override - public void add(int docID, PerDocFieldValues docValues) throws IOException { - add(docID, docValues.getInt()); + public void add(int docID, DocValue docValue) throws IOException { + add(docID, docValue.getInt()); } } diff --git a/lucene/src/test/org/apache/lucene/index/TestIndexableField.java b/lucene/src/test/org/apache/lucene/index/TestIndexableField.java index 1e170f332e0..0310f8dc103 100644 --- a/lucene/src/test/org/apache/lucene/index/TestIndexableField.java +++ b/lucene/src/test/org/apache/lucene/index/TestIndexableField.java @@ -156,12 +156,12 @@ public class TestIndexableField extends LuceneTestCase { // TODO: randomly enable doc values @Override - public PerDocFieldValues docValues() { + public DocValue docValue() { return null; } @Override - public DocValues.Type docValuesType() { + public DocValues.Type docValueType() { return null; } From 0afa9de4e9c55f508952054470bf1907f0960fe1 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 10 Dec 2011 19:38:04 +0000 Subject: [PATCH 16/19] LUCENE-3622: move SortedBytesMergeUtils to index package (to eventually hook into MultiDocValues) git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1212854 13f79535-47bb-0310-9956-ffa450edef68 --- .../values => }/SortedBytesMergeUtils.java | 27 ++++++++++--------- .../lucene40/values/FixedSortedBytesImpl.java | 5 ++-- .../lucene40/values/VarSortedBytesImpl.java | 5 ++-- 3 files changed, 21 insertions(+), 16 deletions(-) rename lucene/src/java/org/apache/lucene/index/{codecs/lucene40/values => }/SortedBytesMergeUtils.java (92%) diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/SortedBytesMergeUtils.java b/lucene/src/java/org/apache/lucene/index/SortedBytesMergeUtils.java similarity index 92% rename from lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/SortedBytesMergeUtils.java rename to lucene/src/java/org/apache/lucene/index/SortedBytesMergeUtils.java index 3b09a91ecee..19959c3d830 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/SortedBytesMergeUtils.java +++ b/lucene/src/java/org/apache/lucene/index/SortedBytesMergeUtils.java @@ -1,4 +1,4 @@ -package org.apache.lucene.index.codecs.lucene40.values; +package org.apache.lucene.index; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -22,8 +22,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import org.apache.lucene.index.DocValues; -import org.apache.lucene.index.MergeState; import org.apache.lucene.index.DocValues.SortedSource; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; @@ -37,13 +35,18 @@ import org.apache.lucene.util.packed.PackedInts; /** * @lucene.internal */ -final class SortedBytesMergeUtils { +// TODO: generalize this a bit more: +// * remove writing (like indexoutput) from here +// * just take IndexReaders (not IR&LiveDocs), doesnt care about liveDocs +// * hook into MultiDocValues to make a MultiSortedSource +// * maybe DV merging should then just use MultiDocValues for simplicity? +public final class SortedBytesMergeUtils { private SortedBytesMergeUtils() { // no instance } - static MergeContext init(Type type, DocValues[] docValues, + public static MergeContext init(Type type, DocValues[] docValues, Comparator comp, MergeState mergeState) { int size = -1; if (type == Type.BYTES_FIXED_SORTED) { @@ -61,10 +64,10 @@ final class SortedBytesMergeUtils { public static final class MergeContext { private final Comparator comp; private final BytesRef missingValue = new BytesRef(); - final int sizePerValues; // -1 if var length + public final int sizePerValues; // -1 if var length final Type type; - final int[] docToEntry; - long[] offsets; // if non-null #mergeRecords collects byte offsets here + public final int[] docToEntry; + public long[] offsets; // if non-null #mergeRecords collects byte offsets here public MergeContext(Comparator comp, MergeState mergeState, int size, Type type) { @@ -80,7 +83,7 @@ final class SortedBytesMergeUtils { } } - static List buildSlices(MergeState mergeState, + public static List buildSlices(MergeState mergeState, DocValues[] docValues, MergeContext ctx) throws IOException { final List slices = new ArrayList(); for (int i = 0; i < docValues.length; i++) { @@ -142,7 +145,7 @@ final class SortedBytesMergeUtils { } } - static int mergeRecords(MergeContext ctx, IndexOutput datOut, + public static int mergeRecords(MergeContext ctx, IndexOutput datOut, List slices) throws IOException { final RecordMerger merger = new RecordMerger(new MergeQueue(slices.size(), ctx.comp), slices.toArray(new SortedSourceSlice[0])); @@ -217,7 +220,7 @@ final class SortedBytesMergeUtils { } } - static class SortedSourceSlice { + public static class SortedSourceSlice { final SortedSource source; final int readerIdx; /* global array indexed by docID containg the relative ord for the doc */ @@ -267,7 +270,7 @@ final class SortedBytesMergeUtils { return null; } - void writeOrds(PackedInts.Writer writer) throws IOException { + public void writeOrds(PackedInts.Writer writer) throws IOException { for (int i = docToOrdStart; i < docToOrdEnd; i++) { final int mappedOrd = docIDToRelativeOrd[i]; assert mappedOrd < ordMapping.length; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java index 617fb64b8f9..0abf11e0531 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/FixedSortedBytesImpl.java @@ -22,14 +22,15 @@ import java.util.Comparator; import java.util.List; import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.SortedBytesMergeUtils; import org.apache.lucene.index.DocValues.SortedSource; import org.apache.lucene.index.DocValues.Type; +import org.apache.lucene.index.SortedBytesMergeUtils.MergeContext; +import org.apache.lucene.index.SortedBytesMergeUtils.SortedSourceSlice; import org.apache.lucene.index.MergeState; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSortedSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; -import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.MergeContext; -import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.SortedSourceSlice; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; diff --git a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java index 20de637f62e..b50df8430ec 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/lucene40/values/VarSortedBytesImpl.java @@ -22,14 +22,15 @@ import java.util.Comparator; import java.util.List; import org.apache.lucene.index.DocValues; +import org.apache.lucene.index.SortedBytesMergeUtils; import org.apache.lucene.index.DocValues.SortedSource; import org.apache.lucene.index.DocValues.Type; +import org.apache.lucene.index.SortedBytesMergeUtils.MergeContext; +import org.apache.lucene.index.SortedBytesMergeUtils.SortedSourceSlice; import org.apache.lucene.index.MergeState; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesReaderBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.BytesSortedSourceBase; import org.apache.lucene.index.codecs.lucene40.values.Bytes.DerefBytesWriterBase; -import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.MergeContext; -import org.apache.lucene.index.codecs.lucene40.values.SortedBytesMergeUtils.SortedSourceSlice; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; From 9460775d26f29cddb2a8f5d9111e110f3621eb76 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 10 Dec 2011 21:44:34 +0000 Subject: [PATCH 17/19] LUCENE-3622: add some sanity checks for docvalues git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1212888 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/CheckIndex.java | 74 ++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/src/java/org/apache/lucene/index/CheckIndex.java index 6be57d5c09a..16c8188f18b 100644 --- a/lucene/src/java/org/apache/lucene/index/CheckIndex.java +++ b/lucene/src/java/org/apache/lucene/index/CheckIndex.java @@ -25,6 +25,7 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.document.Document; +import org.apache.lucene.index.DocValues.SortedSource; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.codecs.PerDocProducer; @@ -638,11 +639,26 @@ public class CheckIndex { if (infoStream != null) { infoStream.print(" test: field norms........."); } + FieldInfos infos = reader.fieldInfos(); byte[] b; for (final String fieldName : fieldNames) { + FieldInfo info = infos.fieldInfo(fieldName); if (reader.hasNorms(fieldName)) { b = reader.norms(fieldName); + if (b.length != reader.maxDoc()) { + throw new RuntimeException("norms for field: " + fieldName + " are of the wrong size"); + } + if (!info.isIndexed || info.omitNorms) { + throw new RuntimeException("field: " + fieldName + " should omit norms but has them!"); + } ++status.totFields; + } else { + if (reader.norms(fieldName) != null) { + throw new RuntimeException("field: " + fieldName + " should omit norms but has them!"); + } + if (info.isIndexed && !info.omitNorms) { + throw new RuntimeException("field: " + fieldName + " should have norms but omits them!"); + } } } @@ -1134,10 +1150,15 @@ public class CheckIndex { status.totalValueFields++; final DocValues docValues = reader.docValues(fieldInfo.name); if (docValues == null) { - continue; + throw new RuntimeException("field: " + fieldInfo.name + " omits docvalues but should have them!"); + } + DocValues.Type type = docValues.type(); + if (type != fieldInfo.getDocValuesType()) { + throw new RuntimeException("field: " + fieldInfo.name + " has type: " + type + " but fieldInfos says:" + fieldInfo.getDocValuesType()); } final Source values = docValues.getDirectSource(); final int maxDoc = reader.maxDoc(); + int size = docValues.getValueSize(); for (int i = 0; i < maxDoc; i++) { switch (fieldInfo.getDocValuesType()) { case BYTES_FIXED_SORTED: @@ -1146,17 +1167,38 @@ public class CheckIndex { case BYTES_FIXED_STRAIGHT: case BYTES_VAR_DEREF: case BYTES_VAR_STRAIGHT: - values.getBytes(i, new BytesRef()); + BytesRef bytes = new BytesRef(); + values.getBytes(i, bytes); + if (size != -1 && size != bytes.length) { + throw new RuntimeException("field: " + fieldInfo.name + " returned wrongly sized bytes, was: " + bytes.length + " should be: " + size); + } break; case FLOAT_32: + assert size == 4; + values.getFloat(i); + break; case FLOAT_64: + assert size == 8; values.getFloat(i); break; case VAR_INTS: + assert size == -1; + values.getInt(i); + break; case FIXED_INTS_16: + assert size == 2; + values.getInt(i); + break; case FIXED_INTS_32: + assert size == 4; + values.getInt(i); + break; case FIXED_INTS_64: + assert size == 8; + values.getInt(i); + break; case FIXED_INTS_8: + assert size == 1; values.getInt(i); break; default: @@ -1164,6 +1206,34 @@ public class CheckIndex { + " - no such DocValues type: " + fieldInfo.getDocValuesType()); } } + if (type == DocValues.Type.BYTES_FIXED_SORTED || type == DocValues.Type.BYTES_VAR_SORTED) { + // check sorted bytes + SortedSource sortedValues = values.asSortedSource(); + Comparator comparator = sortedValues.getComparator(); + int lastOrd = -1; + BytesRef lastBytes = new BytesRef(); + for (int i = 0; i < maxDoc; i++) { + int ord = sortedValues.ord(i); + if (ord < 0 || ord > maxDoc) { + throw new RuntimeException("field: " + fieldInfo.name + " ord is out of bounds: " + ord); + } + BytesRef bytes = new BytesRef(); + sortedValues.getByOrd(ord, bytes); + if (lastOrd != -1) { + int ordComp = Integer.signum(new Integer(ord).compareTo(new Integer(lastOrd))); + int bytesComp = Integer.signum(comparator.compare(bytes, lastBytes)); + if (ordComp != bytesComp) { + throw new RuntimeException("field: " + fieldInfo.name + " ord comparison is wrong: " + ordComp + " comparator claims: " + bytesComp); + } + } + lastOrd = ord; + lastBytes = bytes; + } + } + } else { + if (reader.docValues(fieldInfo.name) != null) { + throw new RuntimeException("field: " + fieldInfo.name + " has docvalues but should omit them!"); + } } } From 64facac463eeaabf4b5d5aaf5aeba18dd9401bb2 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 12 Dec 2011 20:13:33 +0000 Subject: [PATCH 18/19] LUCENE-3622: make this a TODO for now git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1213406 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/lucene/index/codecs/DocValuesConsumer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java index f189badc756..03b3f94dad4 100644 --- a/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java +++ b/lucene/src/java/org/apache/lucene/index/codecs/DocValuesConsumer.java @@ -99,7 +99,7 @@ public abstract class DocValuesConsumer { * @throws IOException * if an {@link IOException} occurs */ - // nocommit: can't we have a default implementation here that merges naively with our apis? + // TODO: can't we have a default implementation here that merges naively with our apis? // this is how stored fields and term vectors work. its a pain to have to impl merging // (should be an optimization to override it) protected abstract void merge(SingleSubMergeState mergeState) throws IOException; From 701000cf27bb1cea6e023645be20b757f331712f Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 12 Dec 2011 20:33:26 +0000 Subject: [PATCH 19/19] LUCENE-3622: function DocValues -> FunctionValues git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3622@1213426 13f79535-47bb-0310-9956-ffa450edef68 --- .../FunctionAllGroupHeadsCollector.java | 6 +- .../function/FunctionAllGroupsCollector.java | 8 +- .../FunctionFirstPassGroupingCollector.java | 6 +- .../FunctionSecondPassGroupingCollector.java | 6 +- .../lucene/queries/function/BoostedQuery.java | 4 +- .../queries/function/FunctionQuery.java | 2 +- .../{DocValues.java => FunctionValues.java} | 6 +- .../lucene/queries/function/ValueSource.java | 8 +- .../queries/function/ValueSourceScorer.java | 4 +- .../function/docvalues/BoolDocValues.java | 4 +- .../function/docvalues/DoubleDocValues.java | 4 +- .../function/docvalues/FloatDocValues.java | 4 +- .../function/docvalues/IntDocValues.java | 4 +- .../function/docvalues/LongDocValues.java | 4 +- .../function/docvalues/StrDocValues.java | 4 +- .../docvalues/StringIndexDocValues.java | 8 +- .../function/valuesource/ByteFieldSource.java | 6 +- .../valuesource/BytesRefFieldSource.java | 6 +- .../valuesource/ConstValueSource.java | 4 +- .../function/valuesource/DefFunction.java | 10 +-- .../valuesource/DivFloatFunction.java | 4 +- .../valuesource/DocFreqValueSource.java | 4 +- .../valuesource/DoubleConstValueSource.java | 4 +- .../valuesource/DoubleFieldSource.java | 4 +- .../valuesource/DualFloatFunction.java | 10 +-- .../valuesource/FloatFieldSource.java | 4 +- .../function/valuesource/IDFValueSource.java | 4 +- .../function/valuesource/IfFunction.java | 12 +-- .../function/valuesource/IntFieldSource.java | 4 +- .../valuesource/JoinDocFreqValueSource.java | 4 +- .../valuesource/LinearFloatFunction.java | 6 +- .../valuesource/LiteralValueSource.java | 4 +- .../function/valuesource/LongFieldSource.java | 4 +- .../valuesource/MaxDocValueSource.java | 4 +- .../valuesource/MaxFloatFunction.java | 6 +- .../valuesource/MinFloatFunction.java | 6 +- .../valuesource/MultiBoolFunction.java | 8 +- .../valuesource/MultiFloatFunction.java | 10 +-- .../function/valuesource/MultiFunction.java | 16 ++-- .../function/valuesource/NormValueSource.java | 4 +- .../valuesource/NumDocsValueSource.java | 4 +- .../NumericIndexDocValueSource.java | 14 +-- .../function/valuesource/OrdFieldSource.java | 4 +- .../valuesource/PowFloatFunction.java | 4 +- .../valuesource/ProductFloatFunction.java | 6 +- .../valuesource/QueryValueSource.java | 8 +- .../valuesource/RangeMapFloatFunction.java | 6 +- .../valuesource/ReciprocalFloatFunction.java | 6 +- .../valuesource/ReverseOrdFieldSource.java | 4 +- .../valuesource/ScaleFloatFunction.java | 8 +- .../valuesource/ShortFieldSource.java | 6 +- .../valuesource/SimpleBoolFunction.java | 6 +- .../valuesource/SimpleFloatFunction.java | 8 +- .../valuesource/SumFloatFunction.java | 6 +- .../SumTotalTermFreqValueSource.java | 6 +- .../function/valuesource/TFValueSource.java | 4 +- .../valuesource/TermFreqValueSource.java | 4 +- .../valuesource/TotalTermFreqValueSource.java | 6 +- .../valuesource/VectorValueSource.java | 20 ++--- .../transform/ValueSourceAugmenter.java | 8 +- .../org/apache/solr/schema/BoolField.java | 4 +- .../org/apache/solr/schema/DateField.java | 4 +- .../org/apache/solr/schema/LatLonType.java | 6 +- .../apache/solr/schema/RandomSortField.java | 4 +- .../solr/schema/SortableDoubleField.java | 4 +- .../solr/schema/SortableFloatField.java | 4 +- .../apache/solr/schema/SortableIntField.java | 4 +- .../apache/solr/schema/SortableLongField.java | 4 +- .../apache/solr/schema/StrFieldSource.java | 4 +- .../search/FunctionRangeQParserPlugin.java | 4 +- .../apache/solr/search/ValueSourceParser.java | 90 +++++++++---------- .../solr/search/function/FileFloatSource.java | 4 +- .../function/distance/GeohashFunction.java | 10 +-- .../distance/GeohashHaversineFunction.java | 10 +-- .../distance/HaversineConstFunction.java | 8 +- .../function/distance/HaversineFunction.java | 10 +-- .../distance/SquaredEuclideanFunction.java | 4 +- .../distance/StringDistanceFunction.java | 8 +- .../distance/VectorDistanceFunction.java | 10 +-- .../solr/core/DummyValueSourceParser.java | 4 +- .../apache/solr/search/TestIndexSearcher.java | 4 +- .../search/function/NvlValueSourceParser.java | 4 +- 82 files changed, 288 insertions(+), 288 deletions(-) rename modules/queries/src/java/org/apache/lucene/queries/function/{DocValues.java => FunctionValues.java} (97%) diff --git a/modules/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java b/modules/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java index 6acc90cf80a..cfe7d2a1f3f 100644 --- a/modules/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java +++ b/modules/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java @@ -18,7 +18,7 @@ package org.apache.lucene.search.grouping.function; */ import org.apache.lucene.index.IndexReader; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.search.FieldComparator; import org.apache.lucene.search.Scorer; @@ -45,7 +45,7 @@ public class FunctionAllGroupHeadsCollector extends AbstractAllGroupHeadsCollect private final Map groups; private final Sort sortWithinGroup; - private DocValues.ValueFiller filler; + private FunctionValues.ValueFiller filler; private MutableValue mval; private IndexReader.AtomicReaderContext readerContext; private Scorer scorer; @@ -105,7 +105,7 @@ public class FunctionAllGroupHeadsCollector extends AbstractAllGroupHeadsCollect public void setNextReader(IndexReader.AtomicReaderContext context) throws IOException { this.readerContext = context; - DocValues docValues = groupBy.getValues(vsContext, context); + FunctionValues docValues = groupBy.getValues(vsContext, context); filler = docValues.getValueFiller(); mval = filler.getValue(); diff --git a/modules/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupsCollector.java b/modules/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupsCollector.java index f17aba3af25..e046ad08551 100644 --- a/modules/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupsCollector.java +++ b/modules/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupsCollector.java @@ -18,7 +18,7 @@ package org.apache.lucene.search.grouping.function; */ import org.apache.lucene.index.IndexReader; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.search.grouping.AbstractAllGroupsCollector; import org.apache.lucene.util.mutable.MutableValue; @@ -36,7 +36,7 @@ import java.util.TreeSet; * the most relevant document of a group. * *

- * Implementation detail: Uses {@link ValueSource} and {@link DocValues} to retrieve the + * Implementation detail: Uses {@link ValueSource} and {@link FunctionValues} to retrieve the * field values to group by. * * @lucene.experimental @@ -47,7 +47,7 @@ public class FunctionAllGroupsCollector extends AbstractAllGroupsCollector groups = new TreeSet(); - private DocValues.ValueFiller filler; + private FunctionValues.ValueFiller filler; private MutableValue mval; /** @@ -79,7 +79,7 @@ public class FunctionAllGroupsCollector extends AbstractAllGroupsCollector * Often used when creating a {@link FunctionQuery}. * @@ -45,7 +45,7 @@ public abstract class ValueSource implements Serializable { * Gets the values for this reader and the context that was previously * passed to createWeight() */ - public abstract DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException; + public abstract FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException; @Override public abstract boolean equals(Object o); @@ -129,12 +129,12 @@ public abstract class ValueSource implements Serializable { /** * Implement a {@link org.apache.lucene.search.FieldComparator} that works - * off of the {@link DocValues} for a ValueSource + * off of the {@link FunctionValues} for a ValueSource * instead of the normal Lucene FieldComparator that works off of a FieldCache. */ class ValueSourceComparator extends FieldComparator { private final double[] values; - private DocValues docVals; + private FunctionValues docVals; private double bottom; private Map fcontext; diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java b/modules/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java index a856d9fc7b9..975bd4b63c1 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java @@ -28,11 +28,11 @@ public class ValueSourceScorer extends Scorer { protected IndexReader reader; private int doc = -1; protected final int maxDoc; - protected final DocValues values; + protected final FunctionValues values; protected boolean checkDeletes; private final Bits liveDocs; - protected ValueSourceScorer(IndexReader reader, DocValues values) { + protected ValueSourceScorer(IndexReader reader, FunctionValues values) { super(null); this.reader = reader; this.maxDoc = reader.maxDoc(); diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/BoolDocValues.java b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/BoolDocValues.java index 8244a8a00f4..e290ddc09c4 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/BoolDocValues.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/BoolDocValues.java @@ -1,12 +1,12 @@ package org.apache.lucene.queries.function.docvalues; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.util.mutable.MutableValue; import org.apache.lucene.util.mutable.MutableValueBool; -public abstract class BoolDocValues extends DocValues { +public abstract class BoolDocValues extends FunctionValues { protected final ValueSource vs; public BoolDocValues(ValueSource vs) { diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/DoubleDocValues.java b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/DoubleDocValues.java index c09e0222db2..069ba11491c 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/DoubleDocValues.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/DoubleDocValues.java @@ -1,11 +1,11 @@ package org.apache.lucene.queries.function.docvalues; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.util.mutable.MutableValue; import org.apache.lucene.util.mutable.MutableValueDouble; -public abstract class DoubleDocValues extends DocValues { +public abstract class DoubleDocValues extends FunctionValues { protected final ValueSource vs; public DoubleDocValues(ValueSource vs) { diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java index 368a45a7a52..eb4daeb197b 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java @@ -1,11 +1,11 @@ package org.apache.lucene.queries.function.docvalues; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.util.mutable.MutableValue; import org.apache.lucene.util.mutable.MutableValueFloat; -public abstract class FloatDocValues extends DocValues { +public abstract class FloatDocValues extends FunctionValues { protected final ValueSource vs; public FloatDocValues(ValueSource vs) { diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/IntDocValues.java b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/IntDocValues.java index fa6c455c81f..9dd50f452e7 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/IntDocValues.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/IntDocValues.java @@ -1,12 +1,12 @@ package org.apache.lucene.queries.function.docvalues; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.util.mutable.MutableValue; import org.apache.lucene.util.mutable.MutableValueInt; -public abstract class IntDocValues extends DocValues { +public abstract class IntDocValues extends FunctionValues { protected final ValueSource vs; public IntDocValues(ValueSource vs) { diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/LongDocValues.java b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/LongDocValues.java index da4934c609b..1767d4ecd73 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/LongDocValues.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/LongDocValues.java @@ -1,12 +1,12 @@ package org.apache.lucene.queries.function.docvalues; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.util.mutable.MutableValue; import org.apache.lucene.util.mutable.MutableValueLong; -public abstract class LongDocValues extends DocValues { +public abstract class LongDocValues extends FunctionValues { protected final ValueSource vs; public LongDocValues(ValueSource vs) { diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/StrDocValues.java b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/StrDocValues.java index b3da187471a..305c651dada 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/StrDocValues.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/StrDocValues.java @@ -1,11 +1,11 @@ package org.apache.lucene.queries.function.docvalues; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.util.mutable.MutableValue; import org.apache.lucene.util.mutable.MutableValueStr; -public abstract class StrDocValues extends DocValues { +public abstract class StrDocValues extends FunctionValues { protected final ValueSource vs; public StrDocValues(ValueSource vs) { diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/StringIndexDocValues.java b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/StringIndexDocValues.java index 7e0bf9278dc..58b049beccc 100755 --- a/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/StringIndexDocValues.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/docvalues/StringIndexDocValues.java @@ -17,7 +17,7 @@ package org.apache.lucene.queries.function.docvalues; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.ValueSourceScorer; import org.apache.lucene.search.FieldCache; @@ -32,9 +32,9 @@ import org.apache.lucene.util.mutable.MutableValueStr; import java.io.IOException; /** Internal class, subject to change. - * Serves as base class for DocValues based on StringIndex + * Serves as base class for FunctionValues based on StringIndex **/ -public abstract class StringIndexDocValues extends DocValues { +public abstract class StringIndexDocValues extends FunctionValues { protected final FieldCache.DocTermsIndex termsIndex; protected final ValueSource vs; protected final MutableValueStr val = new MutableValueStr(); @@ -158,7 +158,7 @@ public abstract class StringIndexDocValues extends DocValues { public StringIndexException(final String fieldName, final RuntimeException cause) { super("Can't initialize StringIndex to generate (function) " + - "DocValues for field: " + fieldName, cause); + "FunctionValues for field: " + fieldName, cause); } } diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ByteFieldSource.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ByteFieldSource.java index 0e2e392bc9b..2a38693a978 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ByteFieldSource.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ByteFieldSource.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.util.Map; import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.search.FieldCache; /** @@ -50,10 +50,10 @@ public class ByteFieldSource extends FieldCacheSource { } @Override - public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { + public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { final byte[] arr = cache.getBytes(readerContext.reader, field, parser, false); - return new DocValues() { + return new FunctionValues() { @Override public byte byteVal(int doc) { return arr[doc]; diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java index 920ac1e3efe..1e94b786993 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/BytesRefFieldSource.java @@ -18,7 +18,7 @@ package org.apache.lucene.queries.function.valuesource; */ import org.apache.lucene.index.IndexReader; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.docvalues.StringIndexDocValues; import org.apache.lucene.queries.function.ValueSource; //javadoc @@ -26,7 +26,7 @@ import java.io.IOException; import java.util.Map; /** - * An implementation for retrieving {@link DocValues} instances for string based fields. + * An implementation for retrieving {@link FunctionValues} instances for string based fields. */ public class BytesRefFieldSource extends FieldCacheSource { @@ -35,7 +35,7 @@ public class BytesRefFieldSource extends FieldCacheSource { } @Override - public DocValues getValues(Map context, IndexReader.AtomicReaderContext readerContext) throws IOException { + public FunctionValues getValues(Map context, IndexReader.AtomicReaderContext readerContext) throws IOException { return new StringIndexDocValues(this, readerContext, field) { @Override diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstValueSource.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstValueSource.java index 869469577f1..4631a9aee0a 100755 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstValueSource.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ConstValueSource.java @@ -18,7 +18,7 @@ package org.apache.lucene.queries.function.valuesource; import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.docvalues.FloatDocValues; import java.io.IOException; @@ -42,7 +42,7 @@ public class ConstValueSource extends ConstNumberSource { } @Override - public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { + public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { return new FloatDocValues(this) { @Override public float floatVal(int doc) { diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java index 1b133a1c1b7..aa1cfe3845d 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/DefFunction.java @@ -17,7 +17,7 @@ package org.apache.lucene.queries.function.valuesource; */ import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.util.BytesRef; @@ -39,15 +39,15 @@ public class DefFunction extends MultiFunction { @Override - public DocValues getValues(Map fcontext, AtomicReaderContext readerContext) throws IOException { + public FunctionValues getValues(Map fcontext, AtomicReaderContext readerContext) throws IOException { return new Values(valsArr(sources, fcontext, readerContext)) { final int upto = valsArr.length - 1; - private DocValues get(int doc) { + private FunctionValues get(int doc) { for (int i=0; i sources, Map fcontext, AtomicReaderContext readerContext) throws IOException { - final DocValues[] valsArr = new DocValues[sources.size()]; + public static FunctionValues[] valsArr(List sources, Map fcontext, AtomicReaderContext readerContext) throws IOException { + final FunctionValues[] valsArr = new FunctionValues[sources.size()]; int i=0; for (ValueSource source : sources) { valsArr[i++] = source.getValues(fcontext, readerContext); @@ -67,10 +67,10 @@ public abstract class MultiFunction extends ValueSource { return valsArr; } - public class Values extends DocValues { - final DocValues[] valsArr; + public class Values extends FunctionValues { + final FunctionValues[] valsArr; - public Values(DocValues[] valsArr) { + public Values(FunctionValues[] valsArr) { this.valsArr = valsArr; } @@ -87,11 +87,11 @@ public abstract class MultiFunction extends ValueSource { } - public static String toString(String name, DocValues[] valsArr, int doc) { + public static String toString(String name, FunctionValues[] valsArr, int doc) { StringBuilder sb = new StringBuilder(); sb.append(name).append('('); boolean firstTime=true; - for (DocValues vals : valsArr) { + for (FunctionValues vals : valsArr) { if (firstTime) { firstTime=false; } else { diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java index 81fa80eadff..755fbb4ba23 100755 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NormValueSource.java @@ -18,7 +18,7 @@ package org.apache.lucene.queries.function.valuesource; import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.docvalues.FloatDocValues; import org.apache.lucene.search.IndexSearcher; @@ -49,7 +49,7 @@ public class NormValueSource extends ValueSource { } @Override - public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { + public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { IndexSearcher searcher = (IndexSearcher)context.get("searcher"); Similarity sim = searcher.getSimilarityProvider().get(field); if (!(sim instanceof TFIDFSimilarity)) { diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumDocsValueSource.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumDocsValueSource.java index 768ade0031c..eadf8663229 100755 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumDocsValueSource.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumDocsValueSource.java @@ -17,7 +17,7 @@ package org.apache.lucene.queries.function.valuesource; import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.util.ReaderUtil; @@ -35,7 +35,7 @@ public class NumDocsValueSource extends ValueSource { } @Override - public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { + public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { // Searcher has no numdocs so we must use the reader instead return new ConstIntDocValues(ReaderUtil.getTopLevelContext(readerContext).reader.numDocs(), this); } diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericIndexDocValueSource.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericIndexDocValueSource.java index 2c95813dfca..38b01cccd30 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericIndexDocValueSource.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/NumericIndexDocValueSource.java @@ -22,13 +22,13 @@ import java.util.Map; import org.apache.lucene.index.DocValues.Source; import org.apache.lucene.index.DocValues.Type; import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; /** - * Expert: obtains numeric field values from a {@link DocValues} field. + * Expert: obtains numeric field values from a {@link FunctionValues} field. * This {@link ValueSource} is compatible with all numerical - * {@link DocValues} + * {@link FunctionValues} * * @lucene.experimental * @@ -42,7 +42,7 @@ public class NumericIndexDocValueSource extends ValueSource { } @Override - public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { + public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { final Source source = readerContext.reader.docValues(field) .getSource(); Type type = source.type(); @@ -50,7 +50,7 @@ public class NumericIndexDocValueSource extends ValueSource { case FLOAT_32: case FLOAT_64: // TODO (chrism) Change to use FloatDocValues and IntDocValues - return new DocValues() { + return new FunctionValues() { @Override public String toString(int doc) { @@ -64,7 +64,7 @@ public class NumericIndexDocValueSource extends ValueSource { }; case VAR_INTS: - return new DocValues() { + return new FunctionValues() { @Override public String toString(int doc) { return "float: [" + floatVal(doc) + "]"; @@ -113,6 +113,6 @@ public class NumericIndexDocValueSource extends ValueSource { @Override public String toString() { - return "DocValues float(" + field + ')'; + return "FunctionValues float(" + field + ')'; } } diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java index f4379570d91..09083004231 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/OrdFieldSource.java @@ -19,7 +19,7 @@ package org.apache.lucene.queries.function.valuesource; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.docvalues.IntDocValues; import org.apache.lucene.search.FieldCache; @@ -62,7 +62,7 @@ public class OrdFieldSource extends ValueSource { @Override - public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { + public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { final int off = readerContext.docBase; final IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader; final FieldCache.DocTermsIndex sindex = FieldCache.DEFAULT.getTermsIndex(topReader, field); diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/PowFloatFunction.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/PowFloatFunction.java index ec2ae94391b..a65b4d25d46 100755 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/PowFloatFunction.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/PowFloatFunction.java @@ -17,7 +17,7 @@ package org.apache.lucene.queries.function.valuesource; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; /** Function to raise the base "a" to the power "b" @@ -37,7 +37,7 @@ public class PowFloatFunction extends DualFloatFunction { } @Override - protected float func(int doc, DocValues aVals, DocValues bVals) { + protected float func(int doc, FunctionValues aVals, FunctionValues bVals) { return (float)Math.pow(aVals.floatVal(doc), bVals.floatVal(doc)); } } diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ProductFloatFunction.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ProductFloatFunction.java index 5aa02540cd1..102fff97cb0 100755 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ProductFloatFunction.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ProductFloatFunction.java @@ -17,7 +17,7 @@ package org.apache.lucene.queries.function.valuesource; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; /** @@ -34,9 +34,9 @@ public class ProductFloatFunction extends MultiFloatFunction { } @Override - protected float func(int doc, DocValues[] valsArr) { + protected float func(int doc, FunctionValues[] valsArr) { float val = 1.0f; - for (DocValues vals : valsArr) { + for (FunctionValues vals : valsArr) { val *= vals.floatVal(doc); } return val; diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java index fb6f2c78f84..92b8f70a3d3 100755 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java @@ -18,7 +18,7 @@ package org.apache.lucene.queries.function.valuesource; import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.docvalues.FloatDocValues; import org.apache.lucene.search.*; @@ -51,7 +51,7 @@ public class QueryValueSource extends ValueSource { } @Override - public DocValues getValues(Map fcontext, AtomicReaderContext readerContext) throws IOException { + public FunctionValues getValues(Map fcontext, AtomicReaderContext readerContext) throws IOException { return new QueryDocValues(this, readerContext, fcontext); } @@ -193,8 +193,8 @@ class QueryDocValues extends FloatDocValues { public ValueFiller getValueFiller() { // // TODO: if we want to support more than one value-filler or a value-filler in conjunction with - // the DocValues, then members like "scorer" should be per ValueFiller instance. - // Or we can say that the user should just instantiate multiple DocValues. + // the FunctionValues, then members like "scorer" should be per ValueFiller instance. + // Or we can say that the user should just instantiate multiple FunctionValues. // return new ValueFiller() { private final MutableValueFloat mval = new MutableValueFloat(); diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.java index 95203a727af..c5ad99907b3 100755 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.java @@ -18,7 +18,7 @@ package org.apache.lucene.queries.function.valuesource; import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.docvalues.FloatDocValues; import org.apache.lucene.search.IndexSearcher; @@ -55,8 +55,8 @@ public class RangeMapFloatFunction extends ValueSource { } @Override - public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { - final DocValues vals = source.getValues(context, readerContext); + public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { + final FunctionValues vals = source.getValues(context, readerContext); return new FloatDocValues(this) { @Override public float floatVal(int doc) { diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ReciprocalFloatFunction.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ReciprocalFloatFunction.java index 98596e66dca..246c5b6e250 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ReciprocalFloatFunction.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ReciprocalFloatFunction.java @@ -18,7 +18,7 @@ package org.apache.lucene.queries.function.valuesource; import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.docvalues.FloatDocValues; import org.apache.lucene.search.IndexSearcher; @@ -61,8 +61,8 @@ public class ReciprocalFloatFunction extends ValueSource { } @Override - public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { - final DocValues vals = source.getValues(context, readerContext); + public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { + final FunctionValues vals = source.getValues(context, readerContext); return new FloatDocValues(this) { @Override public float floatVal(int doc) { diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java index 56d876d383d..a54e15512a3 100644 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ReverseOrdFieldSource.java @@ -19,7 +19,7 @@ package org.apache.lucene.queries.function.valuesource; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.docvalues.IntDocValues; import org.apache.lucene.search.FieldCache; @@ -62,7 +62,7 @@ public class ReverseOrdFieldSource extends ValueSource { } @Override - public DocValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { + public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { final IndexReader topReader = ReaderUtil.getTopLevelContext(readerContext).reader; final int off = readerContext.docBase; diff --git a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ScaleFloatFunction.java b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ScaleFloatFunction.java index 6e2330a006b..a26f88acdd7 100755 --- a/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ScaleFloatFunction.java +++ b/modules/queries/src/java/org/apache/lucene/queries/function/valuesource/ScaleFloatFunction.java @@ -18,7 +18,7 @@ package org.apache.lucene.queries.function.valuesource; import org.apache.lucene.index.IndexReader.AtomicReaderContext; -import org.apache.lucene.queries.function.DocValues; +import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.docvalues.FloatDocValues; import org.apache.lucene.search.IndexSearcher; @@ -67,7 +67,7 @@ public class ScaleFloatFunction extends ValueSource { for (AtomicReaderContext leaf : leaves) { int maxDoc = leaf.reader.maxDoc(); - DocValues vals = source.getValues(context, leaf); + FunctionValues vals = source.getValues(context, leaf); for (int i=0; i