@@ -360,42 +360,42 @@ public void geoShapeFilterSpherical() throws ParseException {
360
360
final Polygon small = factory .createPolygon (new Coordinate []{new Coordinate (34.9001 , 29.7001 ),
361
361
new Coordinate (34.9001 , 29.7100 ), new Coordinate (34.9100 , 29.7100 ),
362
362
new Coordinate (34.9100 , 29.7001 ), new Coordinate (34.9001 , 29.7001 )});
363
- client .hset ("small" , "geom" , small . toString () );
363
+ client .hsetObject ("small" , "geom" , small );
364
364
365
365
final Polygon large = factory .createPolygon (new Coordinate []{new Coordinate (34.9001 , 29.7001 ),
366
366
new Coordinate (34.9001 , 29.7200 ), new Coordinate (34.9200 , 29.7200 ),
367
367
new Coordinate (34.9200 , 29.7001 ), new Coordinate (34.9001 , 29.7001 )});
368
- client .hset ("large" , "geom" , large . toString () );
368
+ client .hsetObject ("large" , "geom" , large );
369
369
370
370
// within condition
371
371
final Polygon within = factory .createPolygon (new Coordinate []{new Coordinate (34.9000 , 29.7000 ),
372
372
new Coordinate (34.9000 , 29.7150 ), new Coordinate (34.9150 , 29.7150 ),
373
373
new Coordinate (34.9150 , 29.7000 ), new Coordinate (34.9000 , 29.7000 )});
374
374
375
- SearchResult res = client .ftSearch (index , "@geom:[within $poly]" ,
375
+ SearchResult result = client .ftSearch (index , "@geom:[within $poly]" ,
376
376
FTSearchParams .searchParams ().addParam ("poly" , within ).dialect (3 ));
377
- assertEquals (1 , res .getTotalResults ());
378
- assertEquals (1 , res .getDocuments ().size ());
379
- assertEquals (small , reader .read (res .getDocuments ().get (0 ).getString ("geom" )));
377
+ assertEquals (1 , result .getTotalResults ());
378
+ assertEquals (1 , result .getDocuments ().size ());
379
+ assertEquals (small , reader .read (result .getDocuments ().get (0 ).getString ("geom" )));
380
380
381
381
// contains condition
382
382
final Polygon contains = factory .createPolygon (new Coordinate []{new Coordinate (34.9002 , 29.7002 ),
383
383
new Coordinate (34.9002 , 29.7050 ), new Coordinate (34.9050 , 29.7050 ),
384
384
new Coordinate (34.9050 , 29.7002 ), new Coordinate (34.9002 , 29.7002 )});
385
385
386
- res = client .ftSearch (index , "@geom:[contains $poly]" ,
386
+ result = client .ftSearch (index , "@geom:[contains $poly]" ,
387
387
FTSearchParams .searchParams ().addParam ("poly" , contains ).dialect (3 ));
388
- assertEquals (2 , res .getTotalResults ());
389
- assertEquals (2 , res .getDocuments ().size ());
388
+ assertEquals (2 , result .getTotalResults ());
389
+ assertEquals (2 , result .getDocuments ().size ());
390
390
391
391
// point type
392
392
final Point point = factory .createPoint (new Coordinate (34.9010 , 29.7010 ));
393
393
client .hset ("point" , "geom" , point .toString ());
394
394
395
- res = client .ftSearch (index , "@geom:[within $poly]" ,
395
+ result = client .ftSearch (index , "@geom:[within $poly]" ,
396
396
FTSearchParams .searchParams ().addParam ("poly" , within ).dialect (3 ));
397
- assertEquals (2 , res .getTotalResults ());
398
- assertEquals (2 , res .getDocuments ().size ());
397
+ assertEquals (2 , result .getTotalResults ());
398
+ assertEquals (2 , result .getDocuments ().size ());
399
399
}
400
400
401
401
@ Test
@@ -406,41 +406,57 @@ public void geoShapeFilterFlat() throws ParseException {
406
406
assertOK (client .ftCreate (index , GeoShapeField .of ("geom" , GeoShapeField .CoordinateSystem .FLAT )));
407
407
408
408
// polygon type
409
- final Polygon small = factory .createPolygon (new Coordinate []{new Coordinate (1 , 1 ),
410
- new Coordinate (1 , 100 ), new Coordinate (100 , 100 ), new Coordinate (100 , 1 ), new Coordinate (1 , 1 )});
411
- client .hset ("small" , "geom" , small . toString () );
409
+ final Polygon small = factory .createPolygon (new Coordinate []{new Coordinate (20 , 20 ),
410
+ new Coordinate (20 , 100 ), new Coordinate (100 , 100 ), new Coordinate (100 , 20 ), new Coordinate (20 , 20 )});
411
+ client .hsetObject ("small" , "geom" , small );
412
412
413
- final Polygon large = factory .createPolygon (new Coordinate []{new Coordinate (1 , 1 ),
414
- new Coordinate (1 , 200 ), new Coordinate (200 , 200 ), new Coordinate (200 , 1 ), new Coordinate (1 , 1 )});
415
- client .hset ("large" , "geom" , large . toString () );
413
+ final Polygon large = factory .createPolygon (new Coordinate []{new Coordinate (10 , 10 ),
414
+ new Coordinate (10 , 200 ), new Coordinate (200 , 200 ), new Coordinate (200 , 10 ), new Coordinate (10 , 10 )});
415
+ client .hsetObject ("large" , "geom" , large );
416
416
417
417
// within condition
418
418
final Polygon within = factory .createPolygon (new Coordinate []{new Coordinate (0 , 0 ),
419
419
new Coordinate (0 , 150 ), new Coordinate (150 , 150 ), new Coordinate (150 , 0 ), new Coordinate (0 , 0 )});
420
420
421
- SearchResult res = client .ftSearch (index , "@geom:[within $poly]" ,
421
+ SearchResult result = client .ftSearch (index , "@geom:[within $poly]" ,
422
422
FTSearchParams .searchParams ().addParam ("poly" , within ).dialect (3 ));
423
- assertEquals (1 , res .getTotalResults ());
424
- assertEquals (1 , res .getDocuments ().size ());
425
- assertEquals (small , reader .read (res .getDocuments ().get (0 ).getString ("geom" )));
423
+ assertEquals (1 , result .getTotalResults ());
424
+ assertEquals (1 , result .getDocuments ().size ());
425
+ assertEquals (small , reader .read (result .getDocuments ().get (0 ).getString ("geom" )));
426
426
427
427
// contains condition
428
- final Polygon contains = factory .createPolygon (new Coordinate []{new Coordinate (2 , 2 ),
429
- new Coordinate (2 , 50 ), new Coordinate (50 , 50 ), new Coordinate (50 , 2 ), new Coordinate (2 , 2 )});
428
+ final Polygon contains = factory .createPolygon (new Coordinate []{new Coordinate (25 , 25 ),
429
+ new Coordinate (25 , 50 ), new Coordinate (50 , 50 ), new Coordinate (50 , 25 ), new Coordinate (25 , 25 )});
430
430
431
- res = client .ftSearch (index , "@geom:[contains $poly]" ,
431
+ result = client .ftSearch (index , "@geom:[contains $poly]" ,
432
432
FTSearchParams .searchParams ().addParam ("poly" , contains ).dialect (3 ));
433
- assertEquals (2 , res .getTotalResults ());
434
- assertEquals (2 , res .getDocuments ().size ());
433
+ assertEquals (2 , result .getTotalResults ());
434
+ assertEquals (2 , result .getDocuments ().size ());
435
+
436
+ // intersects and disjoint
437
+ final Polygon disjointersect = factory .createPolygon (new Coordinate []{new Coordinate (150 , 150 ),
438
+ new Coordinate (150 , 250 ), new Coordinate (250 , 250 ), new Coordinate (250 , 150 ), new Coordinate (150 , 150 )});
439
+
440
+ result = client .ftSearch (index , "@geom:[intersects $poly]" ,
441
+ FTSearchParams .searchParams ().addParam ("poly" , disjointersect ).dialect (3 ));
442
+ assertEquals (1 , result .getTotalResults ());
443
+ assertEquals (1 , result .getDocuments ().size ());
444
+ assertEquals (large , reader .read (result .getDocuments ().get (0 ).getString ("geom" )));
445
+
446
+ result = client .ftSearch (index , "@geom:[disjoint $poly]" ,
447
+ FTSearchParams .searchParams ().addParam ("poly" , disjointersect ).dialect (3 ));
448
+ assertEquals (1 , result .getTotalResults ());
449
+ assertEquals (1 , result .getDocuments ().size ());
450
+ assertEquals (small , reader .read (result .getDocuments ().get (0 ).getString ("geom" )));
435
451
436
452
// point type
437
- final Point point = factory .createPoint (new Coordinate (10 , 10 ));
438
- client .hset ("point" , "geom" , point . toString () );
453
+ final Point point = factory .createPoint (new Coordinate (30 , 30 ));
454
+ client .hsetObject ("point" , "geom" , point );
439
455
440
- res = client .ftSearch (index , "@geom:[within $poly]" ,
456
+ result = client .ftSearch (index , "@geom:[within $poly]" ,
441
457
FTSearchParams .searchParams ().addParam ("poly" , within ).dialect (3 ));
442
- assertEquals (2 , res .getTotalResults ());
443
- assertEquals (2 , res .getDocuments ().size ());
458
+ assertEquals (2 , result .getTotalResults ());
459
+ assertEquals (2 , result .getDocuments ().size ());
444
460
}
445
461
446
462
@ Test
0 commit comments