1 package org.apache.lucene.queryParser.core.nodes;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.util.List;
22 import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
25 * A {@link BooleanQueryNode} represents a list of elements which do not have an
26 * explicit boolean operator defined between them. It can be used to express a
27 * boolean query that intends to use the default boolean operator.
29 public class BooleanQueryNode extends QueryNodeImpl {
31 private static final long serialVersionUID = -2206623652088638072L;
35 * - the query nodes to be and'ed
37 public BooleanQueryNode(List<QueryNode> clauses) {
44 public String toString() {
45 if (getChildren() == null || getChildren().size() == 0)
46 return "<boolean operation='default'/>";
47 StringBuilder sb = new StringBuilder();
48 sb.append("<boolean operation='default'>");
49 for (QueryNode child : getChildren()) {
51 sb.append(child.toString());
53 sb.append("\n</boolean>");
57 public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
58 if (getChildren() == null || getChildren().size() == 0)
61 StringBuilder sb = new StringBuilder();
63 for (QueryNode child : getChildren()) {
64 sb.append(filler).append(child.toQueryString(escapeSyntaxParser));
68 // in case is root or the parent is a group node avoid parenthesis
69 if ((getParent() != null && getParent() instanceof GroupQueryNode)
73 return "( " + sb.toString() + " )";
77 public QueryNode cloneTree() throws CloneNotSupportedException {
78 BooleanQueryNode clone = (BooleanQueryNode) super.cloneTree();