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.Locale;
22 import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
23 import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax.Type;
26 * A {@link FieldQueryNode} represents a element that contains field/text tuple
28 public class FieldQueryNode extends QueryNodeImpl implements FieldValuePairQueryNode<CharSequence>, TextableQueryNode {
30 private static final long serialVersionUID = 3634521145130758265L;
35 protected CharSequence field;
40 protected CharSequence text;
43 * The term's begin position.
48 * The term's end position.
53 * The term's position increment.
55 protected int positionIncrement;
63 * - position in the query string
65 * - position in the query string
67 public FieldQueryNode(CharSequence field, CharSequence text, int begin,
77 protected CharSequence getTermEscaped(EscapeQuerySyntax escaper) {
78 return escaper.escape(this.text, Locale.getDefault(), Type.NORMAL);
81 protected CharSequence getTermEscapeQuoted(EscapeQuerySyntax escaper) {
82 return escaper.escape(this.text, Locale.getDefault(), Type.STRING);
85 public CharSequence toQueryString(EscapeQuerySyntax escaper) {
86 if (isDefaultField(this.field)) {
87 return getTermEscaped(escaper);
89 return this.field + ":" + getTermEscaped(escaper);
94 public String toString() {
95 return "<field start='" + this.begin + "' end='" + this.end + "' field='"
96 + this.field + "' text='" + this.text + "'/>";
102 public String getTextAsString() {
103 if (this.text == null)
106 return this.text.toString();
110 * returns null if the field was not specified in the query string
114 public String getFieldAsString() {
115 if (this.field == null)
118 return this.field.toString();
121 public int getBegin() {
125 public void setBegin(int begin) {
129 public int getEnd() {
133 public void setEnd(int end) {
137 public CharSequence getField() {
141 public void setField(CharSequence field) {
145 public int getPositionIncrement() {
146 return this.positionIncrement;
149 public void setPositionIncrement(int pi) {
150 this.positionIncrement = pi;
156 * @return The "original" form of the term.
158 public CharSequence getText() {
166 public void setText(CharSequence text) {
171 public FieldQueryNode cloneTree() throws CloneNotSupportedException {
172 FieldQueryNode fqn = (FieldQueryNode) super.cloneTree();
173 fqn.begin = this.begin;
175 fqn.field = this.field;
176 fqn.text = this.text;
177 fqn.positionIncrement = this.positionIncrement;
178 fqn.toQueryStringIgnoreFields = this.toQueryStringIgnoreFields;
184 public CharSequence getValue() {
188 public void setValue(CharSequence value) {