/// <summary>
        /// Execute the JSON object parse in facet field list
        /// </summary>
        /// <param name="parameters">List of the parameters arranged in the queryable class</param>
        /// <param name="jsonObject">JSON object used in the parse</param>
        void IConvertJsonObject.Execute(IEnumerable <ISearchParameter> parameters, JObject jsonObject)
        {
            Checker.IsNull(parameters);
            Checker.IsTrue <UnexpectedJsonFormatException>(jsonObject["facet_counts"]?["facet_fields"] == null, jsonObject.ToString());

            if (!jsonObject["facet_counts"]["facet_fields"].Children().Any())
            {
                this.Data = new List <FacetKeyValue <string> >();
            }
            else
            {
                this.Data = jsonObject["facet_counts"]["facet_fields"]
                            .Children()
                            .Select(item =>
                {
                    var value = new FacetKeyValue <string>
                    {
                        Name = ((JProperty)item).Name,
                        Data = new List <FacetItemValue <string> >()
                    };

                    var array = ((JArray)((JProperty)(item)).Value);

                    for (int i = 0; i < array.Count; i += 2)
                    {
                        ((List <FacetItemValue <string> >)value.Data).Add(new FacetItemValue <string> {
                            Key = array[i].ToObject <string>(), Quantity = array[i + 1].ToObject <long>()
                        });
                    }

                    return(value);
                })
                            .ToList();
            }
        }
        private List <FacetKeyValue <string> > GetFacetRangeViewModelList(IEnumerable <FacetKeyValue <FacetRange> > facetRangeList)
        {
            return(facetRangeList
                   .Select(q =>
            {
                var item = new FacetKeyValue <string>();
                item.Name = q.Name;
                item.Data = q
                            .Data
                            .Select(q2 => new FacetItemValue <string>()
                {
                    Key = string.Format("{0} - {1}", q2.Key.GetMinimumValue() ?? "?", q2.Key.GetMaximumValue() ?? "?"),
                    Quantity = q2.Quantity
                })
                            .ToList();

                return item;
            })
                   .ToList());
        }
        /// <summary>
        /// Execute the parse of the JSON object in facet range list
        /// </summary>
        /// <param name="parameters">List of the parameters arranged in the queryable class</param>
        /// <param name="jsonObject">JSON object used in the parse</param>
        void IConvertJsonObject.Execute(IEnumerable <ISearchParameter> parameters, JObject jsonObject)
        {
            Checker.IsNull(parameters);
            Checker.IsTrue <UnexpectedJsonFormatException>(jsonObject["facet_counts"]?["facet_ranges"] == null, jsonObject.ToString());

            if (!jsonObject["facet_counts"]["facet_ranges"].Children().Any())
            {
                this.Data = new List <FacetKeyValue <FacetRange> >();
                return;
            }

            this.Data = jsonObject["facet_counts"]["facet_ranges"]
                        .Children()
                        .Select(item =>
            {
                var jProperty = ((JProperty)item);

                var facet = new FacetKeyValue <FacetRange>
                {
                    Name = jProperty.Name,
                    Data = new List <FacetItemValue <FacetRange> >()
                };

                var facetParameter = (IFacetRangeParameter <TDocument>)parameters.First(q =>
                {
                    return
                    ((q is IFacetRangeParameter <TDocument>) &&
                     ((IFacetRangeParameter <TDocument>)q).AliasName.Equals(facet.Name));
                });

                var facetType = this._expressionBuilder.GetPropertyTypeFromExpression(facetParameter.Expression);

                var gap      = jProperty.Value["gap"].ToObject <string>();
                var gapValue = this.GetGapValue(gap);

                if (jProperty.Value["before"] != null)
                {
                    var firstValue = this.CreateFacetRange(facetType);
                    firstValue.SetMaximumValue(jProperty.Value["start"].ToObject(facetType));
                    ((List <FacetItemValue <FacetRange> >)facet.Data).Add(new FacetItemValue <FacetRange> {
                        Key = firstValue, Quantity = jProperty.Value["before"].ToObject <long>()
                    });
                }

                for (int index = 0; index < jProperty.Value["counts"].Count(); index += 2)
                {
                    var value = this.CreateFacetRange(facetType);
                    value.SetMinimumValue(jProperty.Value["counts"][index]);
                    value.SetMaximumValue(this.CalculateMaximumValue(facetType, jProperty.Value["counts"][index], gapValue));

                    ((List <FacetItemValue <FacetRange> >)facet.Data).Add(new FacetItemValue <FacetRange> {
                        Key = value, Quantity = jProperty.Value["counts"][index + 1].ToObject <long>()
                    });
                }

                if (jProperty.Value["after"] != null)
                {
                    var lastValue = this.CreateFacetRange(facetType);
                    lastValue.SetMinimumValue(jProperty.Value["end"].ToObject(facetType));
                    ((List <FacetItemValue <FacetRange> >)facet.Data).Add(new FacetItemValue <FacetRange> {
                        Key = lastValue, Quantity = jProperty.Value["after"].ToObject <long>()
                    });
                }

                return(facet);
            })
                        .ToList();
        }
        /// <summary>
        /// Execute the parse of the JSON object in facet range list
        /// </summary>
        /// <param name="parameters">List of the parameters arranged in the queryable class</param>
        /// <param name="jsonObject">JSON object used in the parse</param>
        void IConvertJsonObject.Execute(IEnumerable <ISearchParameter> parameters, JObject jsonObject)
        {
            Checker.IsNull(parameters);

            if (jsonObject["facets"] == null)
            {
                throw new UnexpectedJsonFormatException(jsonObject.ToString());
            }

            var list = jsonObject["facets"]
                       .Children()
                       .Where(q =>
                              q is JProperty &&
                              q.Values().Count() == 3 &&
                              ((JProperty)q).Value is JObject &&
                              ((JProperty)q).Value["buckets"] != null)
                       .ToList();

            if (!list.Any())
            {
                this.Data = new List <FacetKeyValue <FacetRange> >();
                return;
            }

            this.Data = list
                        .Select(item =>
            {
                var jProperty = ((JProperty)item);

                var facet = new FacetKeyValue <FacetRange>
                {
                    Name = jProperty.Name,
                    Data = new List <FacetItemValue <FacetRange> >()
                };

                var facetParameter = (IFacetRangeParameter <TDocument>)parameters.First(q =>
                {
                    return
                    ((q is IFacetRangeParameter <TDocument>) &&
                     ((IFacetRangeParameter <TDocument>)q).AliasName.Equals(facet.Name));
                });

                var facetType = this._expressionBuilder.GetPropertyTypeFromExpression(facetParameter.Expression);

                var gapValue = this.GetGapValue(facetParameter.Gap);

                if (jProperty.Value["before"] != null)
                {
                    var firstValue = this.CreateFacetRange(facetType);
                    firstValue.SetMaximumValue(this.GetFacetValue(facetType, facetParameter.Start));
                    ((List <FacetItemValue <FacetRange> >)facet.Data).Add(new FacetItemValue <FacetRange> {
                        Key = firstValue, Quantity = jProperty.Value["before"]["count"].ToObject <long>()
                    });
                }

                jProperty
                .Value["buckets"]
                .ToList()
                .ForEach(bucket =>
                {
                    var value = this.CreateFacetRange(facetType);

                    value.SetMinimumValue(bucket["val"].ToObject(facetType));
                    value.SetMaximumValue(this.CalculateMaximumValue(facetType, bucket["val"], gapValue));

                    ((List <FacetItemValue <FacetRange> >)facet.Data).Add(new FacetItemValue <FacetRange> {
                        Key = value, Quantity = bucket["count"].ToObject <long>()
                    });
                });

                if (jProperty.Value["after"] != null)
                {
                    var lastValue = this.CreateFacetRange(facetType);
                    lastValue.SetMinimumValue(this.GetFacetValue(facetType, facetParameter.End));
                    ((List <FacetItemValue <FacetRange> >)facet.Data).Add(new FacetItemValue <FacetRange> {
                        Key = lastValue, Quantity = jProperty.Value["after"]["count"].ToObject <long>()
                    });
                }

                return(facet);
            })
                        .ToList();
        }