Merge pull request #493 from mschoch/fix492
numeric range facet merging compare range values not pointers
This commit is contained in:
commit
a3f8953c9f
@ -105,11 +105,34 @@ type NumericRangeFacet struct {
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
func (nrf *NumericRangeFacet) Same(other *NumericRangeFacet) bool {
|
||||
if nrf.Min == nil && other.Min != nil {
|
||||
return false
|
||||
}
|
||||
if nrf.Min != nil && other.Min == nil {
|
||||
return false
|
||||
}
|
||||
if nrf.Min != nil && other.Min != nil && *nrf.Min != *other.Min {
|
||||
return false
|
||||
}
|
||||
if nrf.Max == nil && other.Max != nil {
|
||||
return false
|
||||
}
|
||||
if nrf.Max != nil && other.Max == nil {
|
||||
return false
|
||||
}
|
||||
if nrf.Max != nil && other.Max != nil && *nrf.Max != *other.Max {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
type NumericRangeFacets []*NumericRangeFacet
|
||||
|
||||
func (nrf NumericRangeFacets) Add(numericRangeFacet *NumericRangeFacet) NumericRangeFacets {
|
||||
for _, existingNr := range nrf {
|
||||
if numericRangeFacet.Min == existingNr.Min && numericRangeFacet.Max == existingNr.Max {
|
||||
if numericRangeFacet.Same(existingNr) {
|
||||
existingNr.Count += numericRangeFacet.Count
|
||||
return nrf
|
||||
}
|
||||
|
@ -124,6 +124,11 @@ func TestNumericFacetResultsMerge(t *testing.T) {
|
||||
medhi := 6.0
|
||||
hihigher := 9.0
|
||||
|
||||
// why second copy? the pointers may be different, but values the same
|
||||
lowmed2 := 3.0
|
||||
medhi2 := 6.0
|
||||
hihigher2 := 9.0
|
||||
|
||||
fr1 := &FacetResult{
|
||||
Field: "rating",
|
||||
Total: 100,
|
||||
@ -161,18 +166,18 @@ func TestNumericFacetResultsMerge(t *testing.T) {
|
||||
NumericRanges: []*NumericRangeFacet{
|
||||
{
|
||||
Name: "low",
|
||||
Max: &lowmed,
|
||||
Max: &lowmed2,
|
||||
Count: 25,
|
||||
},
|
||||
{
|
||||
Name: "med",
|
||||
Max: &lowmed,
|
||||
Min: &medhi,
|
||||
Max: &lowmed2,
|
||||
Min: &medhi2,
|
||||
Count: 22,
|
||||
},
|
||||
{
|
||||
Name: "highest",
|
||||
Min: &hihigher,
|
||||
Min: &hihigher2,
|
||||
Count: 3,
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user