Exemple #1
0
        // [NULL TO 200]
        // {100 TO 1000]
        public static FacetRange Parse(string label, string rangeValue)
        {
            var parts = rangeValue.Split(new[] { " TO " }, 2, StringSplitOptions.RemoveEmptyEntries);
            if (parts.Length != 2)
                throw new ArgumentException("Invalid range " + rangeValue + ".");

            var from = parts[0].Trim();
            var to = parts[1].Trim();

            var range = new FacetRange(label);
            range.FromInclusive = IsInclusive(from.First());
            range.ToInclusive = IsInclusive(to.Last());

            from = from.Substring(1);
            to = to.Substring(0, to.Length - 1);

            if (from != "NULL" && from != "*")
            {
                range.FromValue = Convert.ToDouble(from);
            }
            if (to != "NULL" && to != "*")
            {
                range.ToValue = Convert.ToDouble(to);
            }

            return range;
        }
        public static EncodedFacetRange CreateFrom(FacetRange range)
        {
            var result = new EncodedFacetRange
            {
                Label = range.Label,
                FromInclusive = range.FromInclusive,
                ToInclusive = range.ToInclusive
            };

            if (range.FromValue != null)
            {
                result.FromValue = NumericUtils.DoubleToPrefixCoded(range.FromValue.Value);
            }
            if (range.ToValue != null)
            {
                result.ToValue = NumericUtils.DoubleToPrefixCoded(range.ToValue.Value);
            }

            return result;
        }