コード例 #1
0
        private void ProcessFacetRangeBuckets(string root, IFacetRangeParameter <TDocument> facetParameter, string facetName, IFacetItem facetItem, Type fieldType)
        {
            this._jsonReader.Read();// Starts array

            while (this._jsonReader.Path.StartsWith($"{root}.{facetName}.buckets["))
            {
                var initialPath = this._jsonReader.Path;

                this._jsonReader.Read();// "val" property
                var rawMinimumValue = this._jsonReader.ReadAsString();

                this._jsonReader.Read();// "count" property
                var count = (long)this._jsonReader.ReadAsInt32();

                var value = GetFacetItemRangeValue(fieldType, rawMinimumValue);

                var maximumValue = GetMaximumValue(fieldType, value, facetParameter.Gap);

                value.SetMaximumValue(maximumValue);
                value.Quantity = count;

                // Go to next token to verify subfacet
                this._jsonReader.Read();

                // Subfacets
                if (this._jsonReader.TokenType != JsonToken.EndObject)
                {
                    this.GetFacetItems(
                        initialPath,
                        facetParameter.Facets,
                        out var facetItems);

                    value.Facets = facetItems;
                }

                ((List <IFacetItemRangeValue>)((FacetItemRange)facetItem).Values).Add(value);

                // Try closes bucket object
                while (this._jsonReader.TokenType != JsonToken.EndObject)
                {
                    this._jsonReader.Read();
                }

                this._jsonReader.Read();// Starts next bucket object
            }

            this._jsonReader.Read();// Ends array

            var values = ((List <IFacetItemRangeValue>)((FacetItemRange)facetItem).Values);

            if (facetParameter.HardEnd && values.Any())
            {
                var item  = values[values.Count - 1];
                var value = GetParsedRangeValue(fieldType, facetParameter.End);
                if (FirstGreaterThanSecond(fieldType, item.GetMaximumValue(), value))
                {
                    item.SetMaximumValue(value);
                }
            }

            IFacetItemRangeValue facetItemRangeValueBefore = null;

            if (this._jsonReader.Path.Equals($"{root}.{facetName}.before"))
            {
                facetItemRangeValueBefore = GetFacetItemRangeValue(fieldType, rawMaximumValue: facetParameter.Start);

                this._jsonReader.Read(); // Ends property
                this._jsonReader.Read(); // "count" property
                facetItemRangeValueBefore.Quantity = (long)this._jsonReader.ReadAsInt32();

                this._jsonReader.Read(); // Ends property
                this._jsonReader.Read(); // Ends object
            }

            if (this._jsonReader.Path.Equals($"{root}.{facetName}.after"))
            {
                var facetItemRangeValue = GetFacetItemRangeValue(fieldType, facetParameter.End);

                if (!facetParameter.HardEnd)
                {
                    var maximumValue = GetMaximumValue(fieldType, facetItemRangeValue, facetParameter.Gap);
                    facetItemRangeValue.SetMinimumValue(maximumValue);
                }

                this._jsonReader.Read(); // Ends property
                this._jsonReader.Read(); // "count" property
                facetItemRangeValue.Quantity = (long)this._jsonReader.ReadAsInt32();

                ((List <IFacetItemRangeValue>)((FacetItemRange)facetItem).Values).Add(facetItemRangeValue);

                this._jsonReader.Read(); // Ends property
                this._jsonReader.Read(); // Ends object
            }

            // ReSharper disable once InvertIf
            if (facetItemRangeValueBefore != null)
            {
                ((List <IFacetItemRangeValue>)((FacetItemRange)facetItem).Values).Insert(0, facetItemRangeValueBefore);
            }
        }
コード例 #2
0
        private void ProcessFacetFieldBuckets(string root, IFacetParameter <TDocument> facetParameter, string facetName, IFacetItem facetItem)
        {
            this._jsonReader.Read();// Starts array

            while (this._jsonReader.Path.StartsWith($"{root}.{facetName}.buckets["))
            {
                var initialPath = this._jsonReader.Path;

                this._jsonReader.Read();// "val" property
                var key = this._jsonReader.ReadAsString();

                this._jsonReader.Read();// "count" property
                var count = this._jsonReader.ReadAsInt32();

                var value = new FacetItemFieldValue
                {
                    Key      = key,
                    Quantity = (long)count
                };

                // Go to next token to verify subfacet
                this._jsonReader.Read();

                // Subfacets
                if (this._jsonReader.TokenType != JsonToken.EndObject)
                {
                    this.GetFacetItems(
                        initialPath,
                        facetParameter.Facets,
                        out var facetItems);

                    value.Facets = facetItems;
                }

                ((List <FacetItemFieldValue>)((FacetItemField)facetItem).Values).Add(value);

                // Try closes bucket object
                while (this._jsonReader.TokenType != JsonToken.EndObject)
                {
                    this._jsonReader.Read();
                }

                this._jsonReader.Read();// Starts next bucket object
            }
        }