From 2d95cfc6036e68718a7725493896c621fb56f8ac Mon Sep 17 00:00:00 2001 From: "maxim.alexeev" Date: Fri, 4 Sep 2026 16:07:11 +0400 Subject: [PATCH 1/5] Adds the ability to set attributes when adding an index --- src/Manticoresearch/Endpoints/Tables/Alter.php | 18 ++++++++++++++---- src/Manticoresearch/Table.php | 6 +++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Manticoresearch/Endpoints/Tables/Alter.php b/src/Manticoresearch/Endpoints/Tables/Alter.php index 7e741b2..050e372 100644 --- a/src/Manticoresearch/Endpoints/Tables/Alter.php +++ b/src/Manticoresearch/Endpoints/Tables/Alter.php @@ -23,10 +23,20 @@ public function setBody($params = null) { if (isset($this->table)) { if (isset($params['operation'])) { if ($params['operation'] === 'add' && isset($params['column'])) { - return parent::setBody( - ['query' => 'ALTER TABLE ' . $this->table . ' ADD COLUMN ' . - $params['column']['name'] . ' ' . strtoupper($params['column']['type'])] - ); + $columnDef = $params['column']['name'] . ' ' . strtoupper($params['column']['type']); + + if (isset($params['column']['options'])) { + $options = $params['column']['options']; + if (is_string($options)) { + $columnDef .= ' ' . $options; + } elseif (is_array($options)) { + $columnDef .= ' ' . implode(' ', $options); + } + } + + return parent::setBody( + ['query' => 'ALTER TABLE ' . $this->table . ' ADD COLUMN ' . $columnDef] + ); } if ($params['operation'] === 'drop') { return parent::setBody( diff --git a/src/Manticoresearch/Table.php b/src/Manticoresearch/Table.php index 31b1f73..f7c9440 100755 --- a/src/Manticoresearch/Table.php +++ b/src/Manticoresearch/Table.php @@ -329,7 +329,7 @@ public function flushramchunk() { $this->client->tables()->flushramchunk($params); } - public function alter($operation, $name, ?string $type = null) { + public function alter($operation, $name, ?string $type = null, $options = null) { if ($operation === 'add') { $params = [ 'table' => $this->table, @@ -338,6 +338,10 @@ public function alter($operation, $name, ?string $type = null) { 'column' => ['name' => $name, 'type' => $type], ], ]; + + if ($options !== null) { + $params['body']['column']['options'] = $options; + } } elseif ($operation === 'drop') { $params = [ 'table' => $this->table, From da03b77b5527202b394014e15ac8aebe055e1c2b Mon Sep 17 00:00:00 2001 From: "maxim.alexeev" Date: Thu, 17 Sep 2026 13:35:37 +0400 Subject: [PATCH 2/5] Adds the ability to set attributes when adding an index Tests and docs update --- docs/tableclass.md | 5 ++- docs/tables.md | 41 +++++++++++++++++- .../Endpoints/Tables/AlterTest.php | 43 +++++++++++++++++++ test/Manticoresearch/TableTest.php | 35 +++++++++++++++ 4 files changed, 120 insertions(+), 4 deletions(-) diff --git a/docs/tableclass.md b/docs/tableclass.md index bc29700..8557453 100755 --- a/docs/tableclass.md +++ b/docs/tableclass.md @@ -452,10 +452,11 @@ Parameters: - operation type - `add` or `drop` - name of the attribute - type of the attribute (only for `add`) +- options - optional column options (only for `add`), can be a string or an array of strings ```php -$table->alter($operation,$name,$type); +$table->alter($operation,$name,$type,$options); ``` @@ -474,7 +475,7 @@ $table->keywords($query, $options); ``` ```php -$table->alter($operation,$name,$type); +$table->alter($operation,$name,$type,$options); ``` diff --git a/docs/tables.md b/docs/tables.md index 85c1181..31c8064 100644 --- a/docs/tables.md +++ b/docs/tables.md @@ -87,8 +87,11 @@ The `body` parameters: * `column` - for add, drop operations, the column is an array of * `name` - column name * `type` - data type + * `options` - optional, additional column options (only for `add`). Can be a string or an array of strings +Example of adding a column without options: + $params = [ 'table' => 'testrt', 'body' => [ @@ -97,11 +100,45 @@ The `body` parameters: 'name' => 'tag', 'type'=> 'string' ] - + ] ]; $response = $client->tables()->alter($params); - + +Example of adding a column with a single option: + + $params = [ + 'table' => 'testrt', + 'body' => [ + 'operation' => 'add', + 'column' => [ + 'name' => 'tag', + 'type'=> 'string', + 'options' => 'indexed' + ] + + ] + ]; + $response = $client->tables()->alter($params); + +Example of adding a column with multiple options: + + $params = [ + 'table' => 'testrt', + 'body' => [ + 'operation' => 'add', + 'column' => [ + 'name' => 'content', + 'type'=> 'text', + 'options' => ['indexed', 'stored'] + ] + + ] + ]; + $response = $client->tables()->alter($params); + +Example of dropping a column: + $params = [ 'table' => 'testrt', 'body' => [ diff --git a/test/Manticoresearch/Endpoints/Tables/AlterTest.php b/test/Manticoresearch/Endpoints/Tables/AlterTest.php index 9f2d60d..7769ba7 100644 --- a/test/Manticoresearch/Endpoints/Tables/AlterTest.php +++ b/test/Manticoresearch/Endpoints/Tables/AlterTest.php @@ -121,6 +121,49 @@ public function testTableAddColumn() { $this->assertEquals(array_keys($expectedResponse), array_keys($response)); } + public function testTableAddColumnWithSingleOption() { + $params = [ + 'table' => 'products', + 'body' => [ + 'operation' => 'add', + 'column' => [ + 'name' => 'content', + 'type' => 'text', + 'options' => 'indexed', + ], + ], + ]; + $response = static::$client->tables()->alter($params); + $this->assertEquals(['total' => 0, 'error' => '', 'warning' => ''], $response); + + $response = static::$client->tables()->describe(['table' => 'products']); + $this->assertArrayHasKey('content', $response); + $this->assertEquals('field', $response['content']['Type']); + $this->assertStringContainsString('indexed', $response['content']['Properties']); + } + + public function testTableAddColumnWithMultipleOptions() { + $params = [ + 'table' => 'products', + 'body' => [ + 'operation' => 'add', + 'column' => [ + 'name' => 'content', + 'type' => 'text', + 'options' => ['indexed', 'stored'], + ], + ], + ]; + $response = static::$client->tables()->alter($params); + $this->assertEquals(['total' => 0, 'error' => '', 'warning' => ''], $response); + + $response = static::$client->tables()->describe(['table' => 'products']); + $this->assertArrayHasKey('content', $response); + $this->assertEquals('field', $response['content']['Type']); + $this->assertStringContainsString('indexed', $response['content']['Properties']); + $this->assertStringContainsString('stored', $response['content']['Properties']); + } + public function testSetGetTable() { $alter = new Alter(); $alter->setTable('testName'); diff --git a/test/Manticoresearch/TableTest.php b/test/Manticoresearch/TableTest.php index e02c3df..d71b720 100644 --- a/test/Manticoresearch/TableTest.php +++ b/test/Manticoresearch/TableTest.php @@ -270,6 +270,41 @@ public function testAlterAdd() { $this->assertEquals(['Type' => 'string', 'Properties' => ''], $description['example']); } + public function testAlterAddWithSingleOption() { + $table = $this->getTable(); + $response = $table->alter('add', 'example', 'string', 'indexed'); + $this->assertEquals(['total' => 0, 'error' => '', 'warning' => ''], $response); + + $description = $table->describe(); + $keys = array_keys($description); + sort($keys); + $this->assertEquals( + [ + 'example', + 'gid', + 'id', + 'label', + 'props', + 'tags', + 'title', + ], $keys + ); + + $this->assertEquals(['Type' => 'string', 'Properties' => 'indexed'], $description['example']); + } + + public function testAlterAddWithMultipleOptions() { + $table = $this->getTable(); + $response = $table->alter('add', 'example', 'text', ['indexed', 'stored']); + $this->assertEquals(['total' => 0, 'error' => '', 'warning' => ''], $response); + + $description = $table->describe(); + $this->assertArrayHasKey('example', $description); + $this->assertEquals('text', $description['example']['Type']); + $this->assertStringContainsString('indexed', $description['example']['Properties']); + $this->assertStringContainsString('stored', $description['example']['Properties']); + } + public function testAlterInvalidOperation() { $table = $this->getTable(); $this->expectException(RuntimeException::class); From eb100473dcb0613036cb647a63e7fd12f7a6b21a Mon Sep 17 00:00:00 2001 From: "maxim.alexeev" Date: Mon, 21 Sep 2026 13:38:38 +0400 Subject: [PATCH 3/5] Fixed alter tests --- .../Endpoints/Tables/AlterTest.php | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/Manticoresearch/Endpoints/Tables/AlterTest.php b/test/Manticoresearch/Endpoints/Tables/AlterTest.php index 7769ba7..1fed414 100644 --- a/test/Manticoresearch/Endpoints/Tables/AlterTest.php +++ b/test/Manticoresearch/Endpoints/Tables/AlterTest.php @@ -127,7 +127,7 @@ public function testTableAddColumnWithSingleOption() { 'body' => [ 'operation' => 'add', 'column' => [ - 'name' => 'content', + 'name' => 'content_single', 'type' => 'text', 'options' => 'indexed', ], @@ -137,9 +137,10 @@ public function testTableAddColumnWithSingleOption() { $this->assertEquals(['total' => 0, 'error' => '', 'warning' => ''], $response); $response = static::$client->tables()->describe(['table' => 'products']); - $this->assertArrayHasKey('content', $response); - $this->assertEquals('field', $response['content']['Type']); - $this->assertStringContainsString('indexed', $response['content']['Properties']); + $this->assertTrue(isset($response['content_single']), 'Column content_single is missing'); + + $properties = (string) $response['content_single']['Properties']; + $this->assertStringContainsString('indexed', $properties); } public function testTableAddColumnWithMultipleOptions() { @@ -148,7 +149,7 @@ public function testTableAddColumnWithMultipleOptions() { 'body' => [ 'operation' => 'add', 'column' => [ - 'name' => 'content', + 'name' => 'content_multiple', 'type' => 'text', 'options' => ['indexed', 'stored'], ], @@ -158,10 +159,11 @@ public function testTableAddColumnWithMultipleOptions() { $this->assertEquals(['total' => 0, 'error' => '', 'warning' => ''], $response); $response = static::$client->tables()->describe(['table' => 'products']); - $this->assertArrayHasKey('content', $response); - $this->assertEquals('field', $response['content']['Type']); - $this->assertStringContainsString('indexed', $response['content']['Properties']); - $this->assertStringContainsString('stored', $response['content']['Properties']); + $this->assertTrue(isset($response['content_multiple']), 'Column content_multiple is missing'); + + $properties = (string) $response['content_multiple']['Properties']; + $this->assertStringContainsString('indexed', $properties); + $this->assertStringContainsString('stored', $properties); } public function testSetGetTable() { From 876a719b50a80b7c08761c32412dd832707dc91e Mon Sep 17 00:00:00 2001 From: "maxim.alexeev" Date: Mon, 21 Sep 2026 13:50:32 +0400 Subject: [PATCH 4/5] Fixed table tests --- test/Manticoresearch/TableTest.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/test/Manticoresearch/TableTest.php b/test/Manticoresearch/TableTest.php index d71b720..693a49b 100644 --- a/test/Manticoresearch/TableTest.php +++ b/test/Manticoresearch/TableTest.php @@ -272,7 +272,7 @@ public function testAlterAdd() { public function testAlterAddWithSingleOption() { $table = $this->getTable(); - $response = $table->alter('add', 'example', 'string', 'indexed'); + $response = $table->alter('add', 'content_single', 'text', 'indexed'); $this->assertEquals(['total' => 0, 'error' => '', 'warning' => ''], $response); $description = $table->describe(); @@ -280,7 +280,7 @@ public function testAlterAddWithSingleOption() { sort($keys); $this->assertEquals( [ - 'example', + 'content_single', 'gid', 'id', 'label', @@ -290,19 +290,24 @@ public function testAlterAddWithSingleOption() { ], $keys ); - $this->assertEquals(['Type' => 'string', 'Properties' => 'indexed'], $description['example']); + $properties = (string)$description['content_single']['Properties']; + $this->assertStringContainsString('indexed', $properties); } public function testAlterAddWithMultipleOptions() { $table = $this->getTable(); - $response = $table->alter('add', 'example', 'text', ['indexed', 'stored']); + $response = $table->alter('add', 'content_multiple', 'text', ['indexed', 'stored']); $this->assertEquals(['total' => 0, 'error' => '', 'warning' => ''], $response); $description = $table->describe(); - $this->assertArrayHasKey('example', $description); - $this->assertEquals('text', $description['example']['Type']); - $this->assertStringContainsString('indexed', $description['example']['Properties']); - $this->assertStringContainsString('stored', $description['example']['Properties']); + $this->assertTrue( + isset($description['content_multiple']), + 'Column content_multiple is missing' + ); + + $properties = (string)$description['content_multiple']['Properties']; + $this->assertStringContainsString('indexed', $properties); + $this->assertStringContainsString('stored', $properties); } public function testAlterInvalidOperation() { From a68994170f075ade18cef5df66549bf07cc34d5e Mon Sep 17 00:00:00 2001 From: "maxim.alexeev" Date: Mon, 21 Sep 2026 13:55:34 +0400 Subject: [PATCH 5/5] Fixed codestyle warnings --- test/Manticoresearch/Endpoints/Tables/AlterTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Manticoresearch/Endpoints/Tables/AlterTest.php b/test/Manticoresearch/Endpoints/Tables/AlterTest.php index 1fed414..aadcab3 100644 --- a/test/Manticoresearch/Endpoints/Tables/AlterTest.php +++ b/test/Manticoresearch/Endpoints/Tables/AlterTest.php @@ -139,7 +139,7 @@ public function testTableAddColumnWithSingleOption() { $response = static::$client->tables()->describe(['table' => 'products']); $this->assertTrue(isset($response['content_single']), 'Column content_single is missing'); - $properties = (string) $response['content_single']['Properties']; + $properties = (string)$response['content_single']['Properties']; $this->assertStringContainsString('indexed', $properties); } @@ -161,7 +161,7 @@ public function testTableAddColumnWithMultipleOptions() { $response = static::$client->tables()->describe(['table' => 'products']); $this->assertTrue(isset($response['content_multiple']), 'Column content_multiple is missing'); - $properties = (string) $response['content_multiple']['Properties']; + $properties = (string)$response['content_multiple']['Properties']; $this->assertStringContainsString('indexed', $properties); $this->assertStringContainsString('stored', $properties); }