lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Trejkaz (Commented) (JIRA)" <>
Subject [jira] [Commented] (LUCENE-3565) StandardQueryParser generates incorrect query for groups containing one term if using default operator AND
Date Sun, 06 Nov 2011 21:49:51 GMT


Trejkaz commented on LUCENE-3565:

I guess another valid result of parsing this query could be:

        BooleanQuery expectedQuery = new BooleanQuery();
        expectedQuery.add(new TermQuery(new Term("text", "a")), BooleanClause.Occur.SHOULD);
        expectedQuery.add(new TermQuery(new Term("text", "b")), BooleanClause.Occur.SHOULD);

Which would still keep the spirit of removing single-child boolean queries.

What is actually generated, however, is the same query with MUST for both clauses.

> StandardQueryParser generates incorrect query for groups containing one term if using
default operator AND
> ----------------------------------------------------------------------------------------------------------
>                 Key: LUCENE-3565
>                 URL:
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: modules/queryparser
>    Affects Versions: 3.4
>            Reporter: Trejkaz
>              Labels: queryparser
> The following test demonstrates a bug in StandardQueryParser when DEFAULT_OPERATOR is
set to AND:
> {code}
>     @Test
>     public void testDefaultOperatorSingleGrouped() throws Exception
>     {
>         StandardQueryParser parser = new StandardQueryParser();
>         parser.getQueryConfigHandler().set(StandardQueryConfigHandler.ConfigurationKeys.DEFAULT_OPERATOR,
>         BooleanQuery expectedQuery = new BooleanQuery();
>         BooleanQuery innerQuery1 = new BooleanQuery();
>         innerQuery1.add(new TermQuery(new Term("text", "a")), BooleanClause.Occur.MUST);
>         expectedQuery.add(innerQuery1, BooleanClause.Occur.SHOULD);
>         BooleanQuery innerQuery2 = new BooleanQuery();
>         innerQuery2.add(new TermQuery(new Term("text", "b")), BooleanClause.Occur.MUST);
>         expectedQuery.add(innerQuery2, BooleanClause.Occur.SHOULD);
>         Query actualQuery = parser.parse("(a) OR (b)", "text");
>         assertEquals("Wrong query was generated", expectedQuery, actualQuery);
>     }
> {code}
> BooleanSingleChildOptimizationQueryNodeProcessor appears to be responsible because if
I remove it, the correct query is generated (however, doing so breaks a number of other tests
of our own.)

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message