parent
54b06ce0f6
commit
7e02e616ce
|
@ -362,7 +362,18 @@ func (dm *DocumentMapping) walkDocument(data interface{}, path []string, indexes
|
||||||
if ptrElem.IsValid() && ptrElem.CanInterface() {
|
if ptrElem.IsValid() && ptrElem.CanInterface() {
|
||||||
dm.processProperty(ptrElem.Interface(), path, indexes, context)
|
dm.processProperty(ptrElem.Interface(), path, indexes, context)
|
||||||
}
|
}
|
||||||
|
case reflect.String:
|
||||||
|
dm.processProperty(val.String(), path, indexes, context)
|
||||||
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
|
dm.processProperty(float64(val.Int()), path, indexes, context)
|
||||||
|
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||||
|
dm.processProperty(float64(val.Uint()), path, indexes, context)
|
||||||
|
case reflect.Float32, reflect.Float64:
|
||||||
|
dm.processProperty(float64(val.Float()), path, indexes, context)
|
||||||
|
case reflect.Bool:
|
||||||
|
dm.processProperty(val.Bool(), path, indexes, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dm *DocumentMapping) processProperty(property interface{}, path []string, indexes []uint64, context *walkContext) {
|
func (dm *DocumentMapping) processProperty(property interface{}, path []string, indexes []uint64, context *walkContext) {
|
||||||
|
|
|
@ -724,3 +724,37 @@ func TestAnonymousStructFieldWithJSONStructTagEmptString(t *testing.T) {
|
||||||
t.Errorf("expected field named 'key', got '%s'", doc.Fields[0].Name())
|
t.Errorf("expected field named 'key', got '%s'", doc.Fields[0].Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMappingPrimitives(t *testing.T) {
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
data interface{}
|
||||||
|
}{
|
||||||
|
{data: "marty"},
|
||||||
|
{data: int(1)},
|
||||||
|
{data: int8(2)},
|
||||||
|
{data: int16(3)},
|
||||||
|
{data: int32(4)},
|
||||||
|
{data: int64(5)},
|
||||||
|
{data: uint(6)},
|
||||||
|
{data: uint8(7)},
|
||||||
|
{data: uint16(8)},
|
||||||
|
{data: uint32(9)},
|
||||||
|
{data: uint64(10)},
|
||||||
|
{data: float32(11.0)},
|
||||||
|
{data: float64(12.0)},
|
||||||
|
{data: false},
|
||||||
|
}
|
||||||
|
|
||||||
|
m := NewIndexMapping()
|
||||||
|
for _, test := range tests {
|
||||||
|
doc := document.NewDocument("x")
|
||||||
|
err := m.mapDocument(doc, test.data)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(doc.Fields) != 1 {
|
||||||
|
t.Errorf("expected 1 field, got %d for %v", len(doc.Fields), test.data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user