FAQ
Assume I have the following rather simple example that works fine:

BooleanQuery bq = new BooleanQuery();
bq.add(new PrefixQuery(new
Term("heading",word)),BooleanClause.Occur.SHOULD);
bq.add(new PrefixQuery(new
Term("attribute",word)),BooleanClause.Occur.SHOULD);

Now I add the following and I assume its doing what it should be
doing, not what I expect it should be doing:

BooleanQuery bq = new BooleanQuery();
bq.add(new PrefixQuery(new
Term("heading",word)),BooleanClause.Occur.SHOULD);
bq.add(new PrefixQuery(new
Term("attribute",word)),BooleanClause.Occur.SHOULD);
if(subjectId.length()>0)
bq.add(new PrefixQuery(new
Term("subject_id",subjectId)),BooleanClause.Occur.MUST);

This appears to be pulling out ALL records where "heading" matches or
"attribute" matches plus all records where "subject_id" matches.

How do I make it return documents that match "heading" or "attribute"
within the "subject_id" subset?

Kind regards,
Jacob Rhoden

____________________________________
Information Technology Services,
The University of Melbourne

Email: jrhoden@unimelb.edu.au
Phone: +61 3 8344 2884
Mobile: +61 4 1095 7575

Search Discussions

  • TCK at Dec 15, 2009 at 5:25 am
    How about the following?

    BooleanQuery bq1 = new BooleanQuery();
    bq1.add(new PrefixQuery(new
    Term("heading",word)),BooleanClause.Occur.SHOULD);
    bq1.add(new PrefixQuery(new
    Term("attribute",word)),BooleanClause.Occur.SHOULD);

    BooleanQuery bq = new BooleanQuery();
    bq.add(bq1, BooleanClause.Occur.MUST);
    if(subjectId.length()>0)
    bq.add(new PrefixQuery(new Term("subject_id",subjectId)),
    BooleanClause.Occur.MUST);

    I think bq should now be your desired query.

    -TCK


    On Mon, Dec 14, 2009 at 11:50 PM, Jacob Rhoden wrote:

    Assume I have the following rather simple example that works fine:

    BooleanQuery bq = new BooleanQuery();
    bq.add(new PrefixQuery(new
    Term("heading",word)),BooleanClause.Occur.SHOULD);
    bq.add(new PrefixQuery(new
    Term("attribute",word)),BooleanClause.Occur.SHOULD);

    Now I add the following and I assume its doing what it should be doing, not
    what I expect it should be doing:

    BooleanQuery bq = new BooleanQuery();
    bq.add(new PrefixQuery(new
    Term("heading",word)),BooleanClause.Occur.SHOULD);
    bq.add(new PrefixQuery(new
    Term("attribute",word)),BooleanClause.Occur.SHOULD);
    if(subjectId.length()>0)
    bq.add(new PrefixQuery(new
    Term("subject_id",subjectId)),BooleanClause.Occur.MUST);

    This appears to be pulling out ALL records where "heading" matches or
    "attribute" matches plus all records where "subject_id" matches.

    How do I make it return documents that match "heading" or "attribute"
    within the "subject_id" subset?

    Kind regards,
    Jacob Rhoden

    ____________________________________
    Information Technology Services,
    The University of Melbourne

    Email: jrhoden@unimelb.edu.au
    Phone: +61 3 8344 2884
    Mobile: +61 4 1095 7575
  • Jacob Rhoden at Dec 15, 2009 at 5:31 am
    Exactly what I was trying to do. Thanks.
    On 15/12/2009, at 4:25 PM, TCK wrote:

    How about the following?

    BooleanQuery bq1 = new BooleanQuery();
    bq1.add(new PrefixQuery(new
    Term("heading",word)),BooleanClause.Occur.SHOULD);
    bq1.add(new PrefixQuery(new
    Term("attribute",word)),BooleanClause.Occur.SHOULD);

    BooleanQuery bq = new BooleanQuery();
    bq.add(bq1, BooleanClause.Occur.MUST);
    if(subjectId.length()>0)
    bq.add(new PrefixQuery(new Term("subject_id",subjectId)),
    BooleanClause.Occur.MUST);

    I think bq should now be your desired query.

    -TCK

    ____________________________________
    Information Technology Services,
    The University of Melbourne

    Email: jrhoden@unimelb.edu.au
    Phone: +61 3 8344 2884
    Mobile: +61 4 1095 7575


    ---------------------------------------------------------------------
    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 15, '09 at 4:51a
activeDec 15, '09 at 5:31a
posts3
users2
websitelucene.apache.org

2 users in discussion

Jacob Rhoden: 2 posts TCK: 1 post

People

Translate

site design / logo © 2022 Grokbase