0
0
Fork 0

properly return multi-value fields in an array

This commit is contained in:
Marty Schoch 2014-11-19 15:55:09 -05:00
parent 19305c6b5f
commit eb16b3c563
1 changed files with 14 additions and 1 deletions

View File

@ -48,7 +48,20 @@ func (dm *DocumentMatch) AddFieldValue(name string, value interface{}) {
if dm.Fields == nil {
dm.Fields = make(map[string]interface{})
}
dm.Fields[name] = value
existingVal, ok := dm.Fields[name]
if ok {
valSlice, ok := existingVal.([]interface{})
if ok {
// already a slice, append to it
valSlice = append(valSlice, value)
} else {
// create a slice
valSlice = []interface{}{existingVal, value}
}
dm.Fields[name] = valSlice
} else {
dm.Fields[name] = value
}
}
type DocumentMatchCollection []*DocumentMatch