Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
TermRangeQuery.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 using System.Globalization;
20 using IndexReader = Lucene.Net.Index.IndexReader;
21 using ToStringUtils = Lucene.Net.Util.ToStringUtils;
22 
23 namespace Lucene.Net.Search
24 {
25 
38 
39  [Serializable]
41  {
42  private System.String lowerTerm;
43  private System.String upperTerm;
44  private System.Globalization.CompareInfo collator;
45  private System.String field;
46  private bool includeLower;
47  private bool includeUpper;
48 
49 
72  public TermRangeQuery(System.String field, System.String lowerTerm, System.String upperTerm, bool includeLower, bool includeUpper):this(field, lowerTerm, upperTerm, includeLower, includeUpper, null)
73  {
74  }
75 
110  public TermRangeQuery(System.String field, System.String lowerTerm, System.String upperTerm, bool includeLower, bool includeUpper, System.Globalization.CompareInfo collator)
111  {
112  this.field = field;
113  this.lowerTerm = lowerTerm;
114  this.upperTerm = upperTerm;
115  this.includeLower = includeLower;
116  this.includeUpper = includeUpper;
117  this.collator = collator;
118  }
119 
121  public virtual string Field
122  {
123  get { return field; }
124  }
125 
127  public virtual string LowerTerm
128  {
129  get { return lowerTerm; }
130  }
131 
133  public virtual string UpperTerm
134  {
135  get { return upperTerm; }
136  }
137 
139  public virtual bool IncludesLower
140  {
141  get { return includeLower; }
142  }
143 
145  public virtual bool IncludesUpper
146  {
147  get { return includeUpper; }
148  }
149 
151  public virtual CompareInfo Collator
152  {
153  get { return collator; }
154  }
155 
156  protected internal override FilteredTermEnum GetEnum(IndexReader reader)
157  {
158  return new TermRangeTermEnum(reader, field, lowerTerm, upperTerm, includeLower, includeUpper, collator);
159  }
160 
162  public override System.String ToString(System.String field)
163  {
164  System.Text.StringBuilder buffer = new System.Text.StringBuilder();
165  if (!Field.Equals(field))
166  {
167  buffer.Append(Field);
168  buffer.Append(":");
169  }
170  buffer.Append(includeLower?'[':'{');
171  buffer.Append(lowerTerm != null?lowerTerm:"*");
172  buffer.Append(" TO ");
173  buffer.Append(upperTerm != null?upperTerm:"*");
174  buffer.Append(includeUpper?']':'}');
175  buffer.Append(ToStringUtils.Boost(Boost));
176  return buffer.ToString();
177  }
178 
179  //@Override
180  public override int GetHashCode()
181  {
182  int prime = 31;
183  int result = base.GetHashCode();
184  result = prime * result + ((collator == null)?0:collator.GetHashCode());
185  result = prime * result + ((field == null)?0:field.GetHashCode());
186  result = prime * result + (includeLower?1231:1237);
187  result = prime * result + (includeUpper?1231:1237);
188  result = prime * result + ((lowerTerm == null)?0:lowerTerm.GetHashCode());
189  result = prime * result + ((upperTerm == null)?0:upperTerm.GetHashCode());
190  return result;
191  }
192 
193  //@Override
194  public override bool Equals(System.Object obj)
195  {
196  if (this == obj)
197  return true;
198  if (!base.Equals(obj))
199  return false;
200  if (GetType() != obj.GetType())
201  return false;
202  TermRangeQuery other = (TermRangeQuery) obj;
203  if (collator == null)
204  {
205  if (other.collator != null)
206  return false;
207  }
208  else if (!collator.Equals(other.collator))
209  return false;
210  if (field == null)
211  {
212  if (other.field != null)
213  return false;
214  }
215  else if (!field.Equals(other.field))
216  return false;
217  if (includeLower != other.includeLower)
218  return false;
219  if (includeUpper != other.includeUpper)
220  return false;
221  if (lowerTerm == null)
222  {
223  if (other.lowerTerm != null)
224  return false;
225  }
226  else if (!lowerTerm.Equals(other.lowerTerm))
227  return false;
228  if (upperTerm == null)
229  {
230  if (other.upperTerm != null)
231  return false;
232  }
233  else if (!upperTerm.Equals(other.upperTerm))
234  return false;
235  return true;
236  }
237  }
238 }