/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Globalization;
namespace Lucene.Net.Search
{
/// A Filter that restricts search results to a range of values in a given
/// field.
///
/// This filter matches the documents looking for terms that fall into the
/// supplied range according to . It is not intended
/// for numerical ranges, use instead.
///
/// If you construct a large number of range filters with different ranges but on the
/// same field, may have significantly better performance.
///
/// 2.9
///
[Serializable]
public class TermRangeFilter:MultiTermQueryWrapperFilter
{
/// The field this range applies to
///
/// The lower bound on this range
///
/// The upper bound on this range
///
/// Does this range include the lower bound?
///
/// Does this range include the upper bound?
///
/// IllegalArgumentException if both terms are null or if
/// lowerTerm is null and includeLower is true (similar for upperTerm
/// and includeUpper)
///
public TermRangeFilter(System.String fieldName, System.String lowerTerm, System.String upperTerm, bool includeLower, bool includeUpper):base(new TermRangeQuery(fieldName, lowerTerm, upperTerm, includeLower, includeUpper))
{
}
/// WARNING: Using this constructor and supplying a non-null
/// value in the collator parameter will cause every single
/// index Term in the Field referenced by lowerTerm and/or upperTerm to be
/// examined. Depending on the number of index Terms in this Field, the
/// operation could be very slow.
///
///
///
/// The lower bound on this range
///
/// The upper bound on this range
///
/// Does this range include the lower bound?
///
/// Does this range include the upper bound?
///
/// The collator to use when determining range inclusion; set
/// to null to use Unicode code point ordering instead of collation.
///
/// IllegalArgumentException if both terms are null or if
/// lowerTerm is null and includeLower is true (similar for upperTerm
/// and includeUpper)
///
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))
{
}
/// Constructs a filter for field fieldName matching
/// less than or equal to upperTerm.
///
public static TermRangeFilter Less(System.String fieldName, System.String upperTerm)
{
return new TermRangeFilter(fieldName, null, upperTerm, false, true);
}
/// Constructs a filter for field fieldName matching
/// greater than or equal to lowerTerm.
///
public static TermRangeFilter More(System.String fieldName, System.String lowerTerm)
{
return new TermRangeFilter(fieldName, lowerTerm, null, true, false);
}
/// Returns the field name for this filter
public virtual string Field
{
get { return query.Field; }
}
/// Returns the lower value of this range filter
public virtual string LowerTerm
{
get { return query.LowerTerm; }
}
/// Returns the upper value of this range filter
public virtual string UpperTerm
{
get { return query.UpperTerm; }
}
/// Returns true if the lower endpoint is inclusive
public virtual bool IncludesLower
{
get { return query.IncludesLower; }
}
/// Returns true if the upper endpoint is inclusive
public virtual bool IncludesUpper
{
get { return query.IncludesUpper; }
}
/// Returns the collator used to determine range inclusion, if any.
public virtual CompareInfo Collator
{
get { return query.Collator; }
}
}
}