parse size and field for facets, print facet results
This commit is contained in:
parent
8891a3688d
commit
944fae27f0
16
search.go
16
search.go
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue