Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Lucene: Java-User

Equality Numeric Query

 

 

Lucene java-user RSS feed   Index | Next | Previous | View Threaded


serera at gmail

Nov 11, 2009, 5:54 AM

Post #1 of 7 (1290 views)
Permalink
Equality Numeric Query

Hi

I index documents with numeric fields using the new Numeric package. I
execute two types of queries: range queries (for example, [1 TO 20}) and
equality queries (for example 24.75). Don't mind the syntax.

Currently, to execute the equality query, I create a NumericRangeQuery with
the lower/upper value being 24.75 and both limits are set to inclusive. Two
questions:
1) Is there a better approach? For example, if I had indexed the values as
separate terms, I could create a TermQuery.
2) Can I run into precision issues such that 24.751 will be matched as well?

Shai


yonik at lucidimagination

Nov 11, 2009, 6:06 AM

Post #2 of 7 (1242 views)
Permalink
Re: Equality Numeric Query [In reply to]

On Wed, Nov 11, 2009 at 8:54 AM, Shai Erera <serera [at] gmail> wrote:
> I index documents with numeric fields using the new Numeric package. I
> execute two types of queries: range queries (for example, [1 TO 20}) and
> equality queries (for example 24.75). Don't mind the syntax.
>
> Currently, to execute the equality query, I create a NumericRangeQuery with
> the lower/upper value being 24.75 and both limits are set to inclusive. Two
> questions:
> 1) Is there a better approach? For example, if I had indexed the values as
> separate terms, I could create a TermQuery.

Create a term query on NumericUtils.floatToPrefixCoded(24.75f)

> 2) Can I run into precision issues such that 24.751 will be matched as well?

Nope... every numeric indexed value has it's precision indexed along
with it as a prefix, so there will be no false matches.

-Yonik
http://www.lucidimagination.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene


uwe at thetaphi

Nov 11, 2009, 6:13 AM

Post #3 of 7 (1243 views)
Permalink
RE: Equality Numeric Query [In reply to]

Hi Shai,

In 2.9.1, the approach using upper/lower bound identical and included is the
official supported usage. The Query is optimized to rewrite efficient in
this case (constant score term query).

But you can also use a TermQuery like Yonik suggested and converting the
numbers yourself.

You will never hit any false terms, as the encoding clearly differentiate
between precisions.

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe [at] thetaphi

> -----Original Message-----
> From: Shai Erera [mailto:serera [at] gmail]
> Sent: Wednesday, November 11, 2009 2:55 PM
> To: java-user [at] lucene
> Subject: Equality Numeric Query
>
> Hi
>
> I index documents with numeric fields using the new Numeric package. I
> execute two types of queries: range queries (for example, [1 TO 20}) and
> equality queries (for example 24.75). Don't mind the syntax.
>
> Currently, to execute the equality query, I create a NumericRangeQuery
> with
> the lower/upper value being 24.75 and both limits are set to inclusive.
> Two
> questions:
> 1) Is there a better approach? For example, if I had indexed the values as
> separate terms, I could create a TermQuery.
> 2) Can I run into precision issues such that 24.751 will be matched as
> well?
>
> Shai


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene


serera at gmail

Nov 11, 2009, 6:16 AM

Post #4 of 7 (1251 views)
Permalink
Re: Equality Numeric Query [In reply to]

Thanks !

If I use Yonik's approach, do I need to index the terms in a special way?

Shai

On Wed, Nov 11, 2009 at 4:13 PM, Uwe Schindler <uwe [at] thetaphi> wrote:

> Hi Shai,
>
> In 2.9.1, the approach using upper/lower bound identical and included is
> the
> official supported usage. The Query is optimized to rewrite efficient in
> this case (constant score term query).
>
> But you can also use a TermQuery like Yonik suggested and converting the
> numbers yourself.
>
> You will never hit any false terms, as the encoding clearly differentiate
> between precisions.
>
> -----
> Uwe Schindler
> H.-H.-Meier-Allee 63, D-28213 Bremen
> http://www.thetaphi.de
> eMail: uwe [at] thetaphi
>
> > -----Original Message-----
> > From: Shai Erera [mailto:serera [at] gmail]
> > Sent: Wednesday, November 11, 2009 2:55 PM
> > To: java-user [at] lucene
> > Subject: Equality Numeric Query
> >
> > Hi
> >
> > I index documents with numeric fields using the new Numeric package. I
> > execute two types of queries: range queries (for example, [1 TO 20}) and
> > equality queries (for example 24.75). Don't mind the syntax.
> >
> > Currently, to execute the equality query, I create a NumericRangeQuery
> > with
> > the lower/upper value being 24.75 and both limits are set to inclusive.
> > Two
> > questions:
> > 1) Is there a better approach? For example, if I had indexed the values
> as
> > separate terms, I could create a TermQuery.
> > 2) Can I run into precision issues such that 24.751 will be matched as
> > well?
> >
> > Shai
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
> For additional commands, e-mail: java-user-help [at] lucene
>
>


