Skip to content

Commit 223a9f7

Browse files
authored
PHPORM-283 Add Schema::dropSearchIndex() (#3235)
1 parent 3960aeb commit 223a9f7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Schema/Blueprint.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,16 @@ public function vectorSearchIndex(array $definition, string $name = 'default'):
339339
return $this;
340340
}
341341

342+
/**
343+
* Drop an Atlas Search or Vector Search index
344+
*/
345+
public function dropSearchIndex(string $name): static
346+
{
347+
$this->collection->dropSearchIndex($name);
348+
349+
return $this;
350+
}
351+
342352
/**
343353
* Allow fluent columns.
344354
*

tests/SchemaTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,13 @@ public function testSearchIndex(): void
539539
self::assertSame('search', $index['type']);
540540
self::assertFalse($index['latestDefinition']['mappings']['dynamic']);
541541
self::assertSame('lucene.whitespace', $index['latestDefinition']['mappings']['fields']['foo']['analyzer']);
542+
543+
Schema::table('newcollection', function (Blueprint $collection) {
544+
$collection->dropSearchIndex('default');
545+
});
546+
547+
$index = $this->getSearchIndex('newcollection', 'default');
548+
self::assertNull($index);
542549
}
543550

544551
public function testVectorSearchIndex()
@@ -559,6 +566,14 @@ public function testVectorSearchIndex()
559566
self::assertSame('vector', $index['name']);
560567
self::assertSame('vectorSearch', $index['type']);
561568
self::assertSame('vector', $index['latestDefinition']['fields'][0]['type']);
569+
570+
// Drop the index
571+
Schema::table('newcollection', function (Blueprint $collection) {
572+
$collection->dropSearchIndex('vector');
573+
});
574+
575+
$index = $this->getSearchIndex('newcollection', 'vector');
576+
self::assertNull($index);
562577
}
563578

564579
protected function assertIndexExists(string $collection, string $name): IndexInfo

0 commit comments

Comments
 (0)