51a59cb05c
an IndexAlias allows you easily work with one logical Index while changing the actual Index its pointing to behind the scenes Changing which actual Index is backing an IndexAlias can be done atomically so that your application smoothly transitions from one Index to another. A separate use of IndexAlias is allowed when the IndexAlias is defined to point to multiple Indexes. In this case only the Search() operation is supported, but the Search will be run on each of the underlying indexes in parallel, and the results will be merged.
106 lines
1.5 KiB
Go
106 lines
1.5 KiB
Go
package search
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestFacetResultsMerge(t *testing.T) {
|
|
|
|
fr1 := &FacetResult{
|
|
Field: "type",
|
|
Total: 100,
|
|
Missing: 25,
|
|
Other: 25,
|
|
Terms: []*TermFacet{
|
|
&TermFacet{
|
|
Term: "blog",
|
|
Count: 25,
|
|
},
|
|
&TermFacet{
|
|
Term: "comment",
|
|
Count: 24,
|
|
},
|
|
&TermFacet{
|
|
Term: "feedback",
|
|
Count: 1,
|
|
},
|
|
},
|
|
}
|
|
fr1Only := &FacetResult{
|
|
Field: "category",
|
|
Total: 97,
|
|
Missing: 22,
|
|
Other: 15,
|
|
Terms: []*TermFacet{
|
|
&TermFacet{
|
|
Term: "clothing",
|
|
Count: 35,
|
|
},
|
|
&TermFacet{
|
|
Term: "electronics",
|
|
Count: 25,
|
|
},
|
|
},
|
|
}
|
|
frs1 := FacetResults{
|
|
"types": fr1,
|
|
"categories": fr1Only,
|
|
}
|
|
|
|
fr2 := &FacetResult{
|
|
Field: "type",
|
|
Total: 100,
|
|
Missing: 25,
|
|
Other: 25,
|
|
Terms: []*TermFacet{
|
|
&TermFacet{
|
|
Term: "blog",
|
|
Count: 25,
|
|
},
|
|
&TermFacet{
|
|
Term: "comment",
|
|
Count: 22,
|
|
},
|
|
&TermFacet{
|
|
Term: "flag",
|
|
Count: 3,
|
|
},
|
|
},
|
|
}
|
|
frs2 := FacetResults{
|
|
"types": fr2,
|
|
}
|
|
|
|
expectedFr := &FacetResult{
|
|
Field: "type",
|
|
Total: 200,
|
|
Missing: 50,
|
|
Other: 51,
|
|
Terms: []*TermFacet{
|
|
&TermFacet{
|
|
Term: "blog",
|
|
Count: 50,
|
|
},
|
|
&TermFacet{
|
|
Term: "comment",
|
|
Count: 46,
|
|
},
|
|
&TermFacet{
|
|
Term: "flag",
|
|
Count: 3,
|
|
},
|
|
},
|
|
}
|
|
expectedFrs := FacetResults{
|
|
"types": expectedFr,
|
|
"categories": fr1Only,
|
|
}
|
|
|
|
frs1.Merge(frs2)
|
|
frs1.Fixup("types", 3)
|
|
if !reflect.DeepEqual(frs1, expectedFrs) {
|
|
t.Errorf("expected %v, got %v", expectedFrs, frs1)
|
|
}
|
|
}
|