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 Re...@bloglines.com on 2004/05/06 10:27:35 UTC
Range searches for numbers
Hi,
What's the best way to store numbers for range searching? If someone
has some info about this I'd love to see it.
This is my current plan:
When I convert the number to a string I will zero pad it so range searches
work. The conversions will be like this for integers:
1 to 10000000001
2 to 10000000002
1000 to 10000001000
I'm just adding a "1" to the
start of the string (or adding 1000000000). This is so negative numbers work
too! They will just be subtracted from a long (1000000000):
-1 to 09999999999
-2 to 09999999998
-1000 to 09999999000
This works great for range
searches. But how do I convert negative longs? I can't subtract 1000000000000000000
from a long can I? It too big to fit in another long.
Any advice is appreciated!
-Reece
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: Range searches for numbers
Posted by Matt Quail <ma...@ctx.com.au>.
Reece,
> What's the best way to store numbers for range searching? If someone
> has some info about this I'd love to see it.
I implemented a "LongField" that encodes any +ve or -ve long into a
string that sorts correctly. I posted that class here:
http://www.mail-archive.com/lucene-dev@jakarta.apache.org/msg04790.html
Doing a String range search should be fairly straight forward from
there. Let me know if you have any problems.
=Matt
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: Range searches for numbers
Posted by Stephane James Vaucher <va...@cirano.qc.ca>.
Quick reference:
http://wiki.apache.org/jakarta-lucene/SearchNumericalFields
If you are stuck, you can always encode the long in a string format (the
date formatter in lucene might do this already). Or even, you could also
treat it like a date and use your long like a date filter.
HTH,
sv
On 6 May 2004 Reece.1247688@bloglines.com wrote:
> Hi,
>
> What's the best way to store numbers for range searching? If someone
> has some info about this I'd love to see it.
>
> This is my current plan:
> When I convert the number to a string I will zero pad it so range searches
> work. The conversions will be like this for integers:
> 1 to 10000000001
>
> 2 to 10000000002
> 1000 to 10000001000
>
> I'm just adding a "1" to the
> start of the string (or adding 1000000000). This is so negative numbers work
> too! They will just be subtracted from a long (1000000000):
> -1 to 09999999999
>
> -2 to 09999999998
> -1000 to 09999999000
>
> This works great for range
> searches. But how do I convert negative longs? I can't subtract 1000000000000000000
> from a long can I? It too big to fit in another long.
>
> Any advice is appreciated!
>
> -Reece
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org