Apache Solr open-source search software
LUCENE-7028: Remove duplicate method in LegacyNumericUtils
Uwe Schindler74421d729b5a
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex aa603ba0d84..8a34d07fcf9 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -90,6 +90,9 @@ API Changes* LUCENE-6947: SortField.missingValue is now protected. You can read its valueusing the new SortField.getMissingValue getter. (Adrien Grand)+* LUCENE-7028: Remove duplicate method in LegacyNumericUtils.+ (Uwe Schindler)+Optimizations* LUCENE-6891: Use prefix coding when writing points indiff --git a/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java b/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.javaindex 3cada71feeb..b41b5f07398 100644--- a/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java+++ b/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java@@ -91,7 +91,7 @@ public final class LegacyNumericUtils {/*** The maximum term length (used for <code>byte[]</code> buffer size)* for encoding <code>long</code> values.- * @see #longToPrefixCodedBytes+ * @see #longToPrefixCoded*/public static final int BUF_SIZE_LONG = 63/7 + 2;@@ -104,7 +104,7 @@ public final class LegacyNumericUtils {/*** The maximum term length (used for <code>byte[]</code> buffer size)* for encoding <code>int</code> values.- * @see #intToPrefixCodedBytes+ * @see #intToPrefixCoded*/public static final int BUF_SIZE_INT = 31/7 + 2;@@ -117,30 +117,6 @@ public final class LegacyNumericUtils {* @param bytes will contain the encoded value*/public static void longToPrefixCoded(final long val, final int shift, final BytesRefBuilder bytes) {- longToPrefixCodedBytes(val, shift, bytes);- }-- /**- * Returns prefix coded bits after reducing the precision by <code>shift</code> bits.- * This is method is used by {@link org.apache.lucene.analysis.LegacyNumericTokenStream}.- * After encoding, {@code bytes.offset} will always be 0.- * @param val the numeric value- * @param shift how many bits to strip from the right- * @param bytes will contain the encoded value- */- public static void intToPrefixCoded(final int val, final int shift, final BytesRefBuilder bytes) {- intToPrefixCodedBytes(val, shift, bytes);- }-- /**- * Returns prefix coded bits after reducing the precision by <code>shift</code> bits.- * This is method is used by {@link org.apache.lucene.analysis.LegacyNumericTokenStream}.- * After encoding, {@code bytes.offset} will always be 0.- * @param val the numeric value- * @param shift how many bits to strip from the right- * @param bytes will contain the encoded value- */- public static void longToPrefixCodedBytes(final long val, final int shift, final BytesRefBuilder bytes) {// ensure shift is 0..63if ((shift & ~0x3f) != 0) {throw new IllegalArgumentException("Illegal shift value, must be 0..63; got shift=" + shift);@@ -159,16 +135,15 @@ public final class LegacyNumericUtils {}}-/*** Returns prefix coded bits after reducing the precision by <code>shift</code> bits.* This is method is used by {@link org.apache.lucene.analysis.LegacyNumericTokenStream}.- * After encoding, {@code bytes.offset} will always be 0.+ * After encoding, {@code bytes.offset} will always be 0.* @param val the numeric value* @param shift how many bits to strip from the right* @param bytes will contain the encoded value*/- public static void intToPrefixCodedBytes(final int val, final int shift, final BytesRefBuilder bytes) {+ public static void intToPrefixCoded(final int val, final int shift, final BytesRefBuilder bytes) {// ensure shift is 0..31if ((shift & ~0x1f) != 0) {throw new IllegalArgumentException("Illegal shift value, must be 0..31; got shift=" + shift);@@ -218,7 +193,7 @@ public final class LegacyNumericUtils {* This method can be used to decode a term's value.* @throws NumberFormatException if the supplied {@link BytesRef} is* not correctly prefix encoded.- * @see #longToPrefixCodedBytes+ * @see #longToPrefixCoded*/public static long prefixCodedToLong(final BytesRef val) {long sortableBits = 0L;@@ -242,7 +217,7 @@ public final class LegacyNumericUtils {* This method can be used to decode a term's value.* @throws NumberFormatException if the supplied {@link BytesRef} is* not correctly prefix encoded.- * @see #intToPrefixCodedBytes+ * @see #intToPrefixCoded*/public static int prefixCodedToInt(final BytesRef val) {int sortableBits = 0;@@ -427,8 +402,8 @@ public final class LegacyNumericUtils {*/public void addRange(final long min, final long max, final int shift) {final BytesRefBuilder minBytes = new BytesRefBuilder(), maxBytes = new BytesRefBuilder();- longToPrefixCodedBytes(min, shift, minBytes);- longToPrefixCodedBytes(max, shift, maxBytes);+ longToPrefixCoded(min, shift, minBytes);+ longToPrefixCoded(max, shift, maxBytes);addRange(minBytes.get(), maxBytes.get());}@@ -456,8 +431,8 @@ public final class LegacyNumericUtils {*/public void addRange(final int min, final int max, final int shift) {final BytesRefBuilder minBytes = new BytesRefBuilder(), maxBytes = new BytesRefBuilder();- intToPrefixCodedBytes(min, shift, minBytes);- intToPrefixCodedBytes(max, shift, maxBytes);+ intToPrefixCoded(min, shift, minBytes);+ intToPrefixCoded(max, shift, maxBytes);addRange(minBytes.get(), maxBytes.get());}diff --git a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.javaindex 3ddff3ac8a5..b9d5197e8df 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java@@ -361,9 +361,9 @@ public class TestNumericRangeQuery32 extends LuceneTestCase {}final BytesRef lowerBytes, upperBytes;BytesRefBuilder b = new BytesRefBuilder();- LegacyNumericUtils.intToPrefixCodedBytes(lower, 0, b);+ LegacyNumericUtils.intToPrefixCoded(lower, 0, b);lowerBytes = b.toBytesRef();- LegacyNumericUtils.intToPrefixCodedBytes(upper, 0, b);+ LegacyNumericUtils.intToPrefixCoded(upper, 0, b);upperBytes = b.toBytesRef();// test inclusive rangediff --git a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.javaindex 19ff2404b5c..7d03fae5406 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java@@ -385,9 +385,9 @@ public class TestNumericRangeQuery64 extends LuceneTestCase {}final BytesRef lowerBytes, upperBytes;BytesRefBuilder b = new BytesRefBuilder();- LegacyNumericUtils.longToPrefixCodedBytes(lower, 0, b);+ LegacyNumericUtils.longToPrefixCoded(lower, 0, b);lowerBytes = b.toBytesRef();- LegacyNumericUtils.longToPrefixCodedBytes(upper, 0, b);+ LegacyNumericUtils.longToPrefixCoded(upper, 0, b);upperBytes = b.toBytesRef();// test inclusive rangediff --git a/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java b/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.javaindex ce32352aab4..1d9c41ed86f 100644--- a/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java+++ b/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java@@ -29,7 +29,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {BytesRefBuilder last = new BytesRefBuilder();BytesRefBuilder act = new BytesRefBuilder();for (long l=-100000L; l<100000L; l++) {- LegacyNumericUtils.longToPrefixCodedBytes(l, 0, act);+ LegacyNumericUtils.longToPrefixCoded(l, 0, act);if (last!=null) {// test if smallerassertTrue("actual bigger than last (BytesRef)", last.get().compareTo(act.get()) < 0 );@@ -47,7 +47,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {BytesRefBuilder act = new BytesRefBuilder();BytesRefBuilder last = new BytesRefBuilder();for (int i=-100000; i<100000; i++) {- LegacyNumericUtils.intToPrefixCodedBytes(i, 0, act);+ LegacyNumericUtils.intToPrefixCoded(i, 0, act);if (last!=null) {// test if smallerassertTrue("actual bigger than last (BytesRef)", last.get().compareTo(act.get()) < 0 );@@ -69,7 +69,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {for (int i=0; i<vals.length; i++) {prefixVals[i] = new BytesRefBuilder();- LegacyNumericUtils.longToPrefixCodedBytes(vals[i], 0, prefixVals[i]);+ LegacyNumericUtils.longToPrefixCoded(vals[i], 0, prefixVals[i]);// check forward and back conversionassertEquals( "forward and back conversion should generate same long", vals[i], LegacyNumericUtils.prefixCodedToLong(prefixVals[i].get()) );@@ -92,7 +92,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {final BytesRefBuilder ref = new BytesRefBuilder();for (int i=0; i<vals.length; i++) {for (int j=0; j<64; j++) {- LegacyNumericUtils.longToPrefixCodedBytes(vals[i], j, ref);+ LegacyNumericUtils.longToPrefixCoded(vals[i], j, ref);long prefixVal= LegacyNumericUtils.prefixCodedToLong(ref.get());long mask=(1L << j) - 1L;assertEquals( "difference between prefix val and original value for "+vals[i]+" with shift="+j, vals[i] & mask, vals[i]-prefixVal );@@ -109,7 +109,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {for (int i=0; i<vals.length; i++) {prefixVals[i] = new BytesRefBuilder();- LegacyNumericUtils.intToPrefixCodedBytes(vals[i], 0, prefixVals[i]);+ LegacyNumericUtils.intToPrefixCoded(vals[i], 0, prefixVals[i]);// check forward and back conversionassertEquals( "forward and back conversion should generate same int", vals[i], LegacyNumericUtils.prefixCodedToInt(prefixVals[i].get()) );@@ -132,7 +132,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {final BytesRefBuilder ref = new BytesRefBuilder();for (int i=0; i<vals.length; i++) {for (int j=0; j<32; j++) {- LegacyNumericUtils.intToPrefixCodedBytes(vals[i], j, ref);+ LegacyNumericUtils.intToPrefixCoded(vals[i], j, ref);int prefixVal= LegacyNumericUtils.prefixCodedToInt(ref.get());int mask=(1 << j) - 1;assertEquals( "difference between prefix val and original value for "+vals[i]+" with shift="+j, vals[i] & mask, vals[i]-prefixVal );diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.javaindex 35b75a65b00..e331c8a2683 100644--- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java@@ -616,7 +616,7 @@ public class TestBlockJoin extends LuceneTestCase {if (VERBOSE) {System.out.println("DELETE parentID=" + deleteID);}- LegacyNumericUtils.intToPrefixCodedBytes(deleteID, 0, term);+ LegacyNumericUtils.intToPrefixCoded(deleteID, 0, term);w.deleteDocuments(new Term("blockID", term.toBytesRef()));joinW.deleteDocuments(new Term("blockID", term.toBytesRef()));}diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.javaindex 9bae0dcf321..869aa318244 100644--- a/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java@@ -581,7 +581,7 @@ public class BBoxStrategy extends SpatialStrategy {private Query makeNumberTermQuery(String field, double number) {BytesRefBuilder bytes = new BytesRefBuilder();- LegacyNumericUtils.longToPrefixCodedBytes(LegacyNumericUtils.doubleToSortableLong(number), 0, bytes);+ LegacyNumericUtils.longToPrefixCoded(LegacyNumericUtils.doubleToSortableLong(number), 0, bytes);return new TermQuery(new Term(field, bytes.get()));}diff --git a/solr/core/src/java/org/apache/solr/schema/TrieField.java b/solr/core/src/java/org/apache/solr/schema/TrieField.javaindex 862d58f87ea..b369e999a89 100644--- a/solr/core/src/java/org/apache/solr/schema/TrieField.java+++ b/solr/core/src/java/org/apache/solr/schema/TrieField.java@@ -463,19 +463,19 @@ public class TrieField extends PrimitiveFieldType {try {switch (type) {case INTEGER:- LegacyNumericUtils.intToPrefixCodedBytes(Integer.parseInt(s), 0, result);+ LegacyNumericUtils.intToPrefixCoded(Integer.parseInt(s), 0, result);break;case FLOAT:- LegacyNumericUtils.intToPrefixCodedBytes(LegacyNumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, result);+ LegacyNumericUtils.intToPrefixCoded(LegacyNumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, result);break;case LONG:- LegacyNumericUtils.longToPrefixCodedBytes(Long.parseLong(s), 0, result);+ LegacyNumericUtils.longToPrefixCoded(Long.parseLong(s), 0, result);break;case DOUBLE:- LegacyNumericUtils.longToPrefixCodedBytes(LegacyNumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, result);+ LegacyNumericUtils.longToPrefixCoded(LegacyNumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, result);break;case DATE:- LegacyNumericUtils.longToPrefixCodedBytes(DateFormatUtil.parseMath(null, s).getTime(), 0, result);+ LegacyNumericUtils.longToPrefixCoded(DateFormatUtil.parseMath(null, s).getTime(), 0, result);break;default:throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);@@ -580,17 +580,17 @@ public class TrieField extends PrimitiveFieldType {if (val != null) {switch (type) {case INTEGER:- LegacyNumericUtils.intToPrefixCodedBytes(val.intValue(), 0, bytes);+ LegacyNumericUtils.intToPrefixCoded(val.intValue(), 0, bytes);break;case FLOAT:- LegacyNumericUtils.intToPrefixCodedBytes(LegacyNumericUtils.floatToSortableInt(val.floatValue()), 0, bytes);+ LegacyNumericUtils.intToPrefixCoded(LegacyNumericUtils.floatToSortableInt(val.floatValue()), 0, bytes);break;case LONG: //fallthrough!case DATE:- LegacyNumericUtils.longToPrefixCodedBytes(val.longValue(), 0, bytes);+ LegacyNumericUtils.longToPrefixCoded(val.longValue(), 0, bytes);break;case DOUBLE:- LegacyNumericUtils.longToPrefixCodedBytes(LegacyNumericUtils.doubleToSortableLong(val.doubleValue()), 0, bytes);+ LegacyNumericUtils.longToPrefixCoded(LegacyNumericUtils.doubleToSortableLong(val.doubleValue()), 0, bytes);break;default:throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + f.name());@@ -602,7 +602,7 @@ public class TrieField extends PrimitiveFieldType {throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Invalid field contents: "+f.name());switch (type) {case INTEGER:- LegacyNumericUtils.intToPrefixCodedBytes(toInt(bytesRef.bytes, bytesRef.offset), 0, bytes);+ LegacyNumericUtils.intToPrefixCoded(toInt(bytesRef.bytes, bytesRef.offset), 0, bytes);break;case FLOAT: {// WARNING: Code Duplication! Keep in sync with o.a.l.util.LegacyNumericUtils!@@ -610,12 +610,12 @@ public class TrieField extends PrimitiveFieldType {// code in next 2 lines is identical to: int v = LegacyNumericUtils.floatToSortableInt(Float.intBitsToFloat(toInt(arr)));int v = toInt(bytesRef.bytes, bytesRef.offset);if (v<0) v ^= 0x7fffffff;- LegacyNumericUtils.intToPrefixCodedBytes(v, 0, bytes);+ LegacyNumericUtils.intToPrefixCoded(v, 0, bytes);break;}case LONG: //fallthrough!case DATE:- LegacyNumericUtils.longToPrefixCodedBytes(toLong(bytesRef.bytes, bytesRef.offset), 0, bytes);+ LegacyNumericUtils.longToPrefixCoded(toLong(bytesRef.bytes, bytesRef.offset), 0, bytes);break;case DOUBLE: {// WARNING: Code Duplication! Keep in sync with o.a.l.util.LegacyNumericUtils!@@ -623,7 +623,7 @@ public class TrieField extends PrimitiveFieldType {// code in next 2 lines is identical to: long v = LegacyNumericUtils.doubleToSortableLong(Double.longBitsToDouble(toLong(arr)));long v = toLong(bytesRef.bytes, bytesRef.offset);if (v<0) v ^= 0x7fffffffffffffffL;- LegacyNumericUtils.longToPrefixCodedBytes(v, 0, bytes);+ LegacyNumericUtils.longToPrefixCoded(v, 0, bytes);break;}default: