@@ -85,6 +85,7 @@ class Database
8585 public const INDEX_HNSW_EUCLIDEAN = 'hnsw_euclidean ' ;
8686 public const INDEX_HNSW_COSINE = 'hnsw_cosine ' ;
8787 public const INDEX_HNSW_DOT = 'hnsw_dot ' ;
88+ public const INDEX_TRIGRAM = 'trigram ' ;
8889
8990 // Max limits
9091 public const MAX_INT = 2147483647 ;
@@ -1641,6 +1642,11 @@ public function createCollection(string $id, array $attributes = [], array $inde
16411642 $ this ->adapter ->getSupportForMultipleFulltextIndexes (),
16421643 $ this ->adapter ->getSupportForIdenticalIndexes (),
16431644 $ this ->adapter ->getSupportForObject (),
1645+ $ this ->adapter ->getSupportForTrigramIndex (),
1646+ $ this ->adapter ->getSupportForSpatialAttributes (),
1647+ $ this ->adapter ->getSupportForIndex (),
1648+ $ this ->adapter ->getSupportForUniqueIndex (),
1649+ $ this ->adapter ->getSupportForFulltextIndex (),
16441650 );
16451651 foreach ($ indexes as $ index ) {
16461652 if (!$ validator ->isValid ($ index )) {
@@ -2785,7 +2791,12 @@ public function updateAttribute(string $collection, string $id, ?string $type =
27852791 $ this ->adapter ->getSupportForAttributes (),
27862792 $ this ->adapter ->getSupportForMultipleFulltextIndexes (),
27872793 $ this ->adapter ->getSupportForIdenticalIndexes (),
2788- $ this ->adapter ->getSupportForObject ()
2794+ $ this ->adapter ->getSupportForObject (),
2795+ $ this ->adapter ->getSupportForTrigramIndex (),
2796+ $ this ->adapter ->getSupportForSpatialAttributes (),
2797+ $ this ->adapter ->getSupportForIndex (),
2798+ $ this ->adapter ->getSupportForUniqueIndex (),
2799+ $ this ->adapter ->getSupportForFulltextIndex (),
27892800 );
27902801
27912802 foreach ($ indexes as $ index ) {
@@ -3623,52 +3634,6 @@ public function createIndex(string $collection, string $id, string $type, array
36233634 throw new LimitException ('Index limit reached. Cannot create new index. ' );
36243635 }
36253636
3626- switch ($ type ) {
3627- case self ::INDEX_KEY :
3628- if (!$ this ->adapter ->getSupportForIndex ()) {
3629- throw new DatabaseException ('Key index is not supported ' );
3630- }
3631- break ;
3632-
3633- case self ::INDEX_UNIQUE :
3634- if (!$ this ->adapter ->getSupportForUniqueIndex ()) {
3635- throw new DatabaseException ('Unique index is not supported ' );
3636- }
3637- break ;
3638-
3639- case self ::INDEX_FULLTEXT :
3640- if (!$ this ->adapter ->getSupportForFulltextIndex ()) {
3641- throw new DatabaseException ('Fulltext index is not supported ' );
3642- }
3643- break ;
3644-
3645- case self ::INDEX_SPATIAL :
3646- if (!$ this ->adapter ->getSupportForSpatialAttributes ()) {
3647- throw new DatabaseException ('Spatial indexes are not supported ' );
3648- }
3649- if (!empty ($ orders ) && !$ this ->adapter ->getSupportForSpatialIndexOrder ()) {
3650- throw new DatabaseException ('Spatial indexes with explicit orders are not supported. Remove the orders to create this index. ' );
3651- }
3652- break ;
3653-
3654- case Database::INDEX_HNSW_EUCLIDEAN :
3655- case Database::INDEX_HNSW_COSINE :
3656- case Database::INDEX_HNSW_DOT :
3657- if (!$ this ->adapter ->getSupportForVectors ()) {
3658- throw new DatabaseException ('Vector indexes are not supported ' );
3659- }
3660- break ;
3661-
3662- case self ::INDEX_OBJECT :
3663- if (!$ this ->adapter ->getSupportForObject ()) {
3664- throw new DatabaseException ('Object indexes are not supported ' );
3665- }
3666- break ;
3667-
3668- default :
3669- throw new DatabaseException ('Unknown index type: ' . $ type . '. Must be one of ' . Database::INDEX_KEY . ', ' . Database::INDEX_UNIQUE . ', ' . Database::INDEX_FULLTEXT . ', ' . Database::INDEX_SPATIAL . ', ' . Database::INDEX_OBJECT . ', ' . Database::INDEX_HNSW_EUCLIDEAN . ', ' . Database::INDEX_HNSW_COSINE . ', ' . Database::INDEX_HNSW_DOT );
3670- }
3671-
36723637 /** @var array<Document> $collectionAttributes */
36733638 $ collectionAttributes = $ collection ->getAttribute ('attributes ' , []);
36743639 $ indexAttributesWithTypes = [];
@@ -3722,6 +3687,11 @@ public function createIndex(string $collection, string $id, string $type, array
37223687 $ this ->adapter ->getSupportForMultipleFulltextIndexes (),
37233688 $ this ->adapter ->getSupportForIdenticalIndexes (),
37243689 $ this ->adapter ->getSupportForObject (),
3690+ $ this ->adapter ->getSupportForTrigramIndex (),
3691+ $ this ->adapter ->getSupportForSpatialAttributes (),
3692+ $ this ->adapter ->getSupportForIndex (),
3693+ $ this ->adapter ->getSupportForUniqueIndex (),
3694+ $ this ->adapter ->getSupportForFulltextIndex (),
37253695 );
37263696 if (!$ validator ->isValid ($ index )) {
37273697 throw new IndexException ($ validator ->getDescription ());
0 commit comments