|
13 | 13 | namespace Predis\Command\Redis\Search;
|
14 | 14 |
|
15 | 15 | use Predis\Command\Argument\Search\CreateArguments;
|
| 16 | +use Predis\Command\Argument\Search\SchemaFields\AbstractField; |
| 17 | +use Predis\Command\Argument\Search\SchemaFields\GeoShapeField; |
16 | 18 | use Predis\Command\Argument\Search\SchemaFields\NumericField;
|
17 | 19 | use Predis\Command\Argument\Search\SchemaFields\TextField;
|
18 | 20 | use Predis\Command\Argument\Search\SearchArguments;
|
@@ -125,6 +127,123 @@ public function testSearchValuesByHashIndex(): void
|
125 | 127 | $this->assertSame($expectedResponse, $actualResponse);
|
126 | 128 | }
|
127 | 129 |
|
| 130 | + /** |
| 131 | + * @group connected |
| 132 | + * @group relay-resp3 |
| 133 | + * @return void |
| 134 | + * @requiresRediSearchVersion >= 2.9.0 |
| 135 | + */ |
| 136 | + public function testGeoSearchQueriesIntersectsAndDisjoint(): void |
| 137 | + { |
| 138 | + $redis = $this->getClient(); |
| 139 | + |
| 140 | + $redis->hset('geo:doc_point1', 'g', 'POINT (10 10)'); |
| 141 | + $redis->hset('geo:doc_point2', 'g', 'POINT (50 50)'); |
| 142 | + $redis->hset('geo:doc_polygon1', 'g', 'POLYGON ((20 20, 25 35, 35 25, 20 20))'); |
| 143 | + $redis->hset('geo:doc_polygon2', 'g', 'POLYGON ((60 60, 65 75, 70 70, 65 55, 60 60))'); |
| 144 | + |
| 145 | + $ftCreateArguments = new CreateArguments(); |
| 146 | + $ftCreateArguments->prefix(['geo:']); |
| 147 | + |
| 148 | + $schema = [ |
| 149 | + new GeoShapeField('g', '', AbstractField::NOT_SORTABLE, false, GeoShapeField::COORD_FLAT), |
| 150 | + ]; |
| 151 | + |
| 152 | + $ftCreateResponse = $redis->ftcreate('idx_geo', $schema, $ftCreateArguments); |
| 153 | + $this->assertEquals('OK', $ftCreateResponse); |
| 154 | + |
| 155 | + $ftSearchArguments = new SearchArguments(); |
| 156 | + $ftSearchArguments->params(['shape', 'POLYGON ((15 15, 75 15, 50 70, 20 40, 15 15))']); |
| 157 | + $ftSearchArguments->noContent(); |
| 158 | + $ftSearchArguments->dialect(3); |
| 159 | + |
| 160 | + $actualResponse = $redis->ftsearch('idx_geo', '@g:[intersects $shape]', $ftSearchArguments); |
| 161 | + $this->assertSameValues( |
| 162 | + [ |
| 163 | + 2, |
| 164 | + 'geo:doc_polygon1', |
| 165 | + 'geo:doc_point2', |
| 166 | + ], $actualResponse |
| 167 | + ); |
| 168 | + |
| 169 | + $actualResponse = $redis->ftsearch('idx_geo', '@g:[disjoint $shape]', $ftSearchArguments); |
| 170 | + $this->assertSameValues( |
| 171 | + [ |
| 172 | + 2, |
| 173 | + 'geo:doc_polygon2', |
| 174 | + 'geo:doc_point1', |
| 175 | + ], $actualResponse |
| 176 | + ); |
| 177 | + } |
| 178 | + |
| 179 | + /** |
| 180 | + * @group connected |
| 181 | + * @group relay-resp3 |
| 182 | + * @return void |
| 183 | + * @requiresRediSearchVersion >= 2.9.0 |
| 184 | + */ |
| 185 | + public function testGeoSearchQueriesContainsAndWithin(): void |
| 186 | + { |
| 187 | + $redis = $this->getClient(); |
| 188 | + |
| 189 | + $redis->hset('geo:doc_point1', 'g', 'POINT (10 10)'); |
| 190 | + $redis->hset('geo:doc_point2', 'g', 'POINT (50 50)'); |
| 191 | + $redis->hset('geo:doc_polygon1', 'g', 'POLYGON ((20 20, 25 35, 35 25, 20 20))'); |
| 192 | + $redis->hset('geo:doc_polygon2', 'g', 'POLYGON ((60 60, 65 75, 70 70, 65 55, 60 60))'); |
| 193 | + |
| 194 | + $ftCreateArguments = new CreateArguments(); |
| 195 | + $ftCreateArguments->prefix(['geo:']); |
| 196 | + |
| 197 | + $schema = [ |
| 198 | + new GeoShapeField('g', '', |
| 199 | + AbstractField::NOT_SORTABLE, false, GeoShapeField::COORD_FLAT |
| 200 | + ), |
| 201 | + ]; |
| 202 | + |
| 203 | + $ftCreateResponse = $redis->ftcreate('idx_geo', $schema, $ftCreateArguments); |
| 204 | + $this->assertEquals('OK', $ftCreateResponse); |
| 205 | + |
| 206 | + $ftSearchArguments = new SearchArguments(); |
| 207 | + $ftSearchArguments->params(['shape', 'POINT(25 25)']); |
| 208 | + $ftSearchArguments->noContent(); |
| 209 | + $ftSearchArguments->dialect(3); |
| 210 | + |
| 211 | + $actualResponse = $redis->ftsearch('idx_geo', '@g:[contains $shape]', $ftSearchArguments); |
| 212 | + $this->assertSameValues( |
| 213 | + [ |
| 214 | + 1, |
| 215 | + 'geo:doc_polygon1', |
| 216 | + ], $actualResponse |
| 217 | + ); |
| 218 | + |
| 219 | + $ftSearchArguments = new SearchArguments(); |
| 220 | + $ftSearchArguments->params(['shape', 'POLYGON((24 24, 24 26, 25 25, 24 24))']); |
| 221 | + $ftSearchArguments->noContent(); |
| 222 | + $ftSearchArguments->dialect(3); |
| 223 | + |
| 224 | + $actualResponse = $redis->ftsearch('idx_geo', '@g:[contains $shape]', $ftSearchArguments); |
| 225 | + $this->assertSameValues( |
| 226 | + [ |
| 227 | + 1, |
| 228 | + 'geo:doc_polygon1', |
| 229 | + ], $actualResponse |
| 230 | + ); |
| 231 | + |
| 232 | + $ftSearchArguments = new SearchArguments(); |
| 233 | + $ftSearchArguments->params(['shape', 'POLYGON((15 15, 75 15, 50 70, 20 40, 15 15))']); |
| 234 | + $ftSearchArguments->noContent(); |
| 235 | + $ftSearchArguments->dialect(3); |
| 236 | + |
| 237 | + $actualResponse = $redis->ftsearch('idx_geo', '@g:[within $shape]', $ftSearchArguments); |
| 238 | + $this->assertSameValues( |
| 239 | + [ |
| 240 | + 2, |
| 241 | + 'geo:doc_polygon1', |
| 242 | + 'geo:doc_point2', |
| 243 | + ], $actualResponse |
| 244 | + ); |
| 245 | + } |
| 246 | + |
128 | 247 | public function argumentsProvider(): array
|
129 | 248 | {
|
130 | 249 | return [
|
|
0 commit comments