From 1a6a1498bc80c831e30db5867aa1704d3b9c4b07 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 19 Jan 2022 00:45:44 +1300 Subject: [PATCH 1/3] Add fulltext index for collections collection `name` column to fix `listCollections` search --- app/config/collections.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/config/collections.php b/app/config/collections.php index abcdec9c1d..0138756177 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -102,6 +102,13 @@ $collections = [ 'lengths' => [1024], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => '_fulltext_name', + 'type' => Database::INDEX_FULLTEXT, + 'attributes' => ['name'], + 'lengths' => [256], + 'orders' => [Database::ORDER_ASC], + ], ], ], From 438f80cc5a2d6457b585280fb61e0c6f69beddb7 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 19 Jan 2022 20:57:18 +1300 Subject: [PATCH 2/3] Update query attribute to search, remove name index --- app/config/collections.php | 7 ------- app/controllers/api/database.php | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 0138756177..abcdec9c1d 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -102,13 +102,6 @@ $collections = [ 'lengths' => [1024], 'orders' => [Database::ORDER_ASC], ], - [ - '$id' => '_fulltext_name', - 'type' => Database::INDEX_FULLTEXT, - 'attributes' => ['name'], - 'lengths' => [256], - 'orders' => [Database::ORDER_ASC], - ], ], ], diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index a25e5e62ae..9d5ac716b3 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -230,7 +230,7 @@ App::get('/v1/database/collections') $queries = []; if (!empty($search)) { - $queries[] = new Query('name', Query::TYPE_SEARCH, [$search]); + $queries[] = new Query('search', Query::TYPE_SEARCH, [$search]); } $usage->setParam('database.collections.read', 1); From 06719b172cefdbbd4d15dbfcef2e7387c7c1ae7f Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 19 Jan 2022 22:04:57 +1300 Subject: [PATCH 3/3] Add listCollection using `search` parameter tests --- .../Database/DatabaseCustomServerTest.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/e2e/Services/Database/DatabaseCustomServerTest.php b/tests/e2e/Services/Database/DatabaseCustomServerTest.php index 659839debe..b770b2b6c3 100644 --- a/tests/e2e/Services/Database/DatabaseCustomServerTest.php +++ b/tests/e2e/Services/Database/DatabaseCustomServerTest.php @@ -125,6 +125,39 @@ class DatabaseCustomServerTest extends Scope $this->assertCount(0, $collections['body']['collections']); $this->assertEmpty($collections['body']['collections']); + /** + * Test for Search + */ + $collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'search' => 'first' + ]); + + $this->assertEquals(1, $collections['body']['sum']); + $this->assertEquals('first', $collections['body']['collections'][0]['$id']); + + $collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'search' => 'Test' + ]); + + $this->assertEquals(2, $collections['body']['sum']); + $this->assertEquals('Test 1', $collections['body']['collections'][0]['name']); + $this->assertEquals('Test 2', $collections['body']['collections'][1]['name']); + + $collections = $this->client->call(Client::METHOD_GET, '/database/collections', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'search' => 'Nonexistent' + ]); + + $this->assertEquals(0, $collections['body']['sum']); + /** * Test for FAILURE */