Пример #1
0
        public virtual Query Build(IQueryNode queryNode)
        {
            NumericRangeQueryNode numericRangeNode = (NumericRangeQueryNode)queryNode;

            NumericQueryNode lowerNumericNode = (NumericQueryNode)numericRangeNode.LowerBound;
            NumericQueryNode upperNumericNode = (NumericQueryNode)numericRangeNode.UpperBound;

            J2N.Numerics.Number lowerNumber = lowerNumericNode.Value;
            J2N.Numerics.Number upperNumber = upperNumericNode.Value;

            NumericConfig numericConfig = numericRangeNode.NumericConfig;
            NumericType   numberType    = numericConfig.Type;
            string        field         = StringUtils.ToString(numericRangeNode.Field);
            bool          minInclusive  = numericRangeNode.IsLowerInclusive;
            bool          maxInclusive  = numericRangeNode.IsUpperInclusive;
            int           precisionStep = numericConfig.PrecisionStep;

            switch (numberType)
            {
            case NumericType.INT64:
                return(NumericRangeQuery.NewInt64Range(field, precisionStep,
                                                       lowerNumber?.ToInt64(), upperNumber?.ToInt64(), minInclusive, maxInclusive));

            case NumericType.INT32:
                return(NumericRangeQuery.NewInt32Range(field, precisionStep,
                                                       lowerNumber?.ToInt32(), upperNumber?.ToInt32(), minInclusive,
                                                       maxInclusive));

            case NumericType.SINGLE:
                return(NumericRangeQuery.NewSingleRange(field, precisionStep,
                                                        lowerNumber?.ToSingle(), upperNumber?.ToSingle(), minInclusive,
                                                        maxInclusive));

            case NumericType.DOUBLE:
                return(NumericRangeQuery.NewDoubleRange(field, precisionStep,
                                                        lowerNumber?.ToDouble(), upperNumber?.ToDouble(), minInclusive,
                                                        maxInclusive));

            default:
                // LUCENENET: Factored out NLS/Message/IMessage so end users can optionally utilize the built-in .NET localization.
                throw new QueryNodeException(string.Format(
                                                 QueryParserMessages.UNSUPPORTED_NUMERIC_DATA_TYPE, numberType));
            }
        }