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 Cristian Lorenzetto <cr...@gmail.com> on 2016/08/21 09:50:53 UTC

sorting biginteger

I took a look for bigInteger point but i didnt see no reference for
sorting,
and SortedNumericDocValuesField accept long not biginteger.


I thought to sort so :

BigInteger bi = (BigInteger) o;
byte[] b = bi.toByteArray();
NumericUtils.bigIntToSortableBytes(bi, BigIntegerPoint.BYTES, b, 0);
doc.add(new SortedSetDocValuesField(key, new BytesRef(b)));

it is correct and it is the best practice ?

Re: sorting biginteger

Posted by Michael McCandless <lu...@mikemccandless.com>.
Points cannot sort.  They can only do range queries.

So you need to convert your 128 bit BigInts into a
sort-order-preserving byte[] (BigIntegerPoint.encodeDimension should
do this correctly), and then index that byte[] using a
SortedDocValuesField.
Mike McCandless

http://blog.mikemccandless.com


On Sat, Aug 27, 2016 at 2:19 PM, Cristian Lorenzetto
<cr...@gmail.com> wrote:
> pratically if i understand correctly with  Points you can not only search
> but also to sort values.
> If it is so, for what scope i might to use NumericDocValuesField.
>  My code actually is :
> .......
>  else if (o instanceof Double) {
> final Double i = (Double) o;
> if (docvalue)
> doc.add(new NumericDocValuesField(key, NumericUtils
> .doubleToSortableLong(i)));
>
> doc.add(new DoublePoint(key, i));
> if (storage) {
> doc.add(new StoredField(key, s.serialize(o)));
> }
> }
>
>
>  I wrote so because i my mind i thought
>  Poiint to use if you want to search
>  docvalues if you want to sort /groupby
>  StoredField if you want to store
>
>
> 2016-08-27 20:12 GMT+02:00 Michael McCandless <lu...@mikemccandless.com>:
>>
>> If it's just 128 bit, do exactly what BigIntegerPoint does.
>> Mike McCandless
>>
>> http://blog.mikemccandless.com
>>
>>
>> On Sat, Aug 27, 2016 at 2:03 PM, Cristian Lorenzetto
>> <cr...@gmail.com> wrote:
>> > Good suggestion :) I will do it. In the while i used just for 128bit.
>> >
>> > 2016-08-27 19:51 GMT+02:00 Michael McCandless
>> > <lu...@mikemccandless.com>:
>> >>
>> >> I think to sort properly you must also ensure all byte[] from those
>> >> BigIntegers are the same length, and that you sign extend them?
>> >> Mike McCandless
>> >>
>> >> http://blog.mikemccandless.com
>> >>
>> >>
>> >> On Sun, Aug 21, 2016 at 5:50 AM, Cristian Lorenzetto
>> >> <cr...@gmail.com> wrote:
>> >> > I took a look for bigInteger point but i didnt see no reference for
>> >> > sorting,
>> >> > and SortedNumericDocValuesField accept long not biginteger.
>> >> >
>> >> >
>> >> > I thought to sort so :
>> >> >
>> >> > BigInteger bi = (BigInteger) o;
>> >> > byte[] b = bi.toByteArray();
>> >> > NumericUtils.bigIntToSortableBytes(bi, BigIntegerPoint.BYTES, b, 0);
>> >> > doc.add(new SortedSetDocValuesField(key, new BytesRef(b)));
>> >> >
>> >> > it is correct and it is the best practice ?
>> >
>> >
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: sorting biginteger

Posted by Michael McCandless <lu...@mikemccandless.com>.
If it's just 128 bit, do exactly what BigIntegerPoint does.
Mike McCandless

http://blog.mikemccandless.com


On Sat, Aug 27, 2016 at 2:03 PM, Cristian Lorenzetto
<cr...@gmail.com> wrote:
> Good suggestion :) I will do it. In the while i used just for 128bit.
>
> 2016-08-27 19:51 GMT+02:00 Michael McCandless <lu...@mikemccandless.com>:
>>
>> I think to sort properly you must also ensure all byte[] from those
>> BigIntegers are the same length, and that you sign extend them?
>> Mike McCandless
>>
>> http://blog.mikemccandless.com
>>
>>
>> On Sun, Aug 21, 2016 at 5:50 AM, Cristian Lorenzetto
>> <cr...@gmail.com> wrote:
>> > I took a look for bigInteger point but i didnt see no reference for
>> > sorting,
>> > and SortedNumericDocValuesField accept long not biginteger.
>> >
>> >
>> > I thought to sort so :
>> >
>> > BigInteger bi = (BigInteger) o;
>> > byte[] b = bi.toByteArray();
>> > NumericUtils.bigIntToSortableBytes(bi, BigIntegerPoint.BYTES, b, 0);
>> > doc.add(new SortedSetDocValuesField(key, new BytesRef(b)));
>> >
>> > it is correct and it is the best practice ?
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Re: sorting biginteger

Posted by Michael McCandless <lu...@mikemccandless.com>.
I think to sort properly you must also ensure all byte[] from those
BigIntegers are the same length, and that you sign extend them?
Mike McCandless

http://blog.mikemccandless.com


On Sun, Aug 21, 2016 at 5:50 AM, Cristian Lorenzetto
<cr...@gmail.com> wrote:
> I took a look for bigInteger point but i didnt see no reference for
> sorting,
> and SortedNumericDocValuesField accept long not biginteger.
>
>
> I thought to sort so :
>
> BigInteger bi = (BigInteger) o;
> byte[] b = bi.toByteArray();
> NumericUtils.bigIntToSortableBytes(bi, BigIntegerPoint.BYTES, b, 0);
> doc.add(new SortedSetDocValuesField(key, new BytesRef(b)));
>
> it is correct and it is the best practice ?

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org