@@ -901,8 +901,22 @@ func TestClient_CreateIndex(t *testing.T) {
901901
902902 // Create a schema
903903 schema := NewSchema (DefaultOptions ).
904- AddField (NewTextFieldOptions ("name" , TextFieldOptions {Sortable : true , PhoneticMatcher : PhoneticDoubleMetaphoneEnglish })).
905- AddField (NewNumericField ("age" ))
904+ AddField (NewGeoField ("geo" )). // There are no useful opttions for geo field at this time
905+ AddField (
906+ NewTagFieldOptions (
907+ "tags" ,
908+ TagFieldOptions {Separator : '|' },
909+ )).
910+ AddField (
911+ NewTextFieldOptions (
912+ "name" ,
913+ TextFieldOptions {Sortable : true , PhoneticMatcher : PhoneticDoubleMetaphoneEnglish },
914+ )).
915+ AddField (
916+ NewNumericFieldOptions (
917+ "age" ,
918+ NumericFieldOptions {Sortable : true },
919+ ))
906920
907921 // IndexDefinition is available for RediSearch 2.0+
908922 // In this example we will only index keys started by product:
@@ -914,9 +928,9 @@ func TestClient_CreateIndex(t *testing.T) {
914928
915929 // Create docs with a name that has the same phonetic matcher
916930 vanillaConnection := c .pool .Get ()
917- _ , err = vanillaConnection .Do ("HSET" , "create-index-info:doc1" , "name" , "Jon" , "age" , 25 )
931+ _ , err = vanillaConnection .Do ("HSET" , "create-index-info:doc1" , "name" , "Jon" , "age" , 25 , "tags" , "tag1|tag2" , "geo" , "40.7222756,-73.9977894" )
918932 assert .Nil (t , err )
919- _ , err = vanillaConnection .Do ("HSET" , "create-index-info:doc2" , "name" , "John" , "age" , 20 )
933+ _ , err = vanillaConnection .Do ("HSET" , "create-index-info:doc2" , "name" , "John" , "age" , 20 , "tags" , "tag1|tag2" , "geo" , "40.7222756,-73.9977894" )
920934 assert .Nil (t , err )
921935
922936 // Wait for all documents to be indexed
@@ -937,6 +951,24 @@ func TestClient_CreateIndex(t *testing.T) {
937951 assert .Equal (t , 2 , total )
938952 assert .Equal (t , "Jon" , docs [0 ].Properties ["name" ])
939953 assert .Equal (t , "John" , docs [1 ].Properties ["name" ])
954+
955+ // Verify that each of the field types is correct
956+ for _ , f := range info .Schema .Fields {
957+ switch {
958+ case f .Name == "age" :
959+ assert .Equal (t , 1 , int (f .Type ))
960+ assert .Equal (t , true , f .Options .(NumericFieldOptions ).Sortable )
961+ case f .Name == "name" :
962+ assert .Equal (t , 0 , int (f .Type ))
963+ assert .Equal (t , true , f .Options .(TextFieldOptions ).Sortable )
964+ case f .Name == "tags" :
965+ assert .Equal (t , 3 , int (f .Type ))
966+ // Verify that the tags separators is | or 0x7c
967+ assert .Equal (t , uint8 (0x7c ), f .Options .(TagFieldOptions ).Separator )
968+ case f .Name == "geo" :
969+ assert .Equal (t , 2 , int (f .Type ))
970+ }
971+ }
940972}
941973
942974func TestClient_CreateJsonIndex (t * testing.T ) {
0 commit comments