Esempio n. 1
0
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is IFieldableNode fieldNode &&
                (node.Parent == null || !(node.Parent is IFieldableNode)))
            {
                QueryConfigHandler config = GetQueryConfigHandler();

                if (config != null)
                {
                    string      field       = fieldNode.Field;
                    FieldConfig fieldConfig = config.GetFieldConfig(StringUtils.ToString(field));

                    if (fieldConfig != null)
                    {
                        float?boost = fieldConfig.Get(ConfigurationKeys.BOOST);

                        if (boost != null)
                        {
                            return(new BoostQueryNode(node, boost.Value));
                        }
                    }
                }
            }

            return(node);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is TermRangeQueryNode termRangeNode)
            {
                QueryConfigHandler config = GetQueryConfigHandler();

                if (config != null)
                {
                    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;
                            J2N.Numerics.Number lowerNumber = null, upperNumber = null;

                            if (lowerText.Length > 0)
                            {
                                try
                                {
                                    lowerNumber = numberFormat.Parse(lowerText);
                                }
                                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, lower
                                                                          .GetTextAsString(), numberFormat.ToString()), e);
                                }
                            }

                            if (upperText.Length > 0)
                            {
                                try
                                {
                                    upperNumber = numberFormat.Parse(upperText);
                                }
                                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, upper
                                                                          .GetTextAsString(), numberFormat.ToString()), e);
                                }
                            }

                            switch (numericConfig.Type)
                            {
                            case NumericType.INT64:
                                if (upperNumber != null)
                                {
                                    upperNumber = J2N.Numerics.Int64.GetInstance(upperNumber.ToInt64());
                                }
                                if (lowerNumber != null)
                                {
                                    lowerNumber = J2N.Numerics.Int64.GetInstance(lowerNumber.ToInt64());
                                }
                                break;

                            case NumericType.INT32:
                                if (upperNumber != null)
                                {
                                    upperNumber = J2N.Numerics.Int32.GetInstance(upperNumber.ToInt32());
                                }
                                if (lowerNumber != null)
                                {
                                    lowerNumber = J2N.Numerics.Int32.GetInstance(lowerNumber.ToInt32());
                                }
                                break;

                            case NumericType.DOUBLE:
                                if (upperNumber != null)
                                {
                                    upperNumber = J2N.Numerics.Double.GetInstance(upperNumber.ToDouble());
                                }
                                if (lowerNumber != null)
                                {
                                    lowerNumber = J2N.Numerics.Double.GetInstance(lowerNumber.ToDouble());
                                }
                                break;

                            case NumericType.SINGLE:
                                if (upperNumber != null)
                                {
                                    upperNumber = J2N.Numerics.Single.GetInstance(upperNumber.ToSingle());
                                }
                                if (lowerNumber != null)
                                {
                                    lowerNumber = J2N.Numerics.Single.GetInstance(lowerNumber.ToSingle());
                                }
                                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);
        }
        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 Message(
                                                                          QueryParserMessages.COULD_NOT_PARSE_NUMBER, lower
                                                                          .GetTextAsString(), numberFormat.ToString()), e);
                                }
                            }

                            if (upperText.Length > 0)
                            {
                                try
                                {
                                    upperNumber = numberFormat.Parse(upperText);
                                }
                                catch (FormatException e)
                                {
                                    throw new QueryNodeParseException(new Message(
                                                                          QueryParserMessages.COULD_NOT_PARSE_NUMBER, upper
                                                                          .GetTextAsString(), numberFormat.ToString()), e);
                                }
                            }

                            switch (numericConfig.Type)
                            {
                            case NumericType.INT64:
                                if (upperNumber != null)
                                {
                                    upperNumber = Convert.ToInt64(upperNumber);                          // LUCENENET TODO: Find a way to pass culture
                                }
                                if (lowerNumber != null)
                                {
                                    lowerNumber = Convert.ToInt64(lowerNumber);
                                }
                                break;

                            case NumericType.INT32:
                                if (upperNumber != null)
                                {
                                    upperNumber = Convert.ToInt32(upperNumber);                          // LUCENENET TODO: Find a way to pass culture
                                }
                                if (lowerNumber != null)
                                {
                                    lowerNumber = Convert.ToInt32(lowerNumber);
                                }
                                break;

                            case NumericType.DOUBLE:
                                if (upperNumber != null)
                                {
                                    upperNumber = Convert.ToDouble(upperNumber);                          // LUCENENET TODO: Find a way to pass culture
                                }
                                if (lowerNumber != null)
                                {
                                    lowerNumber = Convert.ToDouble(lowerNumber);
                                }
                                break;

                            case NumericType.SINGLE:
                                if (upperNumber != null)
                                {
                                    upperNumber = Convert.ToSingle(upperNumber);                          // LUCENENET TODO: Find a way to pass culture
                                }
                                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);
        }
Esempio n. 5
0
        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);
        }