Index: solr/core/src/java/org/apache/solr/schema/TrieField.java =================================================================== --- solr/core/src/java/org/apache/solr/schema/TrieField.java (revision 1437743) +++ solr/core/src/java/org/apache/solr/schema/TrieField.java (working copy) @@ -29,8 +29,6 @@ import org.apache.lucene.document.FloatField; import org.apache.lucene.document.IntField; import org.apache.lucene.document.LongField; -import org.apache.lucene.index.GeneralField; -import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.StorableField; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.valuesource.DoubleFieldSource; @@ -48,7 +46,6 @@ import org.apache.solr.common.SolrException; import org.apache.solr.response.TextResponseWriter; import org.apache.solr.search.QParser; -import org.apache.solr.search.function.*; /** * Provides field types to support for Lucene's {@link @@ -311,19 +308,19 @@ String s = val.toString(); switch (type) { case INTEGER: - NumericUtils.intToPrefixCoded(Integer.parseInt(s), 0, result); + NumericUtils.intToPrefixCodedBytes(Integer.parseInt(s), 0, result); break; case FLOAT: - NumericUtils.intToPrefixCoded(NumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, result); + NumericUtils.intToPrefixCodedBytes(NumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, result); break; case LONG: - NumericUtils.longToPrefixCoded(Long.parseLong(s), 0, result); + NumericUtils.longToPrefixCodedBytes(Long.parseLong(s), 0, result); break; case DOUBLE: - NumericUtils.longToPrefixCoded(NumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, result); + NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, result); break; case DATE: - NumericUtils.longToPrefixCoded(dateField.parseMath(null, s).getTime(), 0, result); + NumericUtils.longToPrefixCodedBytes(dateField.parseMath(null, s).getTime(), 0, result); break; default: throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type); @@ -419,17 +416,17 @@ if (val != null) { switch (type) { case INTEGER: - NumericUtils.intToPrefixCoded(val.intValue(), 0, bytes); + NumericUtils.intToPrefixCodedBytes(val.intValue(), 0, bytes); break; case FLOAT: - NumericUtils.intToPrefixCoded(NumericUtils.floatToSortableInt(val.floatValue()), 0, bytes); + NumericUtils.intToPrefixCodedBytes(NumericUtils.floatToSortableInt(val.floatValue()), 0, bytes); break; case LONG: //fallthrough! case DATE: - NumericUtils.longToPrefixCoded(val.longValue(), 0, bytes); + NumericUtils.longToPrefixCodedBytes(val.longValue(), 0, bytes); break; case DOUBLE: - NumericUtils.longToPrefixCoded(NumericUtils.doubleToSortableLong(val.doubleValue()), 0, bytes); + NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(val.doubleValue()), 0, bytes); break; default: throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + f.name()); @@ -441,7 +438,7 @@ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Invalid field contents: "+f.name()); switch (type) { case INTEGER: - NumericUtils.intToPrefixCoded(toInt(bytesRef.bytes, bytesRef.offset), 0, bytes); + NumericUtils.intToPrefixCodedBytes(toInt(bytesRef.bytes, bytesRef.offset), 0, bytes); break; case FLOAT: { // WARNING: Code Duplication! Keep in sync with o.a.l.util.NumericUtils! @@ -449,12 +446,12 @@ // code in next 2 lines is identical to: int v = NumericUtils.floatToSortableInt(Float.intBitsToFloat(toInt(arr))); int v = toInt(bytesRef.bytes, bytesRef.offset); if (v<0) v ^= 0x7fffffff; - NumericUtils.intToPrefixCoded(v, 0, bytes); + NumericUtils.intToPrefixCodedBytes(v, 0, bytes); break; } case LONG: //fallthrough! case DATE: - NumericUtils.longToPrefixCoded(toLong(bytesRef.bytes, bytesRef.offset), 0, bytes); + NumericUtils.longToPrefixCodedBytes(toLong(bytesRef.bytes, bytesRef.offset), 0, bytes); break; case DOUBLE: { // WARNING: Code Duplication! Keep in sync with o.a.l.util.NumericUtils! @@ -462,7 +459,7 @@ // code in next 2 lines is identical to: long v = NumericUtils.doubleToSortableLong(Double.longBitsToDouble(toLong(arr))); long v = toLong(bytesRef.bytes, bytesRef.offset); if (v<0) v ^= 0x7fffffffffffffffL; - NumericUtils.longToPrefixCoded(v, 0, bytes); + NumericUtils.longToPrefixCodedBytes(v, 0, bytes); break; } default: Index: lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java =================================================================== --- lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (revision 1437743) +++ lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java (working copy) @@ -380,8 +380,8 @@ int a=lower; lower=upper; upper=a; } final BytesRef lowerBytes = new BytesRef(NumericUtils.BUF_SIZE_INT), upperBytes = new BytesRef(NumericUtils.BUF_SIZE_INT); - NumericUtils.intToPrefixCoded(lower, 0, lowerBytes); - NumericUtils.intToPrefixCoded(upper, 0, upperBytes); + NumericUtils.intToPrefixCodedBytes(lower, 0, lowerBytes); + NumericUtils.intToPrefixCodedBytes(upper, 0, upperBytes); // test inclusive range NumericRangeQuery tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, true, true); Index: lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java =================================================================== --- lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java (revision 1437743) +++ lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java (working copy) @@ -405,8 +405,8 @@ long a=lower; lower=upper; upper=a; } final BytesRef lowerBytes = new BytesRef(NumericUtils.BUF_SIZE_LONG), upperBytes = new BytesRef(NumericUtils.BUF_SIZE_LONG); - NumericUtils.longToPrefixCoded(lower, 0, lowerBytes); - NumericUtils.longToPrefixCoded(upper, 0, upperBytes); + NumericUtils.longToPrefixCodedBytes(lower, 0, lowerBytes); + NumericUtils.longToPrefixCodedBytes(upper, 0, upperBytes); // test inclusive range NumericRangeQuery tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, true); Index: lucene/core/src/test/org/apache/lucene/util/TestNumericUtils.java =================================================================== --- lucene/core/src/test/org/apache/lucene/util/TestNumericUtils.java (revision 1437743) +++ lucene/core/src/test/org/apache/lucene/util/TestNumericUtils.java (working copy) @@ -28,7 +28,7 @@ // generate a series of encoded longs, each numerical one bigger than the one before BytesRef last=null, act=new BytesRef(NumericUtils.BUF_SIZE_LONG); for (long l=-100000L; l<100000L; l++) { - NumericUtils.longToPrefixCoded(l, 0, act); + NumericUtils.longToPrefixCodedBytes(l, 0, act); if (last!=null) { // test if smaller assertTrue("actual bigger than last (BytesRef)", last.compareTo(act) < 0 ); @@ -46,7 +46,7 @@ // generate a series of encoded ints, each numerical one bigger than the one before BytesRef last=null, act=new BytesRef(NumericUtils.BUF_SIZE_INT); for (int i=-100000; i<100000; i++) { - NumericUtils.intToPrefixCoded(i, 0, act); + NumericUtils.intToPrefixCodedBytes(i, 0, act); if (last!=null) { // test if smaller assertTrue("actual bigger than last (BytesRef)", last.compareTo(act) < 0 ); @@ -69,7 +69,7 @@ for (int i=0; i>8) + 1; // i/7 is the same as (i*37)>>8 for i in 0..63 bytes.offset = 0; - bytes.length = nChars+1; + bytes.length = nChars+1; // one extra for the byte that contains the shift info if (bytes.bytes.length < bytes.length) { - bytes.grow(NumericUtils.BUF_SIZE_LONG); + bytes.bytes = new byte[NumericUtils.BUF_SIZE_LONG]; // use the max } - bytes.bytes[0] = (byte) (hash = (SHIFT_START_LONG + shift)); + bytes.bytes[0] = (byte)(SHIFT_START_LONG + shift); long sortableBits = val ^ 0x8000000000000000L; sortableBits >>>= shift; while (nChars > 0) { @@ -126,13 +153,9 @@ bytes.bytes[nChars--] = (byte)(sortableBits & 0x7f); sortableBits >>>= 7; } - // calculate hash - for (int i = 1; i < bytes.length; i++) { - hash = 31*hash + bytes.bytes[i]; - } - return hash; } + /** * Returns prefix coded bits after reducing the precision by shift bits. * This is method is used by {@link NumericTokenStream}. @@ -140,18 +163,17 @@ * @param val the numeric value * @param shift how many bits to strip from the right * @param bytes will contain the encoded value - * @return the hash code for indexing (TermsHash) */ - public static int intToPrefixCoded(final int val, final int shift, final BytesRef bytes) { - if (shift>31 || shift<0) + public static void intToPrefixCodedBytes(final int val, final int shift, final BytesRef bytes) { + if ((shift & ~0x1f) != 0) // ensure shift is 0..31 throw new IllegalArgumentException("Illegal shift value, must be 0..31"); - int hash, nChars = (31-shift)/7 + 1; + int nChars = (((31-shift)*37)>>8) + 1; // i/7 is the same as (i*37)>>8 for i in 0..63 bytes.offset = 0; - bytes.length = nChars+1; + bytes.length = nChars+1; // one extra for the byte that contains the shift info if (bytes.bytes.length < bytes.length) { - bytes.grow(NumericUtils.BUF_SIZE_INT); + bytes.bytes = new byte[NumericUtils.BUF_SIZE_LONG]; // use the max } - bytes.bytes[0] = (byte) (hash = (SHIFT_START_INT + shift)); + bytes.bytes[0] = (byte)(SHIFT_START_INT + shift); int sortableBits = val ^ 0x80000000; sortableBits >>>= shift; while (nChars > 0) { @@ -160,13 +182,9 @@ bytes.bytes[nChars--] = (byte)(sortableBits & 0x7f); sortableBits >>>= 7; } - // calculate hash - for (int i = 1; i < bytes.length; i++) { - hash = 31*hash + bytes.bytes[i]; - } - return hash; } + /** * Returns the shift value from a prefix encoded {@code long}. * @throws NumberFormatException if the supplied {@link BytesRef} is @@ -197,7 +215,7 @@ * This method can be used to decode a term's value. * @throws NumberFormatException if the supplied {@link BytesRef} is * not correctly prefix encoded. - * @see #longToPrefixCoded(long,int,BytesRef) + * @see #longToPrefixCodedBytes */ public static long prefixCodedToLong(final BytesRef val) { long sortableBits = 0L; @@ -221,7 +239,7 @@ * This method can be used to decode a term's value. * @throws NumberFormatException if the supplied {@link BytesRef} is * not correctly prefix encoded. - * @see #intToPrefixCoded(int,int,BytesRef) + * @see #intToPrefixCodedBytes */ public static int prefixCodedToInt(final BytesRef val) { int sortableBits = 0; @@ -402,8 +420,8 @@ */ public void addRange(final long min, final long max, final int shift) { final BytesRef minBytes = new BytesRef(BUF_SIZE_LONG), maxBytes = new BytesRef(BUF_SIZE_LONG); - longToPrefixCoded(min, shift, minBytes); - longToPrefixCoded(max, shift, maxBytes); + longToPrefixCodedBytes(min, shift, minBytes); + longToPrefixCodedBytes(max, shift, maxBytes); addRange(minBytes, maxBytes); } @@ -431,8 +449,8 @@ */ public void addRange(final int min, final int max, final int shift) { final BytesRef minBytes = new BytesRef(BUF_SIZE_INT), maxBytes = new BytesRef(BUF_SIZE_INT); - intToPrefixCoded(min, shift, minBytes); - intToPrefixCoded(max, shift, maxBytes); + intToPrefixCodedBytes(min, shift, minBytes); + intToPrefixCodedBytes(max, shift, maxBytes); addRange(minBytes, maxBytes); }