Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
TermRangeFilter.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 
21 namespace Lucene.Net.Search
22 {
23 
24  /// <summary> A Filter that restricts search results to a range of values in a given
25  /// field.
26  ///
27  /// <p/>This filter matches the documents looking for terms that fall into the
28  /// supplied range according to <see cref="String.CompareTo(String)" />. It is not intended
29  /// for numerical ranges, use <see cref="NumericRangeFilter{T}" /> instead.
30  ///
31  /// <p/>If you construct a large number of range filters with different ranges but on the
32  /// same field, <see cref="FieldCacheRangeFilter" /> may have significantly better performance.
33  /// </summary>
34  /// <since> 2.9
35  /// </since>
36  [Serializable]
37  public class TermRangeFilter:MultiTermQueryWrapperFilter<TermRangeQuery>
38  {
39 
40  /// <param name="fieldName">The field this range applies to
41  /// </param>
42  /// <param name="lowerTerm">The lower bound on this range
43  /// </param>
44  /// <param name="upperTerm">The upper bound on this range
45  /// </param>
46  /// <param name="includeLower">Does this range include the lower bound?
47  /// </param>
48  /// <param name="includeUpper">Does this range include the upper bound?
49  /// </param>
50  /// <throws> IllegalArgumentException if both terms are null or if </throws>
51  /// <summary> lowerTerm is null and includeLower is true (similar for upperTerm
52  /// and includeUpper)
53  /// </summary>
54  public TermRangeFilter(System.String fieldName, System.String lowerTerm, System.String upperTerm, bool includeLower, bool includeUpper):base(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper))
55  {
56  }
57 
58  /// <summary> <strong>WARNING:</strong> Using this constructor and supplying a non-null
59  /// value in the <c>collator</c> parameter will cause every single
60  /// index Term in the Field referenced by lowerTerm and/or upperTerm to be
61  /// examined. Depending on the number of index Terms in this Field, the
62  /// operation could be very slow.
63  ///
64  /// </summary>
65  /// <param name="fieldName"></param>
66  /// <param name="lowerTerm">The lower bound on this range
67  /// </param>
68  /// <param name="upperTerm">The upper bound on this range
69  /// </param>
70  /// <param name="includeLower">Does this range include the lower bound?
71  /// </param>
72  /// <param name="includeUpper">Does this range include the upper bound?
73  /// </param>
74  /// <param name="collator">The collator to use when determining range inclusion; set
75  /// to null to use Unicode code point ordering instead of collation.
76  /// </param>
77  /// <throws> IllegalArgumentException if both terms are null or if </throws>
78  /// <summary> lowerTerm is null and includeLower is true (similar for upperTerm
79  /// and includeUpper)
80  /// </summary>
81  public TermRangeFilter(System.String fieldName, System.String lowerTerm, System.String upperTerm, bool includeLower, bool includeUpper, System.Globalization.CompareInfo collator):base(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper, collator))
82  {
83  }
84 
85  /// <summary> Constructs a filter for field <c>fieldName</c> matching
86  /// less than or equal to <c>upperTerm</c>.
87  /// </summary>
88  public static TermRangeFilter Less(System.String fieldName, System.String upperTerm)
89  {
90  return new TermRangeFilter(fieldName, null, upperTerm, false, true);
91  }
92 
93  /// <summary> Constructs a filter for field <c>fieldName</c> matching
94  /// greater than or equal to <c>lowerTerm</c>.
95  /// </summary>
96  public static TermRangeFilter More(System.String fieldName, System.String lowerTerm)
97  {
98  return new TermRangeFilter(fieldName, lowerTerm, null, true, false);
99  }
100 
101  /// <summary>Returns the field name for this filter </summary>
102  public virtual string Field
103  {
104  get { return query.Field; }
105  }
106 
107  /// <summary>Returns the lower value of this range filter </summary>
108  public virtual string LowerTerm
109  {
110  get { return query.LowerTerm; }
111  }
112 
113  /// <summary>Returns the upper value of this range filter </summary>
114  public virtual string UpperTerm
115  {
116  get { return query.UpperTerm; }
117  }
118 
119  /// <summary>Returns <c>true</c> if the lower endpoint is inclusive </summary>
120  public virtual bool IncludesLower
121  {
122  get { return query.IncludesLower; }
123  }
124 
125  /// <summary>Returns <c>true</c> if the upper endpoint is inclusive </summary>
126  public virtual bool IncludesUpper
127  {
128  get { return query.IncludesUpper; }
129  }
130 
131  /// <summary>Returns the collator used to determine range inclusion, if any. </summary>
132  public virtual CompareInfo Collator
133  {
134  get { return query.Collator; }
135  }
136  }
137 }