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.Iterator;
21 import java.util.List;
23 import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
26 * A {@link OrQueryNode} represents an OR boolean operation performed on a list
30 public class OrQueryNode extends BooleanQueryNode {
32 private static final long serialVersionUID = -3692323307688017852L;
36 * - the query nodes to be or'ed
38 public OrQueryNode(List<QueryNode> clauses) {
40 if ((clauses == null) || (clauses.size() == 0)) {
41 throw new IllegalArgumentException(
42 "OR query must have at least one clause");
47 public String toString() {
48 if (getChildren() == null || getChildren().size() == 0)
49 return "<boolean operation='or'/>";
50 StringBuilder sb = new StringBuilder();
51 sb.append("<boolean operation='or'>");
52 for (QueryNode child : getChildren()) {
54 sb.append(child.toString());
57 sb.append("\n</boolean>");
62 public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
63 if (getChildren() == null || getChildren().size() == 0)
66 StringBuilder sb = new StringBuilder();
68 for (Iterator<QueryNode> it = getChildren().iterator(); it.hasNext();) {
69 sb.append(filler).append(it.next().toQueryString(escapeSyntaxParser));
73 // in case is root or the parent is a group node avoid parenthesis
74 if ((getParent() != null && getParent() instanceof GroupQueryNode)
78 return "( " + sb.toString() + " )";