pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / standard / nodes / RangeQueryNode.java
1 package org.apache.lucene.queryParser.standard.nodes;
2
3 /**
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 import java.text.Collator;
21
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;
27
28 /**
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/>
31  * 
32  * @see ParametricRangeQueryNodeProcessor
33  * @see ConfigurationKeys#RANGE_COLLATOR
34  * @see org.apache.lucene.search.TermRangeQuery
35  * 
36  * @deprecated this class will be removed in future, {@link TermRangeQueryNode} should
37  * be used instead
38  */
39 @Deprecated
40 public class RangeQueryNode extends TermRangeQueryNode {
41
42   private static final long serialVersionUID = 7400866652044314657L;
43
44   private Collator collator;
45
46   /**
47    * @param lower
48    * @param upper
49    */
50   public RangeQueryNode(ParametricQueryNode lower, ParametricQueryNode upper,
51       Collator collator) {
52     
53     super(lower, upper, lower.getOperator() == CompareOperator.LE, upper
54         .getOperator() == CompareOperator.GE);
55     
56     this.collator = collator;
57     
58   }
59   
60   @Override
61   public ParametricQueryNode getLowerBound() {
62     return (ParametricQueryNode) super.getLowerBound();
63   }
64   
65   @Override
66   public ParametricQueryNode getUpperBound() {
67     return (ParametricQueryNode) super.getUpperBound();
68   }
69   
70   /**
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.
75    * 
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>
80    * 
81    * @throws IllegalArgumentException if lower or upper are not instance of {@link ParametricQueryNode}
82    * 
83    * @see AbstractRangeQueryNode#setBounds
84    */
85   @Override
86   public void setBounds(FieldQueryNode lower, FieldQueryNode upper,
87       boolean lowerInclusive, boolean upperInclusive) {
88     
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());
93     }
94     
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());
99     }
100     
101     super.setBounds(lower, upper, lowerInclusive, upperInclusive);
102     
103   }
104   
105   @Override
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");
111
112     return sb.toString();
113
114   }
115
116   /**
117    * @return the collator
118    */
119   public Collator getCollator() {
120     return this.collator;
121   }
122   
123 }