0
0
Fork 0

adding UT

This commit is contained in:
Sreekanth Sivasankaran 2018-01-19 11:47:28 +05:30
parent 039a4df33b
commit 47f1c66889
2 changed files with 77 additions and 2 deletions

View File

@ -481,8 +481,10 @@ func (sr *SearchResult) Merge(other *SearchResult) {
if other.MaxScore > sr.MaxScore {
sr.MaxScore = other.MaxScore
}
if len(sr.Facets) == 0 && len(other.Facets) != 0 {
sr.Facets = make(search.FacetResults)
if sr.Facets == nil && len(other.Facets) != 0 {
sr.Facets = other.Facets
return
}
sr.Facets.Merge(other.Facets)
}

View File

@ -326,3 +326,76 @@ func TestFacetNumericDateRangeRequests(t *testing.T) {
}
}
func TestSearchResultFacetsMerge(t *testing.T) {
lowmed := "2010-01-01"
medhi := "2011-01-01"
hihigher := "2012-01-01"
fr := &search.FacetResult{
Field: "birthday",
Total: 100,
Missing: 25,
Other: 25,
DateRanges: []*search.DateRangeFacet{
{
Name: "low",
End: &lowmed,
Count: 25,
},
{
Name: "med",
Count: 24,
Start: &lowmed,
End: &medhi,
},
{
Name: "hi",
Count: 1,
Start: &medhi,
End: &hihigher,
},
},
}
frs := search.FacetResults{
"birthdays": fr,
}
l := &SearchResult{
Status: &SearchStatus{
Total: 10,
Successful: 1,
Errors: make(map[string]error),
},
Total: 10,
MaxScore: 1,
}
r := &SearchResult{
Status: &SearchStatus{
Total: 1,
Successful: 1,
Errors: make(map[string]error),
},
Total: 1,
MaxScore: 2,
Facets: frs,
}
expected := &SearchResult{
Status: &SearchStatus{
Total: 11,
Successful: 2,
Errors: make(map[string]error),
},
Total: 11,
MaxScore: 2,
Facets: frs,
}
l.Merge(r)
if !reflect.DeepEqual(l, expected) {
t.Errorf("expected %#v, got %#v", expected, l)
}
}