uwe at thetaphi

Nov 11, 2009, 6:21 AM

Post #5 of 7 (1238 views)
Permalink
RE: Equality Numeric Query [In reply to]

No.

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe [at] thetaphi


> -----Original Message-----
> From: Shai Erera [mailto:serera [at] gmail]
> Sent: Wednesday, November 11, 2009 3:17 PM
> To: java-user [at] lucene
> Subject: Re: Equality Numeric Query
>
> Thanks !
>
> If I use Yonik's approach, do I need to index the terms in a special way?
>
> Shai
>
> On Wed, Nov 11, 2009 at 4:13 PM, Uwe Schindler <uwe [at] thetaphi> wrote:
>
> > Hi Shai,
> >
> > In 2.9.1, the approach using upper/lower bound identical and included is
> > the
> > official supported usage. The Query is optimized to rewrite efficient in
> > this case (constant score term query).
> >
> > But you can also use a TermQuery like Yonik suggested and converting the
> > numbers yourself.
> >
> > You will never hit any false terms, as the encoding clearly
> differentiate
> > between precisions.
> >
> > -----
> > Uwe Schindler
> > H.-H.-Meier-Allee 63, D-28213 Bremen
> > http://www.thetaphi.de
> > eMail: uwe [at] thetaphi
> >
> > > -----Original Message-----
> > > From: Shai Erera [mailto:serera [at] gmail]
> > > Sent: Wednesday, November 11, 2009 2:55 PM
> > > To: java-user [at] lucene
> > > Subject: Equality Numeric Query
> > >
> > > Hi
> > >
> > > I index documents with numeric fields using the new Numeric package. I
> > > execute two types of queries: range queries (for example, [1 TO 20})
> and
> > > equality queries (for example 24.75). Don't mind the syntax.
> > >
> > > Currently, to execute the equality query, I create a NumericRangeQuery
> > > with
> > > the lower/upper value being 24.75 and both limits are set to
> inclusive.
> > > Two
> > > questions:
> > > 1) Is there a better approach? For example, if I had indexed the
> values
> > as
> > > separate terms, I could create a TermQuery.
> > > 2) Can I run into precision issues such that 24.751 will be matched as
> > > well?
> > >
> > > Shai
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
> > For additional commands, e-mail: java-user-help [at] lucene
> >
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene


serera at gmail

Nov 11, 2009, 6:25 AM

Post #6 of 7 (1231 views)
Permalink
Re: Equality Numeric Query [In reply to]

Thanks a lot for the super fast response !

Shai

On Wed, Nov 11, 2009 at 4:21 PM, Uwe Schindler <uwe [at] thetaphi> wrote:

> No.
>
> -----
> Uwe Schindler
> H.-H.-Meier-Allee 63, D-28213 Bremen
> http://www.thetaphi.de
> eMail: uwe [at] thetaphi
>
>
> > -----Original Message-----
> > From: Shai Erera [mailto:serera [at] gmail]
> > Sent: Wednesday, November 11, 2009 3:17 PM
> > To: java-user [at] lucene
> > Subject: Re: Equality Numeric Query
> >
> > Thanks !
> >
> > If I use Yonik's approach, do I need to index the terms in a special way?
> >
> > Shai
> >
> > On Wed, Nov 11, 2009 at 4:13 PM, Uwe Schindler <uwe [at] thetaphi> wrote:
> >
> > > Hi Shai,
> > >
> > > In 2.9.1, the approach using upper/lower bound identical and included
> is
> > > the
> > > official supported usage. The Query is optimized to rewrite efficient
> in
> > > this case (constant score term query).
> > >
> > > But you can also use a TermQuery like Yonik suggested and converting
> the
> > > numbers yourself.
> > >
> > > You will never hit any false terms, as the encoding clearly
> > differentiate
> > > between precisions.
> > >
> > > -----
> > > Uwe Schindler
> > > H.-H.-Meier-Allee 63, D-28213 Bremen
> > > http://www.thetaphi.de
> > > eMail: uwe [at] thetaphi
> > >
> > > > -----Original Message-----
> > > > From: Shai Erera [mailto:serera [at] gmail]
> > > > Sent: Wednesday, November 11, 2009 2:55 PM
> > > > To: java-user [at] lucene
> > > > Subject: Equality Numeric Query
> > > >
> > > > Hi
> > > >
> > > > I index documents with numeric fields using the new Numeric package.
> I
> > > > execute two types of queries: range queries (for example, [1 TO 20})
> > and
> > > > equality queries (for example 24.75). Don't mind the syntax.
> > > >
> > > > Currently, to execute the equality query, I create a
> NumericRangeQuery
> > > > with
> > > > the lower/upper value being 24.75 and both limits are set to
> > inclusive.
> > > > Two
> > > > questions:
> > > > 1) Is there a better approach? For example, if I had indexed the
> > values
> > > as
> > > > separate terms, I could create a TermQuery.
> > > > 2) Can I run into precision issues such that 24.751 will be matched
> as
> > > > well?
> > > >
> > > > Shai
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
> > > For additional commands, e-mail: java-user-help [at] lucene
> > >
> > >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
> For additional commands, e-mail: java-user-help [at] lucene
>
>


uwe at thetaphi

Nov 11, 2009, 6:31 AM

Post #7 of 7 (1235 views)
Permalink
RE: Equality Numeric Query [In reply to]

Thanks!

I would still suggest to use a NumericRangeQuery with upper/lower identical
and inclusive, because it would not use expert APIs (NumericUtils is such)
and is more comfortable to use. As long as you not change the rewrite
method, there is no speed difference, as it rewrites to a simple constant
score term query (rewrites to a single term term enum -> creates
BooleanQuery with one TermQuery -> this rewrites to the TermQuery -> wraps
in ConstantScore).

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe [at] thetaphi


> -----Original Message-----
> From: Shai Erera [mailto:serera [at] gmail]
> Sent: Wednesday, November 11, 2009 3:26 PM
> To: java-user [at] lucene
> Subject: Re: Equality Numeric Query
>
> Thanks a lot for the super fast response !
>
> Shai
>
> On Wed, Nov 11, 2009 at 4:21 PM, Uwe Schindler <uwe [at] thetaphi> wrote:
>
> > No.
> >
> > -----
> > Uwe Schindler
> > H.-H.-Meier-Allee 63, D-28213 Bremen
> > http://www.thetaphi.de
> > eMail: uwe [at] thetaphi
> >
> >
> > > -----Original Message-----
> > > From: Shai Erera [mailto:serera [at] gmail]
> > > Sent: Wednesday, November 11, 2009 3:17 PM
> > > To: java-user [at] lucene
> > > Subject: Re: Equality Numeric Query
> > >
> > > Thanks !
> > >
> > > If I use Yonik's approach, do I need to index the terms in a special
> way?
> > >
> > > Shai
> > >
> > > On Wed, Nov 11, 2009 at 4:13 PM, Uwe Schindler <uwe [at] thetaphi>
> wrote:
> > >
> > > > Hi Shai,
> > > >
> > > > In 2.9.1, the approach using upper/lower bound identical and
> included
> > is
> > > > the
> > > > official supported usage. The Query is optimized to rewrite
> efficient
> > in
> > > > this case (constant score term query).
> > > >
> > > > But you can also use a TermQuery like Yonik suggested and converting
> > the
> > > > numbers yourself.
> > > >
> > > > You will never hit any false terms, as the encoding clearly
> > > differentiate
> > > > between precisions.
> > > >
> > > > -----
> > > > Uwe Schindler
> > > > H.-H.-Meier-Allee 63, D-28213 Bremen
> > > > http://www.thetaphi.de
> > > > eMail: uwe [at] thetaphi
> > > >
> > > > > -----Original Message-----
> > > > > From: Shai Erera [mailto:serera [at] gmail]
> > > > > Sent: Wednesday, November 11, 2009 2:55 PM
> > > > > To: java-user [at] lucene
> > > > > Subject: Equality Numeric Query
> > > > >
> > > > > Hi
> > > > >
> > > > > I index documents with numeric fields using the new Numeric
> package.
> > I
> > > > > execute two types of queries: range queries (for example, [1 TO
> 20})
> > > and
> > > > > equality queries (for example 24.75). Don't mind the syntax.
> > > > >
> > > > > Currently, to execute the equality query, I create a
> > NumericRangeQuery
> > > > > with
> > > > > the lower/upper value being 24.75 and both limits are set to
> > > inclusive.
> > > > > Two
> > > > > questions:
> > > > > 1) Is there a better approach? For example, if I had indexed the
> > > values
> > > > as
> > > > > separate terms, I could create a TermQuery.
> > > > > 2) Can I run into precision issues such that 24.751 will be
> matched
> > as
> > > > > well?
> > > > >
> > > > > Shai
> > > >
> > > >
> > > > --------------------------------------------------------------------
> -
> > > > To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
> > > > For additional commands, e-mail: java-user-help [at] lucene
> > > >
> > > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
> > For additional commands, e-mail: java-user-help [at] lucene
> >
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe [at] lucene
For additional commands, e-mail: java-user-help [at] lucene

Lucene java-user RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.