protected override IQueryNode PostProcessNode(IQueryNode node) { if (node is FieldQueryNode fieldNode && !(node.Parent is IRangeQueryNode)) { QueryConfigHandler config = GetQueryConfigHandler(); if (config != null) { FieldConfig fieldConfig = config.GetFieldConfig(fieldNode .GetFieldAsString()); if (fieldConfig != null) { NumericConfig numericConfig = fieldConfig .Get(ConfigurationKeys.NUMERIC_CONFIG); if (numericConfig != null) { NumberFormat numberFormat = numericConfig.NumberFormat; string text = fieldNode.GetTextAsString(); Number number; // LUCENENET: IDE0059: Remove unnecessary value assignment if (text.Length > 0) { try { number = numberFormat.Parse(text); } catch (FormatException e) // LUCENENET: In .NET we are expecting the framework to throw FormatException, not ParseException { // LUCENENET: Factored out NLS/Message/IMessage so end users can optionally utilize the built-in .NET localization. throw new QueryNodeParseException(string.Format( QueryParserMessages.COULD_NOT_PARSE_NUMBER, fieldNode .GetTextAsString(), numberFormat.GetType() .AssemblyQualifiedName), e); } switch (numericConfig.Type) { case NumericType.INT64: number = J2N.Numerics.Int64.GetInstance(number.ToInt64()); break; case NumericType.INT32: number = J2N.Numerics.Int32.GetInstance(number.ToInt32()); break; case NumericType.DOUBLE: number = J2N.Numerics.Double.GetInstance(number.ToDouble()); break; case NumericType.SINGLE: number = J2N.Numerics.Single.GetInstance(number.ToSingle()); break; } } else { // LUCENENET: Factored out NLS/Message/IMessage so end users can optionally utilize the built-in .NET localization. throw new QueryNodeParseException(string.Format( QueryParserMessages.NUMERIC_CANNOT_BE_EMPTY, fieldNode.GetFieldAsString())); } NumericQueryNode lowerNode = new NumericQueryNode(fieldNode .Field, number, numberFormat); NumericQueryNode upperNode = new NumericQueryNode(fieldNode .Field, number, numberFormat); return(new NumericRangeQueryNode(lowerNode, upperNode, true, true, numericConfig)); } } } } return(node); }
protected override IQueryNode PostProcessNode(IQueryNode node) { if (node is FieldQueryNode && !(node.Parent is IRangeQueryNode)) { QueryConfigHandler config = GetQueryConfigHandler(); if (config != null) { FieldQueryNode fieldNode = (FieldQueryNode)node; FieldConfig fieldConfig = config.GetFieldConfig(fieldNode .GetFieldAsString()); if (fieldConfig != null) { NumericConfig numericConfig = fieldConfig .Get(ConfigurationKeys.NUMERIC_CONFIG); if (numericConfig != null) { NumberFormat numberFormat = numericConfig.NumberFormat; string text = fieldNode.GetTextAsString(); /*Number*/ object number = null; if (text.Length > 0) { try { number = numberFormat.Parse(text); } catch (FormatException e) { throw new QueryNodeParseException(new MessageImpl( QueryParserMessages.COULD_NOT_PARSE_NUMBER, fieldNode .GetTextAsString(), numberFormat.GetType() .AssemblyQualifiedName), e); } switch (numericConfig.Type) { case FieldType.NumericType.LONG: number = Convert.ToInt64(number); break; case FieldType.NumericType.INT: number = Convert.ToInt32(number); break; case FieldType.NumericType.DOUBLE: number = Convert.ToDouble(number); break; case FieldType.NumericType.FLOAT: number = Convert.ToSingle(number); break; } } else { throw new QueryNodeParseException(new MessageImpl( QueryParserMessages.NUMERIC_CANNOT_BE_EMPTY, fieldNode.GetFieldAsString())); } NumericQueryNode lowerNode = new NumericQueryNode(fieldNode .Field, number, numberFormat); NumericQueryNode upperNode = new NumericQueryNode(fieldNode .Field, number, numberFormat); return(new NumericRangeQueryNode(lowerNode, upperNode, true, true, numericConfig)); } } } } return(node); }
protected override IQueryNode PostProcessNode(IQueryNode node) { if (node is TermRangeQueryNode) { QueryConfigHandler config = GetQueryConfigHandler(); if (config != null) { TermRangeQueryNode termRangeNode = (TermRangeQueryNode)node; FieldConfig fieldConfig = config.GetFieldConfig(StringUtils .ToString(termRangeNode.Field)); if (fieldConfig != null) { NumericConfig numericConfig = fieldConfig .Get(ConfigurationKeys.NUMERIC_CONFIG); if (numericConfig != null) { FieldQueryNode lower = (FieldQueryNode)termRangeNode.LowerBound; FieldQueryNode upper = (FieldQueryNode)termRangeNode.UpperBound; string lowerText = lower.GetTextAsString(); string upperText = upper.GetTextAsString(); NumberFormat numberFormat = numericConfig.NumberFormat; /*Number*/ object lowerNumber = null, upperNumber = null; if (lowerText.Length > 0) { try { lowerNumber = numberFormat.Parse(lowerText); } catch (FormatException e) { throw new QueryNodeParseException(new MessageImpl( QueryParserMessages.COULD_NOT_PARSE_NUMBER, lower .GetTextAsString(), numberFormat.GetType() .AssemblyQualifiedName), e); } } if (upperText.Length > 0) { try { upperNumber = numberFormat.Parse(upperText); } catch (FormatException e) { throw new QueryNodeParseException(new MessageImpl( QueryParserMessages.COULD_NOT_PARSE_NUMBER, upper .GetTextAsString(), numberFormat.GetType() .AssemblyQualifiedName), e); } } switch (numericConfig.Type) { case FieldType.NumericType.LONG: if (upperNumber != null) { upperNumber = Convert.ToInt64(upperNumber); } if (lowerNumber != null) { lowerNumber = Convert.ToInt64(lowerNumber); } break; case FieldType.NumericType.INT: if (upperNumber != null) { upperNumber = Convert.ToInt32(upperNumber); } if (lowerNumber != null) { lowerNumber = Convert.ToInt32(lowerNumber); } break; case FieldType.NumericType.DOUBLE: if (upperNumber != null) { upperNumber = Convert.ToDouble(upperNumber); } if (lowerNumber != null) { lowerNumber = Convert.ToDouble(lowerNumber); } break; case FieldType.NumericType.FLOAT: if (upperNumber != null) { upperNumber = Convert.ToSingle(upperNumber); } if (lowerNumber != null) { lowerNumber = Convert.ToSingle(lowerNumber); } break; } NumericQueryNode lowerNode = new NumericQueryNode( termRangeNode.Field, lowerNumber, numberFormat); NumericQueryNode upperNode = new NumericQueryNode( termRangeNode.Field, upperNumber, numberFormat); bool lowerInclusive = termRangeNode.IsLowerInclusive; bool upperInclusive = termRangeNode.IsUpperInclusive; return(new NumericRangeQueryNode(lowerNode, upperNode, lowerInclusive, upperInclusive, numericConfig)); } } } } return(node); }