/*
* 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 NumericTokenStream = Lucene.Net.Analysis.NumericTokenStream;
using NumericField = Lucene.Net.Documents.NumericField;
using NumericUtils = Lucene.Net.Util.NumericUtils;
namespace Lucene.Net.Search
{
/// A that only accepts numeric values within
/// a specified range. To use this, you must first index the
/// numeric values using (expert:
///).
///
/// You create a new NumericRangeFilter with the static
/// factory methods, eg:
///
///
/// Filter f = NumericRangeFilter.newFloatRange("weight",
/// new Float(0.3f), new Float(0.10f),
/// true, true);
///
///
/// accepts all documents whose float valued "weight" field
/// ranges from 0.3 to 0.10, inclusive.
/// See for details on how Lucene
/// indexes and searches numeric valued fields.
///
/// NOTE: This API is experimental and
/// might change in incompatible ways in the next
/// release.
///
///
/// 2.9
///
///
[Serializable]
public sealed class NumericRangeFilter:MultiTermQueryWrapperFilter
{
private NumericRangeFilter(NumericRangeQuery query):base(query)
{
}
/// Factory that creates a NumericRangeFilter, that filters a long
/// range using the given precisionStep.
/// You can have half-open ranges (which are in fact </≤ or >/≥ queries)
/// by setting the min or max value to null. By setting inclusive to false, it will
/// match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
///
public static NumericRangeFilter NewLongRange(System.String field, int precisionStep, System.ValueType min, System.ValueType max, bool minInclusive, bool maxInclusive)
{
return new NumericRangeFilter(NumericRangeQuery.NewLongRange(field, precisionStep, min, max, minInclusive, maxInclusive));
}
/// Factory that creates a NumericRangeFilter, that queries a long
/// range using the default precisionStep (4).
/// You can have half-open ranges (which are in fact </≤ or >/≥ queries)
/// by setting the min or max value to null. By setting inclusive to false, it will
/// match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
///
public static NumericRangeFilter NewLongRange(System.String field, System.ValueType min, System.ValueType max, bool minInclusive, bool maxInclusive)
{
return new NumericRangeFilter(NumericRangeQuery.NewLongRange(field, min, max, minInclusive, maxInclusive));
}
/// Factory that creates a NumericRangeFilter, that filters a int
/// range using the given precisionStep.
/// You can have half-open ranges (which are in fact </≤ or >/≥ queries)
/// by setting the min or max value to null. By setting inclusive to false, it will
/// match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
///
public static NumericRangeFilter NewIntRange(System.String field, int precisionStep, System.ValueType min, System.ValueType max, bool minInclusive, bool maxInclusive)
{
return new NumericRangeFilter(NumericRangeQuery.NewIntRange(field, precisionStep, min, max, minInclusive, maxInclusive));
}
/// Factory that creates a NumericRangeFilter, that queries a int
/// range using the default precisionStep (4).
/// You can have half-open ranges (which are in fact </≤ or >/≥ queries)
/// by setting the min or max value to null. By setting inclusive to false, it will
/// match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
///
public static NumericRangeFilter NewIntRange(System.String field, System.ValueType min, System.ValueType max, bool minInclusive, bool maxInclusive)
{
return new NumericRangeFilter(NumericRangeQuery.NewIntRange(field, min, max, minInclusive, maxInclusive));
}
/// Factory that creates a NumericRangeFilter, that filters a double
/// range using the given precisionStep.
/// You can have half-open ranges (which are in fact </≤ or >/≥ queries)
/// by setting the min or max value to null. By setting inclusive to false, it will
/// match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
///
public static NumericRangeFilter NewDoubleRange(System.String field, int precisionStep, System.Double min, System.Double max, bool minInclusive, bool maxInclusive)
{
return new NumericRangeFilter(NumericRangeQuery.NewDoubleRange(field, precisionStep, min, max, minInclusive, maxInclusive));
}
/// Factory that creates a NumericRangeFilter, that queries a double
/// range using the default precisionStep (4).
/// You can have half-open ranges (which are in fact </≤ or >/≥ queries)
/// by setting the min or max value to null. By setting inclusive to false, it will
/// match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
///
public static NumericRangeFilter NewDoubleRange(System.String field, System.Double min, System.Double max, bool minInclusive, bool maxInclusive)
{
return new NumericRangeFilter(NumericRangeQuery.NewDoubleRange(field, min, max, minInclusive, maxInclusive));
}
/// Factory that creates a NumericRangeFilter, that filters a float
/// range using the given precisionStep.
/// You can have half-open ranges (which are in fact </≤ or >/≥ queries)
/// by setting the min or max value to null. By setting inclusive to false, it will
/// match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
///
public static NumericRangeFilter NewFloatRange(System.String field, int precisionStep, System.Single min, System.Single max, bool minInclusive, bool maxInclusive)
{
return new NumericRangeFilter(NumericRangeQuery.NewFloatRange(field, precisionStep, min, max, minInclusive, maxInclusive));
}
/// Factory that creates a NumericRangeFilter, that queries a float
/// range using the default precisionStep (4).
/// You can have half-open ranges (which are in fact </≤ or >/≥ queries)
/// by setting the min or max value to null. By setting inclusive to false, it will
/// match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
///
public static NumericRangeFilter NewFloatRange(System.String field, System.Single min, System.Single max, bool minInclusive, bool maxInclusive)
{
return new NumericRangeFilter(NumericRangeQuery.NewFloatRange(field, min, max, minInclusive, maxInclusive));
}
/// Returns the field name for this filter
public System.String GetField()
{
return ((NumericRangeQuery) query).GetField();
}
/// Returns true if the lower endpoint is inclusive
public bool IncludesMin()
{
return ((NumericRangeQuery) query).IncludesMin();
}
/// Returns true if the upper endpoint is inclusive
public bool IncludesMax()
{
return ((NumericRangeQuery) query).IncludesMax();
}
/// Returns the lower value of this range filter
public System.ValueType GetMin()
{
return ((NumericRangeQuery) query).GetMin();
}
/// Returns the upper value of this range filter
public System.ValueType GetMax()
{
return ((NumericRangeQuery) query).GetMax();
}
}
}