FAQ
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/

Search Discussions

  • Dima May at Jul 16, 2007 at 6:40 pm
    Mohammad,

    see for my 2 cents below,

    Good luck.

    D

    On 7/16/07, Mohammad Norouzi 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/
  • Mohammad Norouzi at Jul 17, 2007 at 4:59 am
    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 wrote:

    Mohammad,

    see for my 2 cents below,

    Good luck.

    D

    On 7/16/07, Mohammad Norouzi 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/
  • Mohammad Norouzi at Jul 29, 2007 at 8:30 am
    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 wrote:

    Mohammad,

    see for my 2 cents below,

    Good luck.

    D

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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedJul 16, '07 at 7:01a
activeJul 29, '07 at 8:30a
posts4
users2
websitelucene.apache.org

2 users in discussion

Mohammad Norouzi: 3 posts Dima May: 1 post

People

Translate

site design / logo © 2022 Grokbase