You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Mohammad Norouzi <mn...@gmail.com> on 2007/07/16 09:01:13 UTC

two questions about NumberTools

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

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?


any comment would be of great help

-- 
Regards,
Mohammad
--------------------------
see my blog: http://brainable.blogspot.com/
another in Persian: http://fekre-motefavet.blogspot.com/

Re: two questions about NumberTools

Posted by Mohammad Norouzi <mn...@gmail.com>.
Hi
I create my index files and encode all numbers using solr's NumberUtils but
searching not works!!! I created a custom query parser and override the
getRangeQuery and getFieldQuery but no result will return.
do I have to implement a custom analyzer too? currently I am using
whitespace analayzer and I don't think it needs to be customized.


> On 7/16/07, Dima May <di...@gmail.com> wrote:
> >
> > Mohammad,
> >
> > see for my 2 cents below,
> >
> > Good luck.
> >
> > D
> >
> >
> > On 7/16/07, Mohammad Norouzi <mn...@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/
> > >
> >
>
>
>
> --
> Regards,
> Mohammad
> --------------------------
> see my blog: http://brainable.blogspot.com/
> another in Persian: http://fekre-motefavet.blogspot.com/
>



-- 
Regards,
Mohammad
--------------------------
see my blog: http://brainable.blogspot.com/
another in Persian: http://fekre-motefavet.blogspot.com/

Re: two questions about NumberTools

Posted by Mohammad Norouzi <mn...@gmail.com>.
Thanks Dima
the first link is very nice and I put some comment on that if you take a
look again but it has no decode method.
anyway, I decided to use solr solution

thanks again :)

On 7/16/07, Dima May <di...@gmail.com> wrote:
>
> Mohammad,
>
> see for my 2 cents below,
>
> Good luck.
>
> D
>
>
> On 7/16/07, Mohammad Norouzi <mn...@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/
> >
>



-- 
Regards,
Mohammad
--------------------------
see my blog: http://brainable.blogspot.com/
another in Persian: http://fekre-motefavet.blogspot.com/

Re: two questions about NumberTools

Posted by Dima May <di...@gmail.com>.
Mohammad,

see for my 2 cents below,

Good luck.

D


On 7/16/07, Mohammad Norouzi <mn...@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/
>