@@ -428,42 +428,42 @@ public void geoShapeFilterSpherical() throws ParseException {
428
428
final Polygon small = factory .createPolygon (new Coordinate []{new Coordinate (34.9001 , 29.7001 ),
429
429
new Coordinate (34.9001 , 29.7100 ), new Coordinate (34.9100 , 29.7100 ),
430
430
new Coordinate (34.9100 , 29.7001 ), new Coordinate (34.9001 , 29.7001 )});
431
- client .hset ("small" , "geom" , small . toString () );
431
+ client .hsetObject ("small" , "geom" , small );
432
432
433
433
final Polygon large = factory .createPolygon (new Coordinate []{new Coordinate (34.9001 , 29.7001 ),
434
434
new Coordinate (34.9001 , 29.7200 ), new Coordinate (34.9200 , 29.7200 ),
435
435
new Coordinate (34.9200 , 29.7001 ), new Coordinate (34.9001 , 29.7001 )});
436
- client .hset ("large" , "geom" , large . toString () );
436
+ client .hsetObject ("large" , "geom" , large );
437
437
438
438
// within condition
439
439
final Polygon within = factory .createPolygon (new Coordinate []{new Coordinate (34.9000 , 29.7000 ),
440
440
new Coordinate (34.9000 , 29.7150 ), new Coordinate (34.9150 , 29.7150 ),
441
441
new Coordinate (34.9150 , 29.7000 ), new Coordinate (34.9000 , 29.7000 )});
442
442
443
- SearchResult res = client .ftSearch (index , "@geom:[within $poly]" ,
443
+ SearchResult result = client .ftSearch (index , "@geom:[within $poly]" ,
444
444
FTSearchParams .searchParams ().addParam ("poly" , within ).dialect (3 ));
445
- assertEquals (1 , res .getTotalResults ());
446
- assertEquals (1 , res .getDocuments ().size ());
447
- assertEquals (small , reader .read (res .getDocuments ().get (0 ).getString ("geom" )));
445
+ assertEquals (1 , result .getTotalResults ());
446
+ assertEquals (1 , result .getDocuments ().size ());
447
+ assertEquals (small , reader .read (result .getDocuments ().get (0 ).getString ("geom" )));
448
448
449
449
// contains condition
450
450
final Polygon contains = factory .createPolygon (new Coordinate []{new Coordinate (34.9002 , 29.7002 ),
451
451
new Coordinate (34.9002 , 29.7050 ), new Coordinate (34.9050 , 29.7050 ),
452
452
new Coordinate (34.9050 , 29.7002 ), new Coordinate (34.9002 , 29.7002 )});
453
453
454
- res = client .ftSearch (index , "@geom:[contains $poly]" ,
454
+ result = client .ftSearch (index , "@geom:[contains $poly]" ,
455
455
FTSearchParams .searchParams ().addParam ("poly" , contains ).dialect (3 ));
456
- assertEquals (2 , res .getTotalResults ());
457
- assertEquals (2 , res .getDocuments ().size ());
456
+ assertEquals (2 , result .getTotalResults ());
457
+ assertEquals (2 , result .getDocuments ().size ());
458
458
459
459
// point type
460
460
final Point point = factory .createPoint (new Coordinate (34.9010 , 29.7010 ));
461
461
client .hset ("point" , "geom" , point .toString ());
462
462
463
- res = client .ftSearch (index , "@geom:[within $poly]" ,
463
+ result = client .ftSearch (index , "@geom:[within $poly]" ,
464
464
FTSearchParams .searchParams ().addParam ("poly" , within ).dialect (3 ));
465
- assertEquals (2 , res .getTotalResults ());
466
- assertEquals (2 , res .getDocuments ().size ());
465
+ assertEquals (2 , result .getTotalResults ());
466
+ assertEquals (2 , result .getDocuments ().size ());
467
467
}
468
468
469
469
@ Test
@@ -474,41 +474,57 @@ public void geoShapeFilterFlat() throws ParseException {
474
474
assertOK (client .ftCreate (index , GeoShapeField .of ("geom" , CoordinateSystem .FLAT )));
475
475
476
476
// polygon type
477
- final Polygon small = factory .createPolygon (new Coordinate []{new Coordinate (1 , 1 ),
478
- new Coordinate (1 , 100 ), new Coordinate (100 , 100 ), new Coordinate (100 , 1 ), new Coordinate (1 , 1 )});
479
- client .hset ("small" , "geom" , small . toString () );
477
+ final Polygon small = factory .createPolygon (new Coordinate []{new Coordinate (20 , 20 ),
478
+ new Coordinate (20 , 100 ), new Coordinate (100 , 100 ), new Coordinate (100 , 20 ), new Coordinate (20 , 20 )});
479
+ client .hsetObject ("small" , "geom" , small );
480
480
481
- final Polygon large = factory .createPolygon (new Coordinate []{new Coordinate (1 , 1 ),
482
- new Coordinate (1 , 200 ), new Coordinate (200 , 200 ), new Coordinate (200 , 1 ), new Coordinate (1 , 1 )});
483
- client .hset ("large" , "geom" , large . toString () );
481
+ final Polygon large = factory .createPolygon (new Coordinate []{new Coordinate (10 , 10 ),
482
+ new Coordinate (10 , 200 ), new Coordinate (200 , 200 ), new Coordinate (200 , 10 ), new Coordinate (10 , 10 )});
483
+ client .hsetObject ("large" , "geom" , large );
484
484
485
485
// within condition
486
486
final Polygon within = factory .createPolygon (new Coordinate []{new Coordinate (0 , 0 ),
487
487
new Coordinate (0 , 150 ), new Coordinate (150 , 150 ), new Coordinate (150 , 0 ), new Coordinate (0 , 0 )});
488
488
489
- SearchResult res = client .ftSearch (index , "@geom:[within $poly]" ,
489
+ SearchResult result = client .ftSearch (index , "@geom:[within $poly]" ,
490
490
FTSearchParams .searchParams ().addParam ("poly" , within ).dialect (3 ));
491
- assertEquals (1 , res .getTotalResults ());
492
- assertEquals (1 , res .getDocuments ().size ());
493
- assertEquals (small , reader .read (res .getDocuments ().get (0 ).getString ("geom" )));
491
+ assertEquals (1 , result .getTotalResults ());
492
+ assertEquals (1 , result .getDocuments ().size ());
493
+ assertEquals (small , reader .read (result .getDocuments ().get (0 ).getString ("geom" )));
494
494
495
495
// contains condition
496
- final Polygon contains = factory .createPolygon (new Coordinate []{new Coordinate (2 , 2 ),
497
- new Coordinate (2 , 50 ), new Coordinate (50 , 50 ), new Coordinate (50 , 2 ), new Coordinate (2 , 2 )});
496
+ final Polygon contains = factory .createPolygon (new Coordinate []{new Coordinate (25 , 25 ),
497
+ new Coordinate (25 , 50 ), new Coordinate (50 , 50 ), new Coordinate (50 , 25 ), new Coordinate (25 , 25 )});
498
498
499
- res = client .ftSearch (index , "@geom:[contains $poly]" ,
499
+ result = client .ftSearch (index , "@geom:[contains $poly]" ,
500
500
FTSearchParams .searchParams ().addParam ("poly" , contains ).dialect (3 ));
501
- assertEquals (2 , res .getTotalResults ());
502
- assertEquals (2 , res .getDocuments ().size ());
501
+ assertEquals (2 , result .getTotalResults ());
502
+ assertEquals (2 , result .getDocuments ().size ());
503
+
504
+ // intersects and disjoint
505
+ final Polygon disjointersect = factory .createPolygon (new Coordinate []{new Coordinate (150 , 150 ),
506
+ new Coordinate (150 , 250 ), new Coordinate (250 , 250 ), new Coordinate (250 , 150 ), new Coordinate (150 , 150 )});
507
+
508
+ result = client .ftSearch (index , "@geom:[intersects $poly]" ,
509
+ FTSearchParams .searchParams ().addParam ("poly" , disjointersect ).dialect (3 ));
510
+ assertEquals (1 , result .getTotalResults ());
511
+ assertEquals (1 , result .getDocuments ().size ());
512
+ assertEquals (large , reader .read (result .getDocuments ().get (0 ).getString ("geom" )));
513
+
514
+ result = client .ftSearch (index , "@geom:[disjoint $poly]" ,
515
+ FTSearchParams .searchParams ().addParam ("poly" , disjointersect ).dialect (3 ));
516
+ assertEquals (1 , result .getTotalResults ());
517
+ assertEquals (1 , result .getDocuments ().size ());
518
+ assertEquals (small , reader .read (result .getDocuments ().get (0 ).getString ("geom" )));
503
519
504
520
// point type
505
- final Point point = factory .createPoint (new Coordinate (10 , 10 ));
506
- client .hset ("point" , "geom" , point . toString () );
521
+ final Point point = factory .createPoint (new Coordinate (30 , 30 ));
522
+ client .hsetObject ("point" , "geom" , point );
507
523
508
- res = client .ftSearch (index , "@geom:[within $poly]" ,
524
+ result = client .ftSearch (index , "@geom:[within $poly]" ,
509
525
FTSearchParams .searchParams ().addParam ("poly" , within ).dialect (3 ));
510
- assertEquals (2 , res .getTotalResults ());
511
- assertEquals (2 , res .getDocuments ().size ());
526
+ assertEquals (2 , result .getTotalResults ());
527
+ assertEquals (2 , result .getDocuments ().size ());
512
528
}
513
529
514
530
@ Test
0 commit comments