protected override Query GetRangeQuery(string field, string lower, string upper, bool inclusive)
{
if (lower == "NULL" || lower == "*")
lower = null;
if (upper == "NULL" || upper == "*")
upper = null;
if ( (lower == null || !NumericRangeValue.IsMatch(lower)) && (upper == null || !NumericRangeValue.IsMatch(upper)))
{
return NewRangeQuery(field, lower, upper, inclusive);
}
var from = NumberUtil.StringToNumber(lower);
var to = NumberUtil.StringToNumber(upper);
TypeCode numericType;
if (from != null)
numericType = Type.GetTypeCode(from.GetType());
else if (to != null)
numericType = Type.GetTypeCode(to.GetType());
else
numericType = TypeCode.Empty;
switch (numericType)
{
case TypeCode.Int32:
{
return NumericRangeQuery.NewIntRange(field, (int)(from ?? Int32.MinValue), (int)(to ?? Int32.MaxValue), inclusive, inclusive);
}
case TypeCode.Int64:
{
return NumericRangeQuery.NewLongRange(field, (long)(from ?? Int64.MinValue), (long)(to ?? Int64.MaxValue), inclusive, inclusive);
}
case TypeCode.Double:
{
return NumericRangeQuery.NewDoubleRange(field, (double)(from ?? Double.MinValue), (double)(to ?? Double.MaxValue), inclusive, inclusive);
}
case TypeCode.Single:
{
return NumericRangeQuery.NewFloatRange(field, (float)(from ?? Single.MinValue), (float)(to ?? Single.MaxValue), inclusive, inclusive);
}
default:
{
return NewRangeQuery(field, lower, upper, inclusive);
}
}
}