@@ -1808,6 +1808,58 @@ protected function getSearchRelevanceRaw(Query $query, string $alias): ?array
18081808 ];
18091809 }
18101810
1811+ public function getSupportForSchemaIndexes (): bool
1812+ {
1813+ return true ;
1814+ }
1815+
1816+ public function getSchemaIndexes (string $ collection ): array
1817+ {
1818+ $ schema = $ this ->getDatabase ();
1819+ $ collection = $ this ->getNamespace () . '_ ' . $ this ->filter ($ collection );
1820+
1821+ try {
1822+ $ stmt = $ this ->getPDO ()->prepare ('
1823+ SELECT
1824+ INDEX_NAME as indexName,
1825+ COLUMN_NAME as columnName,
1826+ NON_UNIQUE as nonUnique,
1827+ SEQ_IN_INDEX as seqInIndex,
1828+ INDEX_TYPE as indexType,
1829+ SUB_PART as subPart
1830+ FROM INFORMATION_SCHEMA.STATISTICS
1831+ WHERE TABLE_SCHEMA = :schema AND TABLE_NAME = :table
1832+ ORDER BY INDEX_NAME, SEQ_IN_INDEX
1833+ ' );
1834+ $ stmt ->bindParam (':schema ' , $ schema );
1835+ $ stmt ->bindParam (':table ' , $ collection );
1836+ $ stmt ->execute ();
1837+ $ rows = $ stmt ->fetchAll ();
1838+ $ stmt ->closeCursor ();
1839+
1840+ $ grouped = [];
1841+ foreach ($ rows as $ row ) {
1842+ $ name = $ row ['indexName ' ];
1843+ if (!isset ($ grouped [$ name ])) {
1844+ $ grouped [$ name ] = [
1845+ '$id ' => $ name ,
1846+ 'indexName ' => $ name ,
1847+ 'indexType ' => $ row ['indexType ' ],
1848+ 'nonUnique ' => (int )$ row ['nonUnique ' ],
1849+ 'columns ' => [],
1850+ 'lengths ' => [],
1851+ ];
1852+ }
1853+ $ grouped [$ name ]['columns ' ][] = $ row ['columnName ' ];
1854+ $ grouped [$ name ]['lengths ' ][] = $ row ['subPart ' ] !== null ? (int )$ row ['subPart ' ] : null ;
1855+ }
1856+
1857+ return \array_map (fn ($ idx ) => new Document ($ idx ), \array_values ($ grouped ));
1858+ } catch (PDOException $ e ) {
1859+ throw new DatabaseException ('Failed to get schema indexes ' , $ e ->getCode (), $ e );
1860+ }
1861+ }
1862+
18111863 protected function processException (PDOException $ e ): Exception
18121864 {
18131865 if ($ e ->getCode () === '22007 ' && isset ($ e ->errorInfo [1 ]) && $ e ->errorInfo [1 ] === 1366 ) {
0 commit comments