diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 67e4a6be5d5..b7a292e12cc 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -248,6 +248,12 @@ New Features * LUCENE-5063: FieldCache.DEFAULT.get(Ints|Longs) now uses bit-packing to save memory. (Adrien Grand) + +API Changes + +* LUCENE-5077: Make it easier to use compressed norms. Lucene42NormsFormat takes + an overhead parameter, so you can easily pass a different value other than + PackedInts.FASTEST from your own codec. (Robert Muir) Build diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesFormat.java index bb384c7d0ab..3e81004493d 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesFormat.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42DocValuesFormat.java @@ -120,16 +120,33 @@ import org.apache.lucene.util.packed.BlockPackedWriter; * */ public final class Lucene42DocValuesFormat extends DocValuesFormat { - - /** Sole constructor */ + final float acceptableOverheadRatio; + + /** + * Calls {@link #Lucene42DocValuesFormat(float) + * Lucene42DocValuesFormat(PackedInts.DEFAULT)} + */ public Lucene42DocValuesFormat() { + this(PackedInts.DEFAULT); + } + + /** + * Creates a new Lucene42DocValuesFormat with the specified + * acceptableOverheadRatio for NumericDocValues. + * @param acceptableOverheadRatio compression parameter for numerics. + * Currently this is only used when the number of unique values is small. + * + * @lucene.experimental + */ + public Lucene42DocValuesFormat(float acceptableOverheadRatio) { super("Lucene42"); + this.acceptableOverheadRatio = acceptableOverheadRatio; } @Override public DocValuesConsumer fieldsConsumer(SegmentWriteState state) throws IOException { // note: we choose DEFAULT here (its reasonably fast, and for small bpv has tiny waste) - return new Lucene42DocValuesConsumer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION, PackedInts.DEFAULT); + return new Lucene42DocValuesConsumer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION, acceptableOverheadRatio); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsFormat.java index 9c07bc3e5e1..a7c8c1a2aa7 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsFormat.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsFormat.java @@ -42,14 +42,32 @@ import org.apache.lucene.util.packed.PackedInts; * @see Lucene42DocValuesFormat */ public final class Lucene42NormsFormat extends NormsFormat { + final float acceptableOverheadRatio; - /** Sole constructor */ - public Lucene42NormsFormat() {} + /** + * Calls {@link #Lucene42NormsFormat(float) + * Lucene42DocValuesFormat(PackedInts.FASTEST)} + */ + public Lucene42NormsFormat() { + // note: we choose FASTEST here (otherwise our norms are half as big but 15% slower than previous lucene) + this(PackedInts.FASTEST); + } + + /** + * Creates a new Lucene42DocValuesFormat with the specified + * acceptableOverheadRatio for NumericDocValues. + * @param acceptableOverheadRatio compression parameter for numerics. + * Currently this is only used when the number of unique values is small. + * + * @lucene.experimental + */ + public Lucene42NormsFormat(float acceptableOverheadRatio) { + this.acceptableOverheadRatio = acceptableOverheadRatio; + } @Override public DocValuesConsumer normsConsumer(SegmentWriteState state) throws IOException { - // note: we choose FASTEST here (otherwise our norms are half as big but 15% slower than previous lucene) - return new Lucene42DocValuesConsumer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION, PackedInts.FASTEST); + return new Lucene42DocValuesConsumer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION, acceptableOverheadRatio); } @Override diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastCompressingCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastCompressingCodec.java index 252ba5d0fa3..24f41ab2995 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastCompressingCodec.java +++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastCompressingCodec.java @@ -1,5 +1,11 @@ package org.apache.lucene.codecs.compressing; +import org.apache.lucene.codecs.DocValuesFormat; +import org.apache.lucene.codecs.NormsFormat; +import org.apache.lucene.codecs.lucene42.Lucene42DocValuesFormat; +import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat; +import org.apache.lucene.util.packed.PackedInts; + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,4 +38,13 @@ public class FastCompressingCodec extends CompressingCodec { this(1 << 14, false); } + @Override + public NormsFormat normsFormat() { + return new Lucene42NormsFormat(PackedInts.FAST); + } + + @Override + public DocValuesFormat docValuesFormat() { + return new Lucene42DocValuesFormat(PackedInts.FAST); + } } diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastDecompressionCompressingCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastDecompressionCompressingCodec.java index 568a649289e..7c6ba48f91d 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastDecompressionCompressingCodec.java +++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastDecompressionCompressingCodec.java @@ -1,5 +1,11 @@ package org.apache.lucene.codecs.compressing; +import org.apache.lucene.codecs.DocValuesFormat; +import org.apache.lucene.codecs.NormsFormat; +import org.apache.lucene.codecs.lucene42.Lucene42DocValuesFormat; +import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat; +import org.apache.lucene.util.packed.PackedInts; + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,4 +38,13 @@ public class FastDecompressionCompressingCodec extends CompressingCodec { this(1 << 14, false); } + @Override + public NormsFormat normsFormat() { + return new Lucene42NormsFormat(PackedInts.DEFAULT); + } + + @Override + public DocValuesFormat docValuesFormat() { + return new Lucene42DocValuesFormat(PackedInts.DEFAULT); + } } diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/HighCompressionCompressingCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/HighCompressionCompressingCodec.java index fb235f95218..2f1fc293592 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/HighCompressionCompressingCodec.java +++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/HighCompressionCompressingCodec.java @@ -1,5 +1,9 @@ package org.apache.lucene.codecs.compressing; +import org.apache.lucene.codecs.NormsFormat; +import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat; +import org.apache.lucene.util.packed.PackedInts; + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -32,4 +36,8 @@ public class HighCompressionCompressingCodec extends CompressingCodec { this(1 << 14, false); } + @Override + public NormsFormat normsFormat() { + return new Lucene42NormsFormat(PackedInts.COMPACT); + } }