public override void PopulateFacet(Facet facet)
        {
            RangeResult.Clear();

            NumericRangeFacet numericRangeFacet = facet as NumericRangeFacet;

            if (numericRangeFacet != null)
            {
                // Iterate the defintion, and see if any have been selected
                foreach (NumericRangeResult result in numericRangeFacet.Ranges)
                {
                    SelectableNumericRangeResult rangeResult = new SelectableNumericRangeResult()
                    {
                        Count      = result.Count,
                        From       = result.From,
                        To         = result.To,
                        Total      = result.Total,
                        TotalCount = result.TotalCount,
                        Min        = result.Min,
                        Max        = result.Max,
                        Mean       = result.Mean
                    };

                    SelectableNumericRange selectedRange = Range.FirstOrDefault(r => r.Id == rangeResult.Id && r.Selected == true);
                    rangeResult.Selected = selectedRange != null;
                    RangeResult.Add(rangeResult);
                }
            }
        }
Exemplo n.º 2
0
        public void ToString_NumericRangeFacet()
        {
            var term = new NumericRangeFacet
            {
                Field = "fieldName",
                Name  = "myNumericFacet",
                Size  = 2,
            }.AddRanges(
                new Range <float> {
                Name = "range1", Start = 0.1F, End = 3.0F
            },
                new Range <float> {
                Name = "range2", Start = 3.1F
            });

            var expected = "\"myNumericFacet\":{\"field\":\"fieldName\",\"size\":2,\"numeric_ranges\":[{\"name\":\"range1\",\"min\":0.1,\"max\":3.0},{\"name\":\"range2\",\"min\":3.1}]}";
            var actual   = term.ToString().Replace(Environment.NewLine, string.Empty).Replace(" ", string.Empty);

            Assert.Equal(expected, actual);
        }