// TODO: Refactor so we can use for BetweenQuery as well? private QueryBase GetSingleTermRangeQuery(BinaryNode node, string propertyName) { var fieldName = GetFormattedFieldName(node); // TODO: Don't think we need to format this? //var valueNode = node.GetValueNode<string>(); //var value = ValueFormatter.FormatValueForIndexStorage(valueNode.Value, fieldName); var valueType = node.GetConstantNode().Type; // TODO: This is a bit dodgy, might need testing. var value = node.GetValueNode <object>().Value; // TODO: Use this for type checking instead? Maybe store the types in a list and do DateTimeTypes.Contains(nodeType) //var valueNode = node.GetConstantNode(); // Add method parameter 'nodeType' //var isDate = valueNode.Type == typeof (DateTime) || valueNode.Type == typeof (DateTime?) || // valueNode.Type == typeof (DateTimeOffset) || valueNode.Type == typeof (DateTimeOffset?); // Number double number; if (double.TryParse(value.ToString(), out number)) { var query = new NumericRangeQuery { Field = fieldName, Boost = node.Boost }; return(SetProperty(query, number, propertyName)); } // Date var date = value as DateTime? ?? (value as DateTimeOffset?)?.UtcDateTime; if (date != null) { var query = new DateRangeQuery { Field = fieldName, Boost = node.Boost }; // TODO: We might need to use RoundTo(). Could we maybe specify this on field configuration? return(SetProperty(query, DateMath.Anchored(date.Value), propertyName)); } // String var term = value as string; if (term != null) { var query = new TermRangeQuery { Field = fieldName, Boost = node.Boost }; return(SetProperty(query, term, propertyName)); } // TODO: Handle or throw special exception for null string (when type is string but it is null) throw new NotSupportedException($"The query node type '{valueType}' is not supported in 'greater than' comparisons. Supported types: numeric, DateTime, DateTimeOffset and string"); }