Skip to content

PHPORM-283 Add Schema::dropSearchIndex() #3235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
15 changes: 15 additions & 0 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
Loading