From b97023f2d89d81cd9763e693ddb02d982b78647b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 2 Jan 2025 19:34:27 +0100 Subject: [PATCH 1/2] Add Schema::dropSearchIndex() --- src/Schema/Blueprint.php | 10 ++++++++++ tests/SchemaTest.php | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index b77a7799e..f545683fa 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 = 'default'): static + { + $this->collection->dropSearchIndex($name); + + return $this; + } + /** * Allow fluent columns. * diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 61280a726..38421d26a 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -539,6 +539,14 @@ 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']); + + // Drop the index using default name + Schema::table('newcollection', function (Blueprint $collection) { + $collection->dropSearchIndex(); + }); + + $index = $this->getSearchIndex('newcollection', 'default'); + self::assertNull($index); } public function testVectorSearchIndex() @@ -559,6 +567,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 From e4fdc5befea66e1c0386c959c74728e1909002be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 3 Jan 2025 18:18:10 +0100 Subject: [PATCH 2/2] Require the name of the index to drop --- src/Schema/Blueprint.php | 2 +- tests/SchemaTest.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index f545683fa..e3d7a230b 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -342,7 +342,7 @@ public function vectorSearchIndex(array $definition, string $name = 'default'): /** * Drop an Atlas Search or Vector Search index */ - public function dropSearchIndex(string $name = 'default'): static + public function dropSearchIndex(string $name): static { $this->collection->dropSearchIndex($name); diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 38421d26a..34029aa32 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -540,9 +540,8 @@ public function testSearchIndex(): void self::assertFalse($index['latestDefinition']['mappings']['dynamic']); self::assertSame('lucene.whitespace', $index['latestDefinition']['mappings']['fields']['foo']['analyzer']); - // Drop the index using default name Schema::table('newcollection', function (Blueprint $collection) { - $collection->dropSearchIndex(); + $collection->dropSearchIndex('default'); }); $index = $this->getSearchIndex('newcollection', 'default');