thanks, I use the port PyLucene, and I wonder if there is some utils in
Lucene that can convert floating point number to sortable string,
somebody tell me there should be such utils, but I can't find it in Lucene
document.

Appreciate your help!

2007/1/10, Yonik Seeley <[EMAIL PROTECTED]>:

On 1/9/07, David <[EMAIL PROTECTED]> wrote:
> Hi all:
>     How can I index float type term in Lucene so that we can search in a
> range? I learned that it is possible to convert float to sortable
string,
> but I don't know how to do it.

It's easiest/fastest in binary.  The IEEE floating point format if
interpreted as a signed integer is already very close to sorting
correctly.  If you already know how to index an integer, then do this:
get the float bits as an int, and if the high bit is set, flip all
other bits.
That's how Solr does it:

http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/util/NumberUtils.java?view=markup

  public static String float2sortableStr(float val) {
    int f = Float.floatToRawIntBits(val);
    if (f<0) f ^= 0x7fffffff;
    return int2sortableStr(f);
  }


-Yonik
http://incubator.apache.org/solr Solr, the open-source Lucene search
server

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
David

Reply via email to