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 org.apache.lucene.messages.MessageImpl;
21 import org.apache.lucene.queryParser.core.QueryNodeError;
22 import org.apache.lucene.queryParser.core.QueryNodeException;
23 import org.apache.lucene.queryParser.core.QueryNodeParseException;
24 import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
25 import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
27 public class PhraseSlopQueryNode extends QueryNodeImpl implements FieldableNode {
29 private static final long serialVersionUID = 0L;
31 private int value = 0;
34 * @throws QueryNodeException
35 * @throws QueryNodeParseException
36 * @exception QueryNodeParseException
37 * throw in overridden method to disallow
39 public PhraseSlopQueryNode(QueryNode query, int value)
40 throws QueryNodeException {
42 throw new QueryNodeError(new MessageImpl(
43 QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, "query", "null"));
52 public QueryNode getChild() {
53 return getChildren().get(0);
56 public int getValue() {
60 private CharSequence getValueString() {
61 Float f = Float.valueOf(this.value);
62 if (f == f.longValue())
63 return "" + f.longValue();
70 public String toString() {
71 return "<phraseslop value='" + getValueString() + "'>" + "\n"
72 + getChild().toString() + "\n</phraseslop>";
75 public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
76 if (getChild() == null)
78 return getChild().toQueryString(escapeSyntaxParser) + "~"
83 public QueryNode cloneTree() throws CloneNotSupportedException {
84 PhraseSlopQueryNode clone = (PhraseSlopQueryNode) super.cloneTree();
86 clone.value = this.value;
91 public CharSequence getField() {
92 QueryNode child = getChild();
94 if (child instanceof FieldableNode) {
95 return ((FieldableNode) child).getField();
102 public void setField(CharSequence fieldName) {
103 QueryNode child = getChild();
105 if (child instanceof FieldableNode) {
106 ((FieldableNode) child).setField(fieldName);