lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dima May" <dima...@gmail.com>
Subject Re: two questions about NumberTools
Date Mon, 16 Jul 2007 17:32:08 GMT
Mohammad,

see for my 2 cents below,

Good luck.

D


On 7/16/07, Mohammad Norouzi <mnrz57@gmail.com> wrote:
>
> Hello
> I have problem in range queries, for example, I have queries like
> "field:[1
> TO 25]" or "field:[1.1 TO 11.25]"
> currently these queries not work. field:[20 TO 25] works fine but when the
> both limits of the range have different number of digits the query won't
> work. so the solution is NumberTools.
>
1 - the NumberTools utility has two methods longToString() and
> stringToLong(). how about the double or float  numbers?? I think it should
> be extends to support more data types


Check out these resources:
1. https://issues.apache.org/jira/browse/LUCENE-530
2. Solr has a class that will help you encode/decode floats for lucene range
queries and sorting:
http://lucene.apache.org/solr/api/org/apache/solr/util/NumberUtils.html
3. Alternatively you can pad the floats with zeros like this: 000001.3000.
As long as the padding is consistent between indexing and querying your
range queries and sorting should work fine as appending zeros enforces
lexicographical order.

2 - suppose we are indexing a bunch of information and a field is in long
> that we need to apply range queries on that later.
> now I have a query like "fieldone:(just for test) AND field_long:[1 TO
> 25]",
> the question is whether this query returns correct result? because
> field_long already encoded with longToString() method and in the index
> files
> you can't find any real value say, 1 or 25 or 10 ...
> do I need to use stringToLong() method while I am building query?


Yes the search query must "match" whats in the index so you would have to
encode the value before performing the search. The good news are that you
can encapsulate that logic into the custom analyzer and custom query parser.
In query parser you should implement getRangeQuery.

any comment would be of great help
>
> --
> Regards,
> Mohammad
> --------------------------
> see my blog: http://brainable.blogspot.com/
> another in Persian: http://fekre-motefavet.blogspot.com/
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message