| @@ 2985-3094 (lines=110) @@ | ||
| 2982 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 2983 | * @group maplocation |
|
| 2984 | */ |
|
| 2985 | public function testMapLocationDistanceSortAscending() |
|
| 2986 | { |
|
| 2987 | $contentType = $this->createTestPlaceContentType(); |
|
| 2988 | ||
| 2989 | // Create a draft to account for behaviour with ContentType in different states |
|
| 2990 | $repository = $this->getRepository(); |
|
| 2991 | $contentTypeService = $repository->getContentTypeService(); |
|
| 2992 | $contentService = $repository->getContentService(); |
|
| 2993 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 2994 | ||
| 2995 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 2996 | $createStruct->alwaysAvailable = false; |
|
| 2997 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 2998 | $createStruct->setField( |
|
| 2999 | 'maplocation', |
|
| 3000 | [ |
|
| 3001 | 'latitude' => 45.894877, |
|
| 3002 | 'longitude' => 15.972699, |
|
| 3003 | 'address' => 'Here be wild boars', |
|
| 3004 | ], |
|
| 3005 | 'eng-GB' |
|
| 3006 | ); |
|
| 3007 | ||
| 3008 | $draft = $contentService->createContent($createStruct); |
|
| 3009 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3010 | ||
| 3011 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3012 | $createStruct->alwaysAvailable = false; |
|
| 3013 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3014 | $createStruct->setField( |
|
| 3015 | 'maplocation', |
|
| 3016 | [ |
|
| 3017 | 'latitude' => 45.927334, |
|
| 3018 | 'longitude' => 15.934847, |
|
| 3019 | 'address' => 'A lone tree', |
|
| 3020 | ], |
|
| 3021 | 'eng-GB' |
|
| 3022 | ); |
|
| 3023 | ||
| 3024 | $draft = $contentService->createContent($createStruct); |
|
| 3025 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3026 | ||
| 3027 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3028 | $createStruct->alwaysAvailable = false; |
|
| 3029 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3030 | $createStruct->setField( |
|
| 3031 | 'maplocation', |
|
| 3032 | [ |
|
| 3033 | 'latitude' => 45.903777, |
|
| 3034 | 'longitude' => 15.958788, |
|
| 3035 | 'address' => 'Meadow with mushrooms', |
|
| 3036 | ], |
|
| 3037 | 'eng-GB' |
|
| 3038 | ); |
|
| 3039 | ||
| 3040 | $draft = $contentService->createContent($createStruct); |
|
| 3041 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3042 | ||
| 3043 | $this->refreshSearch($repository); |
|
| 3044 | ||
| 3045 | $wellInVodice = [ |
|
| 3046 | 'latitude' => 43.756825, |
|
| 3047 | 'longitude' => 15.775074, |
|
| 3048 | ]; |
|
| 3049 | ||
| 3050 | $query = new Query( |
|
| 3051 | [ |
|
| 3052 | 'filter' => new Criterion\LogicalAnd( |
|
| 3053 | [ |
|
| 3054 | new Criterion\ContentTypeId($contentType->id), |
|
| 3055 | new Criterion\MapLocationDistance( |
|
| 3056 | 'maplocation', |
|
| 3057 | Criterion\Operator::GTE, |
|
| 3058 | 235, |
|
| 3059 | $wellInVodice['latitude'], |
|
| 3060 | $wellInVodice['longitude'] |
|
| 3061 | ), |
|
| 3062 | ] |
|
| 3063 | ), |
|
| 3064 | 'offset' => 0, |
|
| 3065 | 'limit' => 10, |
|
| 3066 | 'sortClauses' => [ |
|
| 3067 | new SortClause\MapLocationDistance( |
|
| 3068 | 'testtype', |
|
| 3069 | 'maplocation', |
|
| 3070 | $wellInVodice['latitude'], |
|
| 3071 | $wellInVodice['longitude'], |
|
| 3072 | Query::SORT_ASC |
|
| 3073 | ), |
|
| 3074 | ], |
|
| 3075 | ] |
|
| 3076 | ); |
|
| 3077 | ||
| 3078 | $searchService = $repository->getSearchService(); |
|
| 3079 | $result = $searchService->findContent($query); |
|
| 3080 | ||
| 3081 | $this->assertEquals(3, $result->totalCount); |
|
| 3082 | $this->assertEquals( |
|
| 3083 | $wildBoars->id, |
|
| 3084 | $result->searchHits[0]->valueObject->id |
|
| 3085 | ); |
|
| 3086 | $this->assertEquals( |
|
| 3087 | $mushrooms->id, |
|
| 3088 | $result->searchHits[1]->valueObject->id |
|
| 3089 | ); |
|
| 3090 | $this->assertEquals( |
|
| 3091 | $tree->id, |
|
| 3092 | $result->searchHits[2]->valueObject->id |
|
| 3093 | ); |
|
| 3094 | } |
|
| 3095 | ||
| 3096 | /** |
|
| 3097 | * Test for the findContent() method. |
|
| @@ 3102-3211 (lines=110) @@ | ||
| 3099 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 3100 | * @group maplocation |
|
| 3101 | */ |
|
| 3102 | public function testMapLocationDistanceSortDescending() |
|
| 3103 | { |
|
| 3104 | $contentType = $this->createTestPlaceContentType(); |
|
| 3105 | ||
| 3106 | // Create a draft to account for behaviour with ContentType in different states |
|
| 3107 | $repository = $this->getRepository(); |
|
| 3108 | $contentTypeService = $repository->getContentTypeService(); |
|
| 3109 | $contentService = $repository->getContentService(); |
|
| 3110 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 3111 | ||
| 3112 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3113 | $createStruct->alwaysAvailable = false; |
|
| 3114 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3115 | $createStruct->setField( |
|
| 3116 | 'maplocation', |
|
| 3117 | [ |
|
| 3118 | 'latitude' => 45.894877, |
|
| 3119 | 'longitude' => 15.972699, |
|
| 3120 | 'address' => 'Here be wild boars', |
|
| 3121 | ], |
|
| 3122 | 'eng-GB' |
|
| 3123 | ); |
|
| 3124 | ||
| 3125 | $draft = $contentService->createContent($createStruct); |
|
| 3126 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3127 | ||
| 3128 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3129 | $createStruct->alwaysAvailable = false; |
|
| 3130 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3131 | $createStruct->setField( |
|
| 3132 | 'maplocation', |
|
| 3133 | [ |
|
| 3134 | 'latitude' => 45.927334, |
|
| 3135 | 'longitude' => 15.934847, |
|
| 3136 | 'address' => 'A lone tree', |
|
| 3137 | ], |
|
| 3138 | 'eng-GB' |
|
| 3139 | ); |
|
| 3140 | ||
| 3141 | $draft = $contentService->createContent($createStruct); |
|
| 3142 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3143 | ||
| 3144 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3145 | $createStruct->alwaysAvailable = false; |
|
| 3146 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3147 | $createStruct->setField( |
|
| 3148 | 'maplocation', |
|
| 3149 | [ |
|
| 3150 | 'latitude' => 45.903777, |
|
| 3151 | 'longitude' => 15.958788, |
|
| 3152 | 'address' => 'Meadow with mushrooms', |
|
| 3153 | ], |
|
| 3154 | 'eng-GB' |
|
| 3155 | ); |
|
| 3156 | ||
| 3157 | $draft = $contentService->createContent($createStruct); |
|
| 3158 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3159 | ||
| 3160 | $this->refreshSearch($repository); |
|
| 3161 | ||
| 3162 | $well = [ |
|
| 3163 | 'latitude' => 43.756825, |
|
| 3164 | 'longitude' => 15.775074, |
|
| 3165 | ]; |
|
| 3166 | ||
| 3167 | $query = new Query( |
|
| 3168 | [ |
|
| 3169 | 'filter' => new Criterion\LogicalAnd( |
|
| 3170 | [ |
|
| 3171 | new Criterion\ContentTypeId($contentType->id), |
|
| 3172 | new Criterion\MapLocationDistance( |
|
| 3173 | 'maplocation', |
|
| 3174 | Criterion\Operator::GTE, |
|
| 3175 | 235, |
|
| 3176 | $well['latitude'], |
|
| 3177 | $well['longitude'] |
|
| 3178 | ), |
|
| 3179 | ] |
|
| 3180 | ), |
|
| 3181 | 'offset' => 0, |
|
| 3182 | 'limit' => 10, |
|
| 3183 | 'sortClauses' => [ |
|
| 3184 | new SortClause\MapLocationDistance( |
|
| 3185 | 'testtype', |
|
| 3186 | 'maplocation', |
|
| 3187 | $well['latitude'], |
|
| 3188 | $well['longitude'], |
|
| 3189 | Query::SORT_DESC |
|
| 3190 | ), |
|
| 3191 | ], |
|
| 3192 | ] |
|
| 3193 | ); |
|
| 3194 | ||
| 3195 | $searchService = $repository->getSearchService(); |
|
| 3196 | $result = $searchService->findContent($query); |
|
| 3197 | ||
| 3198 | $this->assertEquals(3, $result->totalCount); |
|
| 3199 | $this->assertEquals( |
|
| 3200 | $wildBoars->id, |
|
| 3201 | $result->searchHits[2]->valueObject->id |
|
| 3202 | ); |
|
| 3203 | $this->assertEquals( |
|
| 3204 | $mushrooms->id, |
|
| 3205 | $result->searchHits[1]->valueObject->id |
|
| 3206 | ); |
|
| 3207 | $this->assertEquals( |
|
| 3208 | $tree->id, |
|
| 3209 | $result->searchHits[0]->valueObject->id |
|
| 3210 | ); |
|
| 3211 | } |
|
| 3212 | ||
| 3213 | /** |
|
| 3214 | * Test for the findContent() method. |
|