You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by 惠达 王 <wa...@yahoo.cn> on 2012/09/21 11:54:05 UTC
I want to know that why transform numeric to string
hi all:
I want to know that why transform numeric to string?
public static int longToPrefixCoded(final long val, final int shift, final
BytesRef bytes) {
if (shift>63 || shift<0)
throw new IllegalArgumentException("Illegal shift value, must be
0..63");
int hash, nChars = (63-shift)/7 + 1;
bytes.offset = 0;
bytes.length = nChars+1;
if (bytes.bytes.length < bytes.length) {
bytes.grow(NumericUtils.BUF_SIZE_LONG);//11
}
bytes.bytes[0] = (byte) (hash = (SHIFT_START_LONG + shift));
long sortableBits = val ^ 0x8000000000000000L;
sortableBits >>>= shift;
while (nChars > 0) {
// Store 7 bits per byte for compatibility
// with UTF-8 encoding of terms
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;
}
���ݴ� (PHP��������ʦ, Sysdev Team)
-------------------------
�ֻ���8836
QQ��429335915
mobile: 13795449454
E-mail: williamwang@anjuke.com
�Ϻ����ֶ�����½���컷·166��δ���ʲ�����10¥
Re: I want to know that why transform numeric to string
Posted by Simon Willnauer <si...@gmail.com>.
quick answer, Lucene only operates on strings (from a high level
perspective)
simon
On Fri, Sep 21, 2012 at 11:54 AM, 惠达 王 <wa...@yahoo.cn> wrote:
> hi all:
> I want to know that why transform numeric to string?
>
> public static int longToPrefixCoded(final long val, final int shift,
> final BytesRef bytes) {
>
> if (shift>63 || shift<0)
>
> throw new IllegalArgumentException("Illegal shift value, must be
> 0..63");
>
> int hash, nChars = (63-shift)/7 + 1;
>
> bytes.offset = 0;
>
> bytes.length = nChars+1;
>
> if (bytes.bytes.length < bytes.length) {
>
> bytes.grow(NumericUtils.BUF_SIZE_LONG);//11
>
> }
>
> bytes.bytes[0] = (byte) (hash = (SHIFT_START_LONG + shift));
>
> long sortableBits = val ^ 0x8000000000000000L;
>
> sortableBits >>>= shift;
>
> while (nChars > 0) {
>
> // Store 7 bits per byte for compatibility
>
> // with UTF-8 encoding of terms
>
> 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;
>
> }
>
>
> 王惠达 (PHP开发工程师, Sysdev Team)
> -------------------------
> 分机:8836
> QQ:429335915
> mobile: 13795449454
> E-mail: williamwang@anjuke.com
> 上海市浦东新区陆家嘴环路166号未来资产大厦10楼
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>