diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index b77a7799e..e3d7a230b 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -339,6 +339,16 @@ public function vectorSearchIndex(array $definition, string $name = 'default'): return $this; } + /** + * Drop an Atlas Search or Vector Search index + */ + public function dropSearchIndex(string $name): static + { + $this->collection->dropSearchIndex($name); + + return $this; + } + /** * Allow fluent columns. * diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 61280a726..34029aa32 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -539,6 +539,13 @@ public function testSearchIndex(): void self::assertSame('search', $index['type']); self::assertFalse($index['latestDefinition']['mappings']['dynamic']); self::assertSame('lucene.whitespace', $index['latestDefinition']['mappings']['fields']['foo']['analyzer']); + + Schema::table('newcollection', function (Blueprint $collection) { + $collection->dropSearchIndex('default'); + }); + + $index = $this->getSearchIndex('newcollection', 'default'); + self::assertNull($index); } public function testVectorSearchIndex() @@ -559,6 +566,14 @@ public function testVectorSearchIndex() self::assertSame('vector', $index['name']); self::assertSame('vectorSearch', $index['type']); self::assertSame('vector', $index['latestDefinition']['fields'][0]['type']); + + // Drop the index + Schema::table('newcollection', function (Blueprint $collection) { + $collection->dropSearchIndex('vector'); + }); + + $index = $this->getSearchIndex('newcollection', 'vector'); + self::assertNull($index); } protected function assertIndexExists(string $collection, string $name): IndexInfo