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

GroupQueryNodeProcessor doesn't recursively process children of custom query nodes

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.3
    • Fix Version/s: None
    • Component/s: modules/queryparser
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      In some situations I found that boolean queries weren't using the default operator. I have tracked this issue down to GroupQueryNodeProcessor, which does not appear to be recursing into the tree.

      I have two unit tests. The first one has just the boolean query, the second one has a custom query node wrapped around it. In the second case, the default operator logic is not applied to the boolean query.

          @Test
          public void testDefaultOperator() throws Exception
          {
              QueryNode node = new GroupQueryNode(new BooleanQueryNode(Arrays.<QueryNode>asList(
                  new FieldQueryNode("text", "a", 1, 1),
                  new FieldQueryNode("text", "b", 3, 3)
              )));
      
              GroupQueryNodeProcessor processor = new GroupQueryNodeProcessor();
              QueryConfigHandler config = new StandardQueryConfigHandler();
              config.addAttribute(DefaultOperatorAttribute.class).setOperator(DefaultOperatorAttribute.Operator.AND);
              processor.setQueryConfigHandler(config);
      
              QueryNode actualNode = processor.process(node);
      
              QueryNode expectedNode = new BooleanQueryNode(Arrays.<QueryNode>asList(
                  new BooleanModifierNode(new FieldQueryNode("text", "a", 1, 1), ModifierQueryNode.Modifier.MOD_REQ),
                  new BooleanModifierNode(new FieldQueryNode("text", "b", 3, 3), ModifierQueryNode.Modifier.MOD_REQ)
              ));
      
              assertEquals("Wrong node after processing", expectedNode.toString(), actualNode.toString());
          }
      
          @Test
          public void testDefaultOperatorInsideCustomNode() throws Exception
          {
              QueryNode node = new CustomQueryNode(Arrays.<QueryNode>asList(new GroupQueryNode(new BooleanQueryNode(Arrays.<QueryNode>asList(
                  new FieldQueryNode("text", "a", 1, 1),
                  new FieldQueryNode("text", "b", 3, 3)
              )))));
      
              GroupQueryNodeProcessor processor = new GroupQueryNodeProcessor();
              QueryConfigHandler config = new StandardQueryConfigHandler();
              config.addAttribute(DefaultOperatorAttribute.class).setOperator(DefaultOperatorAttribute.Operator.AND);
              processor.setQueryConfigHandler(config);
      
              QueryNode actualNode = processor.process(node);
      
              QueryNode expectedNode = new CustomQueryNode(Arrays.<QueryNode>asList(new GroupQueryNode(new BooleanQueryNode(Arrays.<QueryNode>asList(
                  new BooleanModifierNode(new FieldQueryNode("text", "a", 1, 1), ModifierQueryNode.Modifier.MOD_REQ),
                  new BooleanModifierNode(new FieldQueryNode("text", "b", 3, 3), ModifierQueryNode.Modifier.MOD_REQ)
              )))));
      
              assertEquals("Wrong node after processing", expectedNode.toString(), actualNode.toString());
          }
      
      
          public static class CustomQueryNode extends QueryNodeImpl
          {
              private CustomQueryNode(List<QueryNode> children)
              {
                  setLeaf(false);
                  allocate();
                  set(children);
              }
      
              @Override
              public CharSequence toQueryString(EscapeQuerySyntax escaper)
              {
                  StringBuilder builder = new StringBuilder(100);
                  builder.append("custom(");
                  String separator = "";
                  for (QueryNode child : getChildren())
                  {
                      builder.append(separator);
                      builder.append(child.toQueryString(escaper));
                      separator = ",";
                  }
                  builder.append(')');
                  return builder.toString();
              }
      
              @Override
              public String toString()
              {
                  StringBuilder builder = new StringBuilder(100);
                  builder.append("<custom>\n");
                  for (QueryNode child : getChildren())
                  {
                      builder.append(child).append('\n');
                  }
                  builder.append("\n</custom>");
                  return builder.toString();
              }
          }
      

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated: