| @@ 3157-3266 (lines=110) @@ | ||
| 3154 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 3155 | * @group maplocation |
|
| 3156 | */ |
|
| 3157 | public function testMapLocationDistanceSortAscending() |
|
| 3158 | { |
|
| 3159 | $contentType = $this->createTestPlaceContentType(); |
|
| 3160 | ||
| 3161 | // Create a draft to account for behaviour with ContentType in different states |
|
| 3162 | $repository = $this->getRepository(); |
|
| 3163 | $contentTypeService = $repository->getContentTypeService(); |
|
| 3164 | $contentService = $repository->getContentService(); |
|
| 3165 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 3166 | ||
| 3167 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3168 | $createStruct->alwaysAvailable = false; |
|
| 3169 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3170 | $createStruct->setField( |
|
| 3171 | 'maplocation', |
|
| 3172 | [ |
|
| 3173 | 'latitude' => 45.894877, |
|
| 3174 | 'longitude' => 15.972699, |
|
| 3175 | 'address' => 'Here be wild boars', |
|
| 3176 | ], |
|
| 3177 | 'eng-GB' |
|
| 3178 | ); |
|
| 3179 | ||
| 3180 | $draft = $contentService->createContent($createStruct); |
|
| 3181 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3182 | ||
| 3183 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3184 | $createStruct->alwaysAvailable = false; |
|
| 3185 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3186 | $createStruct->setField( |
|
| 3187 | 'maplocation', |
|
| 3188 | [ |
|
| 3189 | 'latitude' => 45.927334, |
|
| 3190 | 'longitude' => 15.934847, |
|
| 3191 | 'address' => 'A lone tree', |
|
| 3192 | ], |
|
| 3193 | 'eng-GB' |
|
| 3194 | ); |
|
| 3195 | ||
| 3196 | $draft = $contentService->createContent($createStruct); |
|
| 3197 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3198 | ||
| 3199 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3200 | $createStruct->alwaysAvailable = false; |
|
| 3201 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3202 | $createStruct->setField( |
|
| 3203 | 'maplocation', |
|
| 3204 | [ |
|
| 3205 | 'latitude' => 45.903777, |
|
| 3206 | 'longitude' => 15.958788, |
|
| 3207 | 'address' => 'Meadow with mushrooms', |
|
| 3208 | ], |
|
| 3209 | 'eng-GB' |
|
| 3210 | ); |
|
| 3211 | ||
| 3212 | $draft = $contentService->createContent($createStruct); |
|
| 3213 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3214 | ||
| 3215 | $this->refreshSearch($repository); |
|
| 3216 | ||
| 3217 | $wellInVodice = [ |
|
| 3218 | 'latitude' => 43.756825, |
|
| 3219 | 'longitude' => 15.775074, |
|
| 3220 | ]; |
|
| 3221 | ||
| 3222 | $query = new Query( |
|
| 3223 | [ |
|
| 3224 | 'filter' => new Criterion\LogicalAnd( |
|
| 3225 | [ |
|
| 3226 | new Criterion\ContentTypeId($contentType->id), |
|
| 3227 | new Criterion\MapLocationDistance( |
|
| 3228 | 'maplocation', |
|
| 3229 | Criterion\Operator::GTE, |
|
| 3230 | 235, |
|
| 3231 | $wellInVodice['latitude'], |
|
| 3232 | $wellInVodice['longitude'] |
|
| 3233 | ), |
|
| 3234 | ] |
|
| 3235 | ), |
|
| 3236 | 'offset' => 0, |
|
| 3237 | 'limit' => 10, |
|
| 3238 | 'sortClauses' => [ |
|
| 3239 | new SortClause\MapLocationDistance( |
|
| 3240 | 'testtype', |
|
| 3241 | 'maplocation', |
|
| 3242 | $wellInVodice['latitude'], |
|
| 3243 | $wellInVodice['longitude'], |
|
| 3244 | Query::SORT_ASC |
|
| 3245 | ), |
|
| 3246 | ], |
|
| 3247 | ] |
|
| 3248 | ); |
|
| 3249 | ||
| 3250 | $searchService = $repository->getSearchService(); |
|
| 3251 | $result = $searchService->findContent($query); |
|
| 3252 | ||
| 3253 | $this->assertEquals(3, $result->totalCount); |
|
| 3254 | $this->assertEquals( |
|
| 3255 | $wildBoars->id, |
|
| 3256 | $result->searchHits[0]->valueObject->id |
|
| 3257 | ); |
|
| 3258 | $this->assertEquals( |
|
| 3259 | $mushrooms->id, |
|
| 3260 | $result->searchHits[1]->valueObject->id |
|
| 3261 | ); |
|
| 3262 | $this->assertEquals( |
|
| 3263 | $tree->id, |
|
| 3264 | $result->searchHits[2]->valueObject->id |
|
| 3265 | ); |
|
| 3266 | } |
|
| 3267 | ||
| 3268 | /** |
|
| 3269 | * Test for the findContent() method. |
|
| @@ 3274-3383 (lines=110) @@ | ||
| 3271 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 3272 | * @group maplocation |
|
| 3273 | */ |
|
| 3274 | public function testMapLocationDistanceSortDescending() |
|
| 3275 | { |
|
| 3276 | $contentType = $this->createTestPlaceContentType(); |
|
| 3277 | ||
| 3278 | // Create a draft to account for behaviour with ContentType in different states |
|
| 3279 | $repository = $this->getRepository(); |
|
| 3280 | $contentTypeService = $repository->getContentTypeService(); |
|
| 3281 | $contentService = $repository->getContentService(); |
|
| 3282 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 3283 | ||
| 3284 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3285 | $createStruct->alwaysAvailable = false; |
|
| 3286 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3287 | $createStruct->setField( |
|
| 3288 | 'maplocation', |
|
| 3289 | [ |
|
| 3290 | 'latitude' => 45.894877, |
|
| 3291 | 'longitude' => 15.972699, |
|
| 3292 | 'address' => 'Here be wild boars', |
|
| 3293 | ], |
|
| 3294 | 'eng-GB' |
|
| 3295 | ); |
|
| 3296 | ||
| 3297 | $draft = $contentService->createContent($createStruct); |
|
| 3298 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3299 | ||
| 3300 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3301 | $createStruct->alwaysAvailable = false; |
|
| 3302 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3303 | $createStruct->setField( |
|
| 3304 | 'maplocation', |
|
| 3305 | [ |
|
| 3306 | 'latitude' => 45.927334, |
|
| 3307 | 'longitude' => 15.934847, |
|
| 3308 | 'address' => 'A lone tree', |
|
| 3309 | ], |
|
| 3310 | 'eng-GB' |
|
| 3311 | ); |
|
| 3312 | ||
| 3313 | $draft = $contentService->createContent($createStruct); |
|
| 3314 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3315 | ||
| 3316 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3317 | $createStruct->alwaysAvailable = false; |
|
| 3318 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3319 | $createStruct->setField( |
|
| 3320 | 'maplocation', |
|
| 3321 | [ |
|
| 3322 | 'latitude' => 45.903777, |
|
| 3323 | 'longitude' => 15.958788, |
|
| 3324 | 'address' => 'Meadow with mushrooms', |
|
| 3325 | ], |
|
| 3326 | 'eng-GB' |
|
| 3327 | ); |
|
| 3328 | ||
| 3329 | $draft = $contentService->createContent($createStruct); |
|
| 3330 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3331 | ||
| 3332 | $this->refreshSearch($repository); |
|
| 3333 | ||
| 3334 | $well = [ |
|
| 3335 | 'latitude' => 43.756825, |
|
| 3336 | 'longitude' => 15.775074, |
|
| 3337 | ]; |
|
| 3338 | ||
| 3339 | $query = new Query( |
|
| 3340 | [ |
|
| 3341 | 'filter' => new Criterion\LogicalAnd( |
|
| 3342 | [ |
|
| 3343 | new Criterion\ContentTypeId($contentType->id), |
|
| 3344 | new Criterion\MapLocationDistance( |
|
| 3345 | 'maplocation', |
|
| 3346 | Criterion\Operator::GTE, |
|
| 3347 | 235, |
|
| 3348 | $well['latitude'], |
|
| 3349 | $well['longitude'] |
|
| 3350 | ), |
|
| 3351 | ] |
|
| 3352 | ), |
|
| 3353 | 'offset' => 0, |
|
| 3354 | 'limit' => 10, |
|
| 3355 | 'sortClauses' => [ |
|
| 3356 | new SortClause\MapLocationDistance( |
|
| 3357 | 'testtype', |
|
| 3358 | 'maplocation', |
|
| 3359 | $well['latitude'], |
|
| 3360 | $well['longitude'], |
|
| 3361 | Query::SORT_DESC |
|
| 3362 | ), |
|
| 3363 | ], |
|
| 3364 | ] |
|
| 3365 | ); |
|
| 3366 | ||
| 3367 | $searchService = $repository->getSearchService(); |
|
| 3368 | $result = $searchService->findContent($query); |
|
| 3369 | ||
| 3370 | $this->assertEquals(3, $result->totalCount); |
|
| 3371 | $this->assertEquals( |
|
| 3372 | $wildBoars->id, |
|
| 3373 | $result->searchHits[2]->valueObject->id |
|
| 3374 | ); |
|
| 3375 | $this->assertEquals( |
|
| 3376 | $mushrooms->id, |
|
| 3377 | $result->searchHits[1]->valueObject->id |
|
| 3378 | ); |
|
| 3379 | $this->assertEquals( |
|
| 3380 | $tree->id, |
|
| 3381 | $result->searchHits[0]->valueObject->id |
|
| 3382 | ); |
|
| 3383 | } |
|
| 3384 | ||
| 3385 | /** |
|
| 3386 | * Test for the findContent() method. |
|