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.ArrayList;
21 import java.util.List;
23 import org.apache.lucene.messages.MessageImpl;
24 import org.apache.lucene.queryParser.core.QueryNodeError;
25 import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
26 import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
29 * A {@link ModifierQueryNode} indicates the modifier value (+,-,?,NONE) for
30 * each term on the query string. For example "+t1 -t2 t3" will have a tree of:
32 * <BooleanQueryNode> <ModifierQueryNode modifier="MOD_REQ"> <t1/>
33 * </ModifierQueryNode> <ModifierQueryNode modifier="MOD_NOT"> <t2/>
34 * </ModifierQueryNode> <t3/> </BooleanQueryNode>
37 public class ModifierQueryNode extends QueryNodeImpl {
39 private static final long serialVersionUID = -391209837953928169L;
41 public enum Modifier {
42 MOD_NONE, MOD_NOT, MOD_REQ;
45 public String toString() {
54 // this code is never executed
58 public String toDigitString() {
67 // this code is never executed
71 public String toLargeString() {
80 // this code is never executed
85 private Modifier modifier = Modifier.MOD_NONE;
88 * Used to store the modifier value on the original query string
95 public ModifierQueryNode(QueryNode query, Modifier mod) {
97 throw new QueryNodeError(new MessageImpl(
98 QueryParserMessages.PARAMETER_VALUE_NOT_SUPPORTED, "query", "null"));
107 public QueryNode getChild() {
108 return getChildren().get(0);
111 public Modifier getModifier() {
112 return this.modifier;
116 public String toString() {
117 return "<modifier operation='" + this.modifier.toString() + "'>" + "\n"
118 + getChild().toString() + "\n</modifier>";
121 public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
122 if (getChild() == null)
125 String leftParenthensis = "";
126 String rightParenthensis = "";
128 if (getChild() != null && getChild() instanceof ModifierQueryNode) {
129 leftParenthensis = "(";
130 rightParenthensis = ")";
133 if (getChild() instanceof BooleanQueryNode) {
134 return this.modifier.toLargeString() + leftParenthensis
135 + getChild().toQueryString(escapeSyntaxParser) + rightParenthensis;
137 return this.modifier.toDigitString() + leftParenthensis
138 + getChild().toQueryString(escapeSyntaxParser) + rightParenthensis;
143 public QueryNode cloneTree() throws CloneNotSupportedException {
144 ModifierQueryNode clone = (ModifierQueryNode) super.cloneTree();
146 clone.modifier = this.modifier;
154 public void setChild(QueryNode child) {
155 List<QueryNode> list = new ArrayList<QueryNode>();