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