FAQ
Hi,

I do have some indices where I need to get results based on a fixed number list (not a range)
Let's say I have a field named "CategoryID" and I now need all results where "CategoryID" is 1,3 or 7.

In Lucene 2.4 I created a QueryParser which looked like: "CategoryID:(1 3 7)". But the Query Parser won't work with NumericFields...

How can I achieve the same for NumericFields?

Btw I'm using Lucene.net.

Thanks for Help
//Roman

comparis.ch auf Twitter folgen: http://twitter.com/comparis

Ein Freund auf Facebook werden: http://www.facebook.com/comparis.ch

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org

Search Discussions

  • Shashi Kant at Dec 10, 2009 at 3:40 pm
    Have you looked at BooleanQuery? Create individual TermQuery and OR them
    using BooleanQuery.
    On Thu, Dec 10, 2009 at 10:34 AM, comparis.ch - Roman Baeriswyl wrote:

    Hi,

    I do have some indices where I need to get results based on a fixed number
    list (not a range)
    Let's say I have a field named "CategoryID" and I now need all results
    where "CategoryID" is 1,3 or 7.

    In Lucene 2.4 I created a QueryParser which looked like: "CategoryID:(1 3
    7)". But the Query Parser won't work with NumericFields...

    How can I achieve the same for NumericFields?

    Btw I'm using Lucene.net.

    Thanks for Help
    //Roman

    comparis.ch auf Twitter folgen: http://twitter.com/comparis

    Ein Freund auf Facebook werden: http://www.facebook.com/comparis.ch

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • comparis.ch - Roman Baeriswyl at Dec 10, 2009 at 4:26 pm
    I tried

    Query q = new BooleanQuery();
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 1, 1, true, true), BooleanClause.Occur.MUST);
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 3, 3, true, true), BooleanClause.Occur.MUST);
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 7, 7, true, true), BooleanClause.Occur.MUST);

    But that seems to mach all Documents in my Index.

    -----Original Message-----
    From: shashi.mit@gmail.com On Behalf Of Shashi Kant
    Sent: Donnerstag, 10. Dezember 2009 16:40
    To: java-user@lucene.apache.org
    Subject: Re: "IN" Query for NumericFields

    Have you looked at BooleanQuery? Create individual TermQuery and OR them
    using BooleanQuery.
    On Thu, Dec 10, 2009 at 10:34 AM, comparis.ch - Roman Baeriswyl wrote:

    Hi,

    I do have some indices where I need to get results based on a fixed number
    list (not a range)
    Let's say I have a field named "CategoryID" and I now need all results
    where "CategoryID" is 1,3 or 7.

    In Lucene 2.4 I created a QueryParser which looked like: "CategoryID:(1 3
    7)". But the Query Parser won't work with NumericFields...

    How can I achieve the same for NumericFields?

    Btw I'm using Lucene.net.

    Thanks for Help
    //Roman

    comparis.ch auf Twitter folgen: http://twitter.com/comparis

    Ein Freund auf Facebook werden: http://www.facebook.com/comparis.ch

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
    comparis.ch auf Twitter folgen: http://twitter.com/comparis

    Ein Freund auf Facebook werden: http://www.facebook.com/comparis.ch

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Uwe Schindler at Dec 10, 2009 at 6:03 pm
    Cannot be :-) Is the precstep identical?

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

    -----Original Message-----
    From: comparis.ch - Roman Baeriswyl
    Sent: Thursday, December 10, 2009 5:24 PM
    To: 'java-user@lucene.apache.org'
    Subject: RE: "IN" Query for NumericFields

    I tried

    Query q = new BooleanQuery();
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 1, 1,
    true, true), BooleanClause.Occur.MUST);
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 3, 3,
    true, true), BooleanClause.Occur.MUST);
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 7, 7,
    true, true), BooleanClause.Occur.MUST);

    But that seems to mach all Documents in my Index.

    -----Original Message-----
    From: shashi.mit@gmail.com On Behalf Of
    Shashi Kant
    Sent: Donnerstag, 10. Dezember 2009 16:40
    To: java-user@lucene.apache.org
    Subject: Re: "IN" Query for NumericFields

    Have you looked at BooleanQuery? Create individual TermQuery and OR them
    using BooleanQuery.

    On Thu, Dec 10, 2009 at 10:34 AM, comparis.ch - Roman Baeriswyl <
    roman.baeriswyl@comparis.ch> wrote:
    Hi,

    I do have some indices where I need to get results based on a fixed number
    list (not a range)
    Let's say I have a field named "CategoryID" and I now need all results
    where "CategoryID" is 1,3 or 7.

    In Lucene 2.4 I created a QueryParser which looked like: "CategoryID:(1 3
    7)". But the Query Parser won't work with NumericFields...

    How can I achieve the same for NumericFields?

    Btw I'm using Lucene.net.

    Thanks for Help
    //Roman

    comparis.ch auf Twitter folgen: http://twitter.com/comparis

    Ein Freund auf Facebook werden: http://www.facebook.com/comparis.ch

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
    comparis.ch auf Twitter folgen: http://twitter.com/comparis

    Ein Freund auf Facebook werden: http://www.facebook.com/comparis.ch

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Uwe Schindler at Dec 10, 2009 at 6:15 pm
    Sorry, if you have an IN query, it must be BooleanClause.Occur.SHOULD, as
    the CategoryID can be 1, or 3 or 7. You query should not match any doc (I
    verified this).

    -----
    Uwe Schindler
    H.-H.-Meier-Allee 63, D-28213 Bremen
    http://www.thetaphi.de
    eMail: uwe@thetaphi.de
    -----Original Message-----
    From: Uwe Schindler
    Sent: Thursday, December 10, 2009 7:03 PM
    To: java-user@lucene.apache.org
    Subject: RE: "IN" Query for NumericFields

    Cannot be :-) Is the precstep identical?

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

    -----Original Message-----
    From: comparis.ch - Roman Baeriswyl
    Sent: Thursday, December 10, 2009 5:24 PM
    To: 'java-user@lucene.apache.org'
    Subject: RE: "IN" Query for NumericFields

    I tried

    Query q = new BooleanQuery();
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 1, 1,
    true, true), BooleanClause.Occur.MUST);
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 3, 3,
    true, true), BooleanClause.Occur.MUST);
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 7, 7,
    true, true), BooleanClause.Occur.MUST);

    But that seems to mach all Documents in my Index.

    -----Original Message-----
    From: shashi.mit@gmail.com On Behalf Of
    Shashi Kant
    Sent: Donnerstag, 10. Dezember 2009 16:40
    To: java-user@lucene.apache.org
    Subject: Re: "IN" Query for NumericFields

    Have you looked at BooleanQuery? Create individual TermQuery and OR them
    using BooleanQuery.

    On Thu, Dec 10, 2009 at 10:34 AM, comparis.ch - Roman Baeriswyl <
    roman.baeriswyl@comparis.ch> wrote:
    Hi,

    I do have some indices where I need to get results based on a fixed number
    list (not a range)
    Let's say I have a field named "CategoryID" and I now need all results
    where "CategoryID" is 1,3 or 7.

    In Lucene 2.4 I created a QueryParser which looked like:
    "CategoryID:(1
    3
    7)". But the Query Parser won't work with NumericFields...

    How can I achieve the same for NumericFields?

    Btw I'm using Lucene.net.

    Thanks for Help
    //Roman

    comparis.ch auf Twitter folgen: http://twitter.com/comparis

    Ein Freund auf Facebook werden: http://www.facebook.com/comparis.ch

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
    comparis.ch auf Twitter folgen: http://twitter.com/comparis

    Ein Freund auf Facebook werden: http://www.facebook.com/comparis.ch

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Matthew Hall at Dec 10, 2009 at 6:51 pm
    I suspect he's running the query through an analyzer that is dropping
    out single digit numerics, which would basically be a query that pulls
    back everything from the indexes.. or at least I think so.

    Uwe Schindler wrote:
    Sorry, if you have an IN query, it must be BooleanClause.Occur.SHOULD, as
    the CategoryID can be 1, or 3 or 7. You query should not match any doc (I
    verified this).

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

    -----Original Message-----
    From: Uwe Schindler
    Sent: Thursday, December 10, 2009 7:03 PM
    To: java-user@lucene.apache.org
    Subject: RE: "IN" Query for NumericFields

    Cannot be :-) Is the precstep identical?

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


    -----Original Message-----
    From: comparis.ch - Roman Baeriswyl
    Sent: Thursday, December 10, 2009 5:24 PM
    To: 'java-user@lucene.apache.org'
    Subject: RE: "IN" Query for NumericFields

    I tried

    Query q = new BooleanQuery();
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 1, 1,
    true, true), BooleanClause.Occur.MUST);
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 3, 3,
    true, true), BooleanClause.Occur.MUST);
    ((BooleanQuery)q).Add(NumericRangeQuery.NewLongRange("CategoryID", 7, 7,
    true, true), BooleanClause.Occur.MUST);

    But that seems to mach all Documents in my Index.

    -----Original Message-----
    From: shashi.mit@gmail.com On Behalf Of
    Shashi Kant
    Sent: Donnerstag, 10. Dezember 2009 16:40
    To: java-user@lucene.apache.org
    Subject: Re: "IN" Query for NumericFields

    Have you looked at BooleanQuery? Create individual TermQuery and OR them
    using BooleanQuery.

    On Thu, Dec 10, 2009 at 10:34 AM, comparis.ch - Roman Baeriswyl <
    roman.baeriswyl@comparis.ch> wrote:

    Hi,

    I do have some indices where I need to get results based on a fixed number
    list (not a range)
    Let's say I have a field named "CategoryID" and I now need all results
    where "CategoryID" is 1,3 or 7.

    In Lucene 2.4 I created a QueryParser which looked like:
    "CategoryID:(1
    3
    7)". But the Query Parser won't work with NumericFields...

    How can I achieve the same for NumericFields?

    Btw I'm using Lucene.net.

    Thanks for Help
    //Roman

    comparis.ch auf Twitter folgen: http://twitter.com/comparis

    Ein Freund auf Facebook werden: http://www.facebook.com/comparis.ch

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

    comparis.ch auf Twitter folgen: http://twitter.com/comparis

    Ein Freund auf Facebook werden: http://www.facebook.com/comparis.ch

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

    --
    Matthew Hall
    Software Engineer
    Mouse Genome Informatics
    mhall@informatics.jax.org
    (207) 288-6012



    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Uwe Schindler at Dec 10, 2009 at 3:41 pm
    You can override QP's newTermQuery method. Look into the list archives and
    search for both keywords. There it is also explained how to use
    NumericRangeQuery with QP.

    The ideal solution to hit exact terms are to use NumericRangeQuery with
    upper lower bound indentical and inclusive.

    Uwe

    -----
    Uwe Schindler
    H.-H.-Meier-Allee 63, D-28213 Bremen
    http://www.thetaphi.de
    eMail: uwe@thetaphi.de
    -----Original Message-----
    From: comparis.ch - Roman Baeriswyl
    Sent: Thursday, December 10, 2009 4:35 PM
    To: 'java-user@lucene.apache.org'
    Subject: "IN" Query for NumericFields

    Hi,

    I do have some indices where I need to get results based on a fixed number
    list (not a range)
    Let's say I have a field named "CategoryID" and I now need all results
    where "CategoryID" is 1,3 or 7.

    In Lucene 2.4 I created a QueryParser which looked like: "CategoryID:(1 3
    7)". But the Query Parser won't work with NumericFields...

    How can I achieve the same for NumericFields?

    Btw I'm using Lucene.net.

    Thanks for Help
    //Roman

    comparis.ch auf Twitter folgen: http://twitter.com/comparis

    Ein Freund auf Facebook werden: http://www.facebook.com/comparis.ch

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedDec 10, '09 at 3:35p
activeDec 10, '09 at 6:51p
posts7
users4
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase