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 101 2 to 102 1000 to 1001000 I'm just adding a 1 to the start of the string (or adding 10). This is so negative numbers work too! They will just be subtracted from a long (10): -1 to 099 -2 to 098 -1000 to 0999000 This works great for range searches. But how do I convert negative longs? I can't subtract 100 from a long can I? It too big to fit in another long. Any advice is appreciated! -Reece - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Range searches for numbers
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 [EMAIL PROTECTED] 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 101 2 to 102 1000 to 1001000 I'm just adding a 1 to the start of the string (or adding 10). This is so negative numbers work too! They will just be subtracted from a long (10): -1 to 099 -2 to 098 -1000 to 0999000 This works great for range searches. But how do I convert negative longs? I can't subtract 100 from a long can I? It too big to fit in another long. Any advice is appreciated! -Reece - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Range searches for numbers
Thanks for the info. The Date formatter doesn't work because it can only deal with positive longs. My problem was how to handle the negatives but I got it figured out. Thanks! --- Lucene Users List [EMAIL PROTECTED] wrote: 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 [EMAIL PROTECTED] 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 101 2 to 102 1000 to 1001000 I'm just adding a 1 to the start of the string (or adding 10). This is so negative numbers work too! They will just be subtracted from a long (10): -1 to 099 -2 to 098 -1000 to 0999000 This works great for range searches. But how do I convert negative longs? I can't subtract 100 from a long can I? It too big to fit in another long. Any advice is appreciated! -Reece - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Range searches for numbers
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/[EMAIL PROTECTED]/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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]