lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Trejkaz (JIRA)" <j...@apache.org>
Subject [jira] [Created] (LUCENE-3367) GroupQueryNodeProcessor doesn't recursively process children of custom query nodes
Date Tue, 09 Aug 2011 01:20:31 GMT
GroupQueryNodeProcessor doesn't recursively process children of custom query nodes
----------------------------------------------------------------------------------

                 Key: LUCENE-3367
                 URL: https://issues.apache.org/jira/browse/LUCENE-3367
             Project: Lucene - Java
          Issue Type: Bug
          Components: modules/queryparser
    Affects Versions: 3.3
            Reporter: Trejkaz


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.

{code}
    @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();
        }
    }
{code}


--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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


Mime
View raw message