@@ -280,6 +280,11 @@ public function checkSpatialIndex(Document $index): bool
280280 $ attributes = $ index ->getAttribute ('attributes ' , []);
281281 $ orders = $ index ->getAttribute ('orders ' , []);
282282
283+ if (\count ($ attributes ) !== 1 ) {
284+ $ this ->message = 'Spatial index must have exactly one attribute ' ;
285+ return false ;
286+ }
287+
283288 foreach ($ attributes as $ attributeName ) {
284289 $ attribute = $ this ->attributes [\strtolower ($ attributeName )] ?? new Document ();
285290 $ attributeType = $ attribute ->getAttribute ('type ' , '' );
@@ -304,6 +309,34 @@ public function checkSpatialIndex(Document $index): bool
304309 return true ;
305310 }
306311
312+ /**
313+ * @param Document $index
314+ * @return bool
315+ */
316+ public function checkNonSpatialIndexOnSpatialAttribute (Document $ index ): bool
317+ {
318+ $ type = $ index ->getAttribute ('type ' );
319+
320+ // Skip check for spatial indexes
321+ if ($ type === Database::INDEX_SPATIAL ) {
322+ return true ;
323+ }
324+
325+ $ attributes = $ index ->getAttribute ('attributes ' , []);
326+
327+ foreach ($ attributes as $ attributeName ) {
328+ $ attribute = $ this ->attributes [\strtolower ($ attributeName )] ?? new Document ();
329+ $ attributeType = $ attribute ->getAttribute ('type ' , '' );
330+
331+ if (\in_array ($ attributeType , Database::SPATIAL_TYPES , true )) {
332+ $ this ->message = 'Cannot create ' . $ type . ' index on spatial attribute " ' . $ attributeName . '". Spatial attributes require spatial indexes. ' ;
333+ return false ;
334+ }
335+ }
336+
337+ return true ;
338+ }
339+
307340 /**
308341 * @param Document $index
309342 * @return bool
@@ -378,6 +411,9 @@ public function isValid($value): bool
378411 if (!$ this ->checkSpatialIndex ($ value )) {
379412 return false ;
380413 }
414+ if (!$ this ->checkNonSpatialIndexOnSpatialAttribute ($ value )) {
415+ return false ;
416+ }
381417 if (!$ this ->checkVectorIndex ($ value )) {
382418 return false ;
383419 }
0 commit comments