public virtual Query GetQuery(XmlElement e)
{
string field = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
string lowerTerm = DOMUtils.GetAttributeOrFail(e, "lowerTerm");
string upperTerm = DOMUtils.GetAttributeOrFail(e, "upperTerm");
bool lowerInclusive = DOMUtils.GetAttribute(e, "includeLower", true);
bool upperInclusive = DOMUtils.GetAttribute(e, "includeUpper", true);
int precisionStep = DOMUtils.GetAttribute(e, "precisionStep", NumericUtils.PRECISION_STEP_DEFAULT);
string type = DOMUtils.GetAttribute(e, "type", "int");
try
{
Query filter;
if (type.Equals("int", StringComparison.OrdinalIgnoreCase))
{
filter = NumericRangeQuery.NewIntRange(field, precisionStep, Convert
.ToInt32(lowerTerm), Convert.ToInt32(upperTerm), lowerInclusive,
upperInclusive);
}
else if (type.Equals("long", StringComparison.OrdinalIgnoreCase))
{
filter = NumericRangeQuery.NewLongRange(field, precisionStep, Convert
.ToInt64(lowerTerm), Convert.ToInt64(upperTerm), lowerInclusive,
upperInclusive);
}
else if (type.Equals("double", StringComparison.OrdinalIgnoreCase))
{
filter = NumericRangeQuery.NewDoubleRange(field, precisionStep, Convert
.ToDouble(lowerTerm), Convert.ToDouble(upperTerm), lowerInclusive,
upperInclusive);
}
else if (type.Equals("float", StringComparison.OrdinalIgnoreCase))
{
filter = NumericRangeQuery.NewFloatRange(field, precisionStep, Convert
.ToSingle(lowerTerm), Convert.ToSingle(upperTerm), lowerInclusive,
upperInclusive);
}
else
{
throw new ParserException("type attribute must be one of: [long, int, double, float]");
}
return filter;
}
catch (FormatException nfe)
{
throw new ParserException("Could not parse lowerTerm or upperTerm into a number", nfe);
}
}
}