1
package org.apache.lucene.queryParser.standard.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.text.Collator;
22
import org.apache.lucene.queryParser.core.nodes.FieldQueryNode;
23
import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode;
24
import org.apache.lucene.queryParser.core.nodes.ParametricQueryNode.CompareOperator;
25
import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
26
import org.apache.lucene.queryParser.standard.processors.ParametricRangeQueryNodeProcessor;
29
* This query node represents a range query. It also holds which collator will
30
* be used by the range query and if the constant score rewrite is enabled. <br/>
32
* @see ParametricRangeQueryNodeProcessor
33
* @see ConfigurationKeys#RANGE_COLLATOR
34
* @see org.apache.lucene.search.TermRangeQuery
36
* @deprecated this class will be removed in future, {@link TermRangeQueryNode} should
40
public class RangeQueryNode extends TermRangeQueryNode {
42
private static final long serialVersionUID = 7400866652044314657L;
44
private Collator collator;
50
public RangeQueryNode(ParametricQueryNode lower, ParametricQueryNode upper,
53
super(lower, upper, lower.getOperator() == CompareOperator.LE, upper
54
.getOperator() == CompareOperator.GE);
56
this.collator = collator;
61
public ParametricQueryNode getLowerBound() {
62
return (ParametricQueryNode) super.getLowerBound();
66
public ParametricQueryNode getUpperBound() {
67
return (ParametricQueryNode) super.getUpperBound();
71
* Sets lower and upper bounds. The method signature expects
72
* {@link FieldQueryNode} objects as lower and upper, however,
73
* an {@link IllegalArgumentException} will be thrown at runtime
74
* if a non {@link ParametricQueryNode} is passed as lower and upper.
76
* @param lower a {@link ParametricQueryNode} object
77
* @param upper a {@link ParametricQueryNode} object
78
* @param lowerInclusive <code>true</code> if lower bound is inclusive, otherwise, <code>false</code>
79
* @param upperInclusive <code>true</code> if upper bound is inclusive, otherwise, <code>false</code>
81
* @throws IllegalArgumentException if lower or upper are not instance of {@link ParametricQueryNode}
83
* @see AbstractRangeQueryNode#setBounds
86
public void setBounds(FieldQueryNode lower, FieldQueryNode upper,
87
boolean lowerInclusive, boolean upperInclusive) {
89
if (lower != null && !(lower instanceof ParametricQueryNode)) {
90
throw new IllegalArgumentException("lower should be an instance of "
91
+ ParametricQueryNode.class.getCanonicalName() + ", but found "
92
+ lower.getClass().getCanonicalName());
95
if (upper != null && !(upper instanceof ParametricQueryNode)) {
96
throw new IllegalArgumentException("upper should be an instance of "
97
+ ParametricQueryNode.class.getCanonicalName() + ", but found "
98
+ lower.getClass().getCanonicalName());
101
super.setBounds(lower, upper, lowerInclusive, upperInclusive);
106
public String toString() {
107
StringBuilder sb = new StringBuilder("<range>\n\t");
108
sb.append(this.getUpperBound()).append("\n\t");
109
sb.append(this.getLowerBound()).append("\n");
110
sb.append("</range>\n");
112
return sb.toString();
117
* @return the collator
119
public Collator getCollator() {
120
return this.collator;