@@ -1044,6 +1044,74 @@ var _ = Describe("RediSearch commands", Label("search"), func() {
10441044 Expect (res2 .Total ).To (BeEquivalentTo (int64 (2 )))
10451045 })
10461046
1047+ It ("should test geoshapes query intersects and disjoint" , Label ("NonRedisEnterprise" ), func () {
1048+ _ , err := client .FTCreate (ctx , "idx1" , & redis.FTCreateOptions {}, & redis.FieldSchema {
1049+ FieldName : "g" ,
1050+ FieldType : redis .SearchFieldTypeGeoShape ,
1051+ GeoShapeFieldType : "FLAT" ,
1052+ }).Result ()
1053+ Expect (err ).NotTo (HaveOccurred ())
1054+
1055+ client .HSet (ctx , "doc_point1" , "g" , "POINT (10 10)" )
1056+ client .HSet (ctx , "doc_point2" , "g" , "POINT (50 50)" )
1057+ client .HSet (ctx , "doc_polygon1" , "g" , "POLYGON ((20 20, 25 35, 35 25, 20 20))" )
1058+ client .HSet (ctx , "doc_polygon2" , "g" , "POLYGON ((60 60, 65 75, 70 70, 65 55, 60 60))" )
1059+
1060+ intersection , err := client .FTSearchWithArgs (ctx , "idx1" , "@g:[intersects $shape]" ,
1061+ & redis.FTSearchOptions {
1062+ DialectVersion : 3 ,
1063+ Params : map [string ]interface {}{"shape" : "POLYGON((15 15, 75 15, 50 70, 20 40, 15 15))" },
1064+ }).Result ()
1065+ Expect (err ).NotTo (HaveOccurred ())
1066+ _assert_geosearch_result (& intersection , []string {"doc_point2" , "doc_polygon1" })
1067+
1068+ disjunction , err := client .FTSearchWithArgs (ctx , "idx1" , "@g:[disjoint $shape]" ,
1069+ & redis.FTSearchOptions {
1070+ DialectVersion : 3 ,
1071+ Params : map [string ]interface {}{"shape" : "POLYGON((15 15, 75 15, 50 70, 20 40, 15 15))" },
1072+ }).Result ()
1073+ Expect (err ).NotTo (HaveOccurred ())
1074+ _assert_geosearch_result (& disjunction , []string {"doc_point1" , "doc_polygon2" })
1075+ })
1076+
1077+ It ("should test geoshapes query contains and within" , func () {
1078+ _ , err := client .FTCreate (ctx , "idx2" , & redis.FTCreateOptions {}, & redis.FieldSchema {
1079+ FieldName : "g" ,
1080+ FieldType : redis .SearchFieldTypeGeoShape ,
1081+ GeoShapeFieldType : "FLAT" ,
1082+ }).Result ()
1083+ Expect (err ).NotTo (HaveOccurred ())
1084+
1085+ client .HSet (ctx , "doc_point1" , "g" , "POINT (10 10)" )
1086+ client .HSet (ctx , "doc_point2" , "g" , "POINT (50 50)" )
1087+ client .HSet (ctx , "doc_polygon1" , "g" , "POLYGON ((20 20, 25 35, 35 25, 20 20))" )
1088+ client .HSet (ctx , "doc_polygon2" , "g" , "POLYGON ((60 60, 65 75, 70 70, 65 55, 60 60))" )
1089+
1090+ containsA , err := client .FTSearchWithArgs (ctx , "idx2" , "@g:[contains $shape]" ,
1091+ & redis.FTSearchOptions {
1092+ DialectVersion : 3 ,
1093+ Params : map [string ]interface {}{"shape" : "POINT(25 25)" },
1094+ }).Result ()
1095+ Expect (err ).NotTo (HaveOccurred ())
1096+ _assert_geosearch_result (& containsA , []string {"doc_polygon1" })
1097+
1098+ containsB , err := client .FTSearchWithArgs (ctx , "idx2" , "@g:[contains $shape]" ,
1099+ & redis.FTSearchOptions {
1100+ DialectVersion : 3 ,
1101+ Params : map [string ]interface {}{"shape" : "POLYGON((24 24, 24 26, 25 25, 24 24))" },
1102+ }).Result ()
1103+ Expect (err ).NotTo (HaveOccurred ())
1104+ _assert_geosearch_result (& containsB , []string {"doc_polygon1" })
1105+
1106+ within , err := client .FTSearchWithArgs (ctx , "idx2" , "@g:[within $shape]" ,
1107+ & redis.FTSearchOptions {
1108+ DialectVersion : 3 ,
1109+ Params : map [string ]interface {}{"shape" : "POLYGON((15 15, 75 15, 50 70, 20 40, 15 15))" },
1110+ }).Result ()
1111+ Expect (err ).NotTo (HaveOccurred ())
1112+ _assert_geosearch_result (& within , []string {"doc_point2" , "doc_polygon1" })
1113+ })
1114+
10471115 It ("should search missing fields" , Label ("search" , "ftcreate" , "ftsearch" , "NonRedisEnterprise" ), func () {
10481116 val , err := client .FTCreate (ctx , "idx1" , & redis.FTCreateOptions {Prefix : []interface {}{"property:" }},
10491117 & redis.FieldSchema {FieldName : "title" , FieldType : redis .SearchFieldTypeText , Sortable : true },
@@ -1135,6 +1203,15 @@ var _ = Describe("RediSearch commands", Label("search"), func() {
11351203 })
11361204})
11371205
1206+ func _assert_geosearch_result (result * redis.FTSearchResult , expectedDocIDs []string ) {
1207+ ids := make ([]string , len (result .Docs ))
1208+ for i , doc := range result .Docs {
1209+ ids [i ] = doc .ID
1210+ }
1211+ Expect (ids ).To (ConsistOf (expectedDocIDs ))
1212+ Expect (result .Total ).To (BeEquivalentTo (len (expectedDocIDs )))
1213+ }
1214+
11381215// It("should FTProfile Search and Aggregate", Label("search", "ftprofile"), func() {
11391216// val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, &redis.FieldSchema{FieldName: "t", FieldType: redis.SearchFieldTypeText}).Result()
11401217// Expect(err).NotTo(HaveOccurred())
0 commit comments