2 Replies Latest reply on Feb 16, 2010 2:57 PM by sannegrinovero

    Hibernate Search and numeric ranges

    flopsi
      Hi there,

      i use Hibernate Search 3.1 along with Seam 2.1.2, which works fine in general.
      But i wonder if there is a satisfying solution for searching numeric ranges, especially open-ended ones.
      First: I read that the latest Lucene versions (since 2.9.0) support native numeric handling, but it seems the latest Hibernate Search releases are bundled with Lucene 2.4.1, so this is not available. Could i maybe integrate Lucene 2.9 and use the new features through Hibernate Search somehow?

      If that's not possible, how should i best execute such range searches? Since everything is text in Lucene prior 2.9, i guess i cannot get around padding and other dirty things?!? Let's face an example with a solution i implemented yet:

      Some numbers in field 'amount' - e.g. 123.45, 99.1, 1234.555, 456.8, 699.95, 699.958
      For sorting, i did some padding via custom bridge, in my case 6 digits before, 2 after decimal point:
      => e.g. 000123.45, 000099.10, 001234.55, 000456.80, 000699.95, 000699.95
      So a search 'amount:[000200.00 To 000800.00]' returns the correct docs (the last three in example)
      For an open-ended search, i use signs lexically before '0' ('*' in my case) and lexically after '9' ('_' in my case):
      E.g. 'amount:[* TO 000800.00]' or 'amount:[000200.00 TO _]'
      This also seems to work fine.

      Is that (at the moment) the only appropriate way to implement numeric range searches in Hibernate Search? I see some (maybe minor) precision and performance issues here, and it's not really elegant i think...

      Thanks for any suggestions,
      best regards,
      Flo
        • 1. Re: Hibernate Search and numeric ranges
          cbensemann

          Did you find a solution to this? I have upgraded the lucene jars to 2.9.1 to solve another probelem and everything still seems to work successfully so that should be possible if you want/need to upgrade.

          • 2. Re: Hibernate Search and numeric ranges
            sannegrinovero

            Hi, while Lucene 2.9 aims to be drop-in compatible with 2.4 it will break the use of filters; so you can do it as long as you don't enable multiple filters.


            Lucene 2.9 is not having native numeric handling, it's always about strings, but it applies some nice tricks which speed things up a bit, like splitting up a high precision number in several fields: you can do the same thing like splitting the integer part from the real part of the string, or add a separate part for the thousands, something like
            12.3  -> th[000] un[012] cent[30]


            Of course that makes querying more complex, and that's what the new Lucene does - of course for the full and exact explanation please see the lucene forums.


            Current trunk of Hibernate Search is working fine on Lucene 2.9 but is not making full use of this feature yet; it should do before the GA, but it will require Hibernate 3.5 so it might now work with current Seam.