How to support float type term in Lucene?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to support float type term in Lucene?

David-317
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.

--
David
Reply | Threaded
Open this post in threaded view
|

Re: How to support float type term in Lucene?

Yonik Seeley-2
On 1/9/07, David <[hidden email]> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to support float type term in Lucene?

David-317
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 <[hidden email]>:

>
> On 1/9/07, David <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
David