1 package org.apache.lucene.queryParser.standard.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.nodes.FieldableNode;
23 import org.apache.lucene.queryParser.core.nodes.QueryNode;
24 import org.apache.lucene.queryParser.core.nodes.QueryNodeImpl;
25 import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
26 import org.apache.lucene.search.MultiPhraseQuery;
27 import org.apache.lucene.search.PhraseQuery;
30 * A {@link MultiPhraseQueryNode} indicates that its children should be used to
31 * build a {@link MultiPhraseQuery} instead of {@link PhraseQuery}.
33 public class MultiPhraseQueryNode extends QueryNodeImpl implements
36 private static final long serialVersionUID = -2138501723963320158L;
38 public MultiPhraseQueryNode() {
45 public String toString() {
46 if (getChildren() == null || getChildren().size() == 0)
47 return "<multiPhrase/>";
48 StringBuilder sb = new StringBuilder();
49 sb.append("<multiPhrase>");
50 for (QueryNode child : getChildren()) {
52 sb.append(child.toString());
54 sb.append("\n</multiPhrase>");
58 public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
59 if (getChildren() == null || getChildren().size() == 0)
62 StringBuilder sb = new StringBuilder();
64 for (QueryNode child : getChildren()) {
65 sb.append(filler).append(child.toQueryString(escapeSyntaxParser));
69 return "[MTP[" + sb.toString() + "]]";
73 public QueryNode cloneTree() throws CloneNotSupportedException {
74 MultiPhraseQueryNode clone = (MultiPhraseQueryNode) super.cloneTree();
81 public CharSequence getField() {
82 List<QueryNode> children = getChildren();
84 if (children == null || children.size() == 0) {
88 return ((FieldableNode) children.get(0)).getField();
93 public void setField(CharSequence fieldName) {
94 List<QueryNode> children = getChildren();
96 if (children != null) {
98 for (QueryNode child : children) {
100 if (child instanceof FieldableNode) {
101 ((FieldableNode) child).setField(fieldName);
110 } // end class MultitermQueryNode