0
0
Fork 0

parse size and field for facets, print facet results

This commit is contained in:
Marty Schoch 2015-01-22 09:55:20 -05:00
parent 8891a3688d
commit 944fae27f0
1 changed files with 14 additions and 2 deletions

View File

@ -74,8 +74,8 @@ func (dr *dateTimeRange) UnmarshalJSON(input []byte) error {
// of the result document set you would like to be
// built.
type FacetRequest struct {
Size int
Field string
Size int `json:"size"`
Field string `json:"field"`
NumericRanges []*numericRange `json:"numeric_ranges,omitempty"`
DateTimeRanges []*dateTimeRange `json:"date_ranges,omitempty"`
}
@ -272,6 +272,18 @@ func (sr *SearchResult) String() string {
} else {
rv = "No matches"
}
if len(sr.Facets) > 0 {
rv += fmt.Sprintf("Facets:\n")
for fn, f := range sr.Facets {
rv += fmt.Sprintf("%s(%d)\n", fn, f.Total)
for _, t := range f.Terms {
rv += fmt.Sprintf("\t%s(%d)\n", t.Term, t.Count)
}
if f.Other != 0 {
rv += fmt.Sprintf("\tOther(%d)\n", f.Other)
}
}
}
return rv
}