Exemplo n.º 1
0
 /// <summary>
 /// Constructs a <see cref="NumericConfig"/> object.
 /// </summary>
 /// <param name="precisionStep">the precision used to index the numeric values</param>
 /// <param name="format">the <see cref="NumberFormat"/> used to parse a <see cref="string"/> to an <see cref="object"/> representing a .NET numeric type.</param>
 /// <param name="type">the numeric type used to index the numeric values</param>
 /// <seealso cref="NumericConfig.PrecisionStep"/>
 /// <seealso cref="NumericConfig.NumberFormat"/>
 /// <seealso cref="Type"/>
 public NumericConfig(int precisionStep, NumberFormat format,
                      FieldType.NumericType type)
 {
     PrecisionStep = precisionStep;
     NumberFormat  = format;
     Type          = type;
 }
Exemplo n.º 2
0
        public virtual Query Build(IQueryNode queryNode)
        {
            NumericRangeQueryNode numericRangeNode = (NumericRangeQueryNode)queryNode;

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

            /*Number*/
            object lowerNumber = lowerNumericNode.Value;
            /*Number*/
            object upperNumber = upperNumericNode.Value;

            NumericConfig numericConfig = numericRangeNode.NumericConfig;

            FieldType.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 FieldType.NumericType.LONG:
                return(NumericRangeQuery.NewLongRange(field, precisionStep,
                                                      (long?)lowerNumber, (long?)upperNumber, minInclusive, maxInclusive));

            case FieldType.NumericType.INT:
                return(NumericRangeQuery.NewIntRange(field, precisionStep,
                                                     (int?)lowerNumber, (int?)upperNumber, minInclusive,
                                                     maxInclusive));

            case FieldType.NumericType.FLOAT:
                return(NumericRangeQuery.NewFloatRange(field, precisionStep,
                                                       (float?)lowerNumber, (float?)upperNumber, minInclusive,
                                                       maxInclusive));

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

            default:
                throw new QueryNodeException(new MessageImpl(
                                                 QueryParserMessages.UNSUPPORTED_NUMERIC_DATA_TYPE, numberType));
            }
        }