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.queryParser.core.parser.EscapeQuerySyntax;
23 * A {@link FuzzyQueryNode} represents a element that contains
24 * field/text/similarity tuple
26 public class FuzzyQueryNode extends FieldQueryNode {
28 private static final long serialVersionUID = -1794537213032589441L;
30 private float similarity;
32 private int prefixLength;
36 * Name of the field query will use.
38 * Term token to use for building term for the query
45 * @param minSimilarity
48 * - position in the query string
50 * - position in the query string
52 public FuzzyQueryNode(CharSequence field, CharSequence term,
53 float minSimilarity, int begin, int end) {
54 super(field, term, begin, end);
55 this.similarity = minSimilarity;
59 public void setPrefixLength(int prefixLength) {
60 this.prefixLength = prefixLength;
63 public int getPrefixLength() {
64 return this.prefixLength;
68 public CharSequence toQueryString(EscapeQuerySyntax escaper) {
69 if (isDefaultField(this.field)) {
70 return getTermEscaped(escaper) + "~" + this.similarity;
72 return this.field + ":" + getTermEscaped(escaper) + "~" + this.similarity;
77 public String toString() {
78 return "<fuzzy field='" + this.field + "' similarity='" + this.similarity
79 + "' term='" + this.text + "'/>";
82 public void setSimilarity(float similarity) {
83 this.similarity = similarity;
87 public FuzzyQueryNode cloneTree() throws CloneNotSupportedException {
88 FuzzyQueryNode clone = (FuzzyQueryNode) super.cloneTree();
90 clone.similarity = this.similarity;
96 * @return the similarity
98 public float getSimilarity() {
99 return this.similarity;