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.List;
22
import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode.CompareOperator;
23
import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
26
* A {@link ParametricRangeQueryNode} represents LE, LT, GE, GT, EQ, NE query.
27
* Example: date >= "2009-10-10" OR price = 200
29
public class ParametricRangeQueryNode extends QueryNodeImpl implements
30
RangeQueryNode<ParametricQueryNode> {
32
private static final long serialVersionUID = 7120958816535573935L;
34
public ParametricRangeQueryNode(ParametricQueryNode lowerBound,
35
ParametricQueryNode upperBound) {
37
if (upperBound.getOperator() != CompareOperator.LE
38
&& upperBound.getOperator() != CompareOperator.LT) {
39
throw new IllegalArgumentException("upper bound should have "
40
+ CompareOperator.LE + " or " + CompareOperator.LT);
43
if (lowerBound.getOperator() != CompareOperator.GE
44
&& lowerBound.getOperator() != CompareOperator.GT) {
45
throw new IllegalArgumentException("lower bound should have "
46
+ CompareOperator.GE + " or " + CompareOperator.GT);
49
if (upperBound.getField() != lowerBound.getField()
50
|| (upperBound.getField() != null && !upperBound.getField().equals(
51
lowerBound.getField()))) {
53
throw new IllegalArgumentException(
54
"lower and upper bounds should have the same field name!");
66
public ParametricQueryNode getUpperBound() {
67
return (ParametricQueryNode) getChildren().get(1);
70
public ParametricQueryNode getLowerBound() {
71
return (ParametricQueryNode) getChildren().get(0);
74
public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
75
return getLowerBound().toQueryString(escapeSyntaxParser) + " AND "
76
+ getUpperBound().toQueryString(escapeSyntaxParser);
79
public CharSequence getField() {
80
return getLowerBound().getField();
84
public String toString() {
85
StringBuilder sb = new StringBuilder("<parametricRange>\n\t");
86
sb.append(getUpperBound()).append("\n\t");
87
sb.append(getLowerBound()).append("\n");
88
sb.append("</parametricRange>\n");
95
public ParametricRangeQueryNode cloneTree() throws CloneNotSupportedException {
96
ParametricRangeQueryNode clone = (ParametricRangeQueryNode) super
104
public void setField(CharSequence fieldName) {
105
List<QueryNode> children = getChildren();
107
if (children != null) {
109
for (QueryNode child : getChildren()) {
111
if (child instanceof FieldableNode) {
112
((FieldableNode) child).setField(fieldName);
121
public boolean isLowerInclusive() {
122
return getUpperBound().getOperator() == CompareOperator.GE;
125
public boolean isUpperInclusive() {
126
return getLowerBound().getOperator() == CompareOperator.LE;