Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-3565

StandardQueryParser generates incorrect query for groups containing one term if using default operator AND

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 3.4
    • Fix Version/s: None
    • Component/s: modules/queryparser
    • Labels:
    • Lucene Fields:
      New

      Description

      The following test demonstrates a bug in StandardQueryParser when DEFAULT_OPERATOR is set to AND:

          @Test
          public void testDefaultOperatorSingleGrouped() throws Exception
          {
              StandardQueryParser parser = new StandardQueryParser();
              parser.getQueryConfigHandler().set(StandardQueryConfigHandler.ConfigurationKeys.DEFAULT_OPERATOR, StandardQueryConfigHandler.Operator.AND);
      
              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);
          }
      

      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.)

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              trejkaz Trejkaz
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: