1
0
Fork 0
mirror of synced 2024-06-15 09:14:50 +12:00

Implemented search

This commit is contained in:
Eldad Fux 2021-05-27 13:09:14 +03:00
parent abd0bba8a4
commit 26d0d5d3dc
11 changed files with 125 additions and 108 deletions

View file

@ -184,6 +184,13 @@ $collections = [
],
],
'indexes' => [
[
'$id' => '_fulltext_name',
'type' => Database::INDEX_FULLTEXT,
'attributes' => ['name'],
'lengths' => [1024],
'orders' => [Database::ORDER_ASC],
]
],
],
@ -360,7 +367,15 @@ $collections = [
'filters' => [],
],
],
'indexes' => [],
'indexes' => [
[
'$id' => '_fulltext_name',
'type' => Database::INDEX_FULLTEXT,
'attributes' => ['name'],
'lengths' => [1024],
'orders' => [Database::ORDER_ASC],
]
],
],
'memberships' => [
@ -618,6 +633,13 @@ $collections = [
'attributes' => ['bucketId'],
'lengths' => [Database::LENGTH_KEY],
'orders' => [Database::ORDER_ASC],
],
[
'$id' => '_fulltext_name',
'type' => Database::INDEX_FULLTEXT,
'attributes' => ['name'],
'lengths' => [1024],
'orders' => [Database::ORDER_ASC],
]
],
],
@ -760,6 +782,13 @@ $collections = [
],
],
'indexes' => [
[
'$id' => '_fulltext_name',
'type' => Database::INDEX_FULLTEXT,
'attributes' => ['name'],
'lengths' => [1024],
'orders' => [Database::ORDER_ASC],
]
],
],

View file

@ -810,8 +810,8 @@ App::get('/v1/account/sessions')
}
$response->dynamic2(new Document([
'sessions' => $sessions,
'sum' => count($sessions),
'sessions' => $sessions
]), Response::MODEL_SESSION_LIST);
});
@ -1250,8 +1250,8 @@ App::delete('/v1/account/sessions')
$events
->setParam('eventData', $response->output2(new Document([
'sessions' => $sessions,
'sum' => count($sessions),
'sessions' => $sessions
]), Response::MODEL_SESSION_LIST))
;

View file

@ -85,10 +85,8 @@ App::post('/v1/database/collections')
->setParam('data', $data->getArrayCopy())
;
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic($data, Response::MODEL_COLLECTION)
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($data, Response::MODEL_COLLECTION);
});
App::get('/v1/database/collections')
@ -123,8 +121,8 @@ App::get('/v1/database/collections')
]);
$response->dynamic(new Document([
'collections' => $results,
'sum' => $projectDB->getSum(),
'collections' => $results
]), Response::MODEL_COLLECTION_LIST);
});
@ -399,10 +397,8 @@ App::post('/v1/database/collections/:collectionId/documents')
->setParam('data', $data->getArrayCopy())
;
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic($data, Response::MODEL_DOCUMENT)
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($data, Response::MODEL_DOCUMENT);
});
App::get('/v1/database/collections/:collectionId/documents')

View file

@ -66,10 +66,8 @@ App::post('/v1/functions')
'timeout' => $timeout,
]));
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic2($function, Response::MODEL_FUNCTION)
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic2($function, Response::MODEL_FUNCTION);
});
App::get('/v1/functions')
@ -93,9 +91,11 @@ App::get('/v1/functions')
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
$queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, [$search])] : [];
$response->dynamic2(new Document([
'sum' => $dbForInternal->count('functions', [], APP_LIMIT_COUNT),
'functions' => $dbForInternal->find('functions', [], $limit, $offset)
'functions' => $dbForInternal->find('functions', $queries, $limit, $offset, ['_id'], [$orderType]),
'sum' => $dbForInternal->count('functions', $queries, APP_LIMIT_COUNT),
]), Response::MODEL_FUNCTION_LIST);
});
@ -483,10 +483,8 @@ App::post('/v1/functions/:functionId/tags')
->setParam('storage', $tag->getAttribute('size', 0))
;
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic2($tag, Response::MODEL_TAG)
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic2($tag, Response::MODEL_TAG);
});
App::get('/v1/functions/:functionId/tags')
@ -501,13 +499,13 @@ App::get('/v1/functions/:functionId/tags')
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_TAG_LIST)
->param('functionId', '', new UID(), 'Function unique ID.')
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
// ->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
->param('limit', 25, new Range(0, 100), 'Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request.', true)
->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true)
->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true)
// ->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true)
->inject('response')
->inject('dbForInternal')
->action(function ($functionId, $search, $limit, $offset, $orderType, $response, $dbForInternal) {
->action(function ($functionId, $limit, $offset, $response, $dbForInternal) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
@ -516,18 +514,15 @@ App::get('/v1/functions/:functionId/tags')
if (empty($function->getId())) {
throw new Exception('Function not found', 404);
}
$queries[] = new Query('functionId', Query::TYPE_EQUAL, [$function->getId()]);
$results = $dbForInternal->find('tags', [
new Query('functionId', Query::TYPE_EQUAL, [$function->getId()]),
], $limit, $offset);
$sum = $dbForInternal->count('tags', [
new Query('functionId', Query::TYPE_EQUAL, [$function->getId()]),
], APP_LIMIT_COUNT);
$results = $dbForInternal->find('tags', $queries, $limit, $offset);
$sum = $dbForInternal->count('tags', $queries, APP_LIMIT_COUNT);
$response->dynamic2(new Document([
'tags' => $results,
'sum' => $sum,
'tags' => $results
]), Response::MODEL_TAG_LIST);
});
@ -730,10 +725,8 @@ App::post('/v1/functions/:functionId/executions')
'jwt' => $jwt,
]);
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic2($execution, Response::MODEL_EXECUTION)
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic2($execution, Response::MODEL_EXECUTION);
});
App::get('/v1/functions/:functionId/executions')
@ -748,13 +741,11 @@ App::get('/v1/functions/:functionId/executions')
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_EXECUTION_LIST)
->param('functionId', '', new UID(), 'Function unique ID.')
->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true)
->param('limit', 25, new Range(0, 100), 'Results limit value. By default will return maximum 25 results. Maximum of 100 results allowed per request.', true)
->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true)
->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true)
->inject('response')
->inject('dbForInternal')
->action(function ($functionId, $search, $limit, $offset, $orderType, $response, $dbForInternal) {
->action(function ($functionId, $limit, $offset, $response, $dbForInternal) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
@ -765,7 +756,7 @@ App::get('/v1/functions/:functionId/executions')
if (empty($function->getId())) {
throw new Exception('Function not found', 404);
}
$results = $dbForInternal->find('executions', [
new Query('functionId', Query::TYPE_EQUAL, [$function->getId()]),
], $limit, $offset);
@ -775,8 +766,8 @@ App::get('/v1/functions/:functionId/executions')
], APP_LIMIT_COUNT);
$response->dynamic2(new Document([
'executions' => $results,
'sum' => $sum,
'executions' => $results
]), Response::MODEL_EXECUTION_LIST);
});

View file

@ -6,7 +6,6 @@ use Utopia\Storage\Device\Local;
use Utopia\Storage\Storage;
use Appwrite\ClamAV\Network;
use Appwrite\Event\Event;
use RuntimeException;
App::get('/v1/health')
->desc('Get HTTP')
@ -268,7 +267,7 @@ App::get('/v1/health/anti-virus')
'status' => (@$antiVirus->ping()) ? 'online' : 'offline',
'version' => @$antiVirus->version(),
]);
} catch( RuntimeException $e) {
} catch (Throwable $e) {
$response->json([
'status' => 'offline',
'version' => '',

View file

@ -18,6 +18,7 @@ use Appwrite\Network\Validator\Domain as DomainValidator;
use Appwrite\Utopia\Response;
use Cron\CronExpression;
use Utopia\Database\Document;
use Utopia\Database\Query;
use Utopia\Database\Validator\UID;
App::post('/v1/projects')
@ -143,12 +144,14 @@ App::get('/v1/projects')
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForConsole */
$results = $dbForConsole->find('projects', [], $limit, $offset);
$sum = $dbForConsole->count('projects', [], APP_LIMIT_COUNT);
$queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, [$search])] : [];
$results = $dbForConsole->find('projects', $queries, $limit, $offset);
$sum = $dbForConsole->count('projects', $queries, APP_LIMIT_COUNT);
$response->dynamic2(new Document([
'projects' => $results,
'sum' => $sum,
'projects' => $results
]), Response::MODEL_PROJECT_LIST);
});
@ -622,10 +625,8 @@ App::post('/v1/projects/:projectId/webhooks')
->setAttribute('webhooks', $webhook, Document::SET_TYPE_APPEND)
);
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic2($webhook, Response::MODEL_WEBHOOK)
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic2($webhook, Response::MODEL_WEBHOOK);
});
App::get('/v1/projects/:projectId/webhooks')
@ -654,8 +655,8 @@ App::get('/v1/projects/:projectId/webhooks')
$webhooks = $project->getAttribute('webhooks', []);
$response->dynamic2(new Document([
'webhooks' => $webhooks,
'sum' => count($webhooks),
'webhooks' => $webhooks
]), Response::MODEL_WEBHOOK_LIST);
});
@ -814,10 +815,8 @@ App::post('/v1/projects/:projectId/keys')
->setAttribute('keys', $key, Document::SET_TYPE_APPEND)
);
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic2($key, Response::MODEL_KEY)
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic2($key, Response::MODEL_KEY);
});
App::get('/v1/projects/:projectId/keys')
@ -846,8 +845,8 @@ App::get('/v1/projects/:projectId/keys')
$keys = $project->getAttribute('keys', []);
$response->dynamic2(new Document([
'keys' => $keys,
'sum' => count($keys),
'keys' => $keys
]), Response::MODEL_KEY_LIST);
});
@ -1019,10 +1018,8 @@ App::post('/v1/projects/:projectId/tasks')
ResqueScheduler::enqueueAt($next, 'v1-tasks', 'TasksV1', $task->getArrayCopy());
}
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic2($task, Response::MODEL_TASK)
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic2($task, Response::MODEL_TASK);
});
App::get('/v1/projects/:projectId/tasks')
@ -1051,8 +1048,8 @@ App::get('/v1/projects/:projectId/tasks')
$tasks = $project->getAttribute('tasks', []);
$response->dynamic2(new Document([
'tasks' => $tasks,
'sum' => count($tasks),
'tasks' => $tasks
]), Response::MODEL_TASK_LIST);
});
@ -1233,10 +1230,8 @@ App::post('/v1/projects/:projectId/platforms')
->setAttribute('platforms', $platform, Document::SET_TYPE_APPEND)
);
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic2($platform, Response::MODEL_PLATFORM)
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic2($platform, Response::MODEL_PLATFORM);
});
App::get('/v1/projects/:projectId/platforms')
@ -1265,8 +1260,8 @@ App::get('/v1/projects/:projectId/platforms')
$platforms = $project->getAttribute('platforms', []);
$response->dynamic2(new Document([
'platforms' => $platforms,
'sum' => count($platforms),
'platforms' => $platforms
]), Response::MODEL_PLATFORM_LIST);
});
@ -1444,10 +1439,8 @@ App::post('/v1/projects/:projectId/domains')
->setAttribute('domains', $domain, Document::SET_TYPE_APPEND)
);
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic2($domain, Response::MODEL_DOMAIN)
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic2($domain, Response::MODEL_DOMAIN);
});
App::get('/v1/projects/:projectId/domains')
@ -1476,8 +1469,8 @@ App::get('/v1/projects/:projectId/domains')
$domains = $project->getAttribute('domains', []);
$response->dynamic2(new Document([
'domains' => $domains,
'sum' => count($domains),
'domains' => $domains
]), Response::MODEL_DOMAIN_LIST);
});

View file

@ -21,6 +21,7 @@ use Utopia\Image\Image;
use Appwrite\OpenSSL\OpenSSL;
use Appwrite\Utopia\Response;
use Utopia\Config\Config;
use Utopia\Database\Query;
use Utopia\Validator\Numeric;
App::post('/v1/storage/files')
@ -149,9 +150,8 @@ App::post('/v1/storage/files')
->setParam('storage', $sizeActual)
;
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->dynamic2($file, Response::MODEL_FILE)
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic2($file, Response::MODEL_FILE);
;
});
@ -176,9 +176,11 @@ App::get('/v1/storage/files')
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
$queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, $search)] : [];
$response->dynamic2(new Document([
'sum' => $dbForInternal->count('files', [], APP_LIMIT_COUNT),
'files' => $dbForInternal->find('files', [], $limit, $offset)
'files' => $dbForInternal->find('files', $queries, $limit, $offset, ['_id'], [$orderType]),
'sum' => $dbForInternal->count('files', $queries, APP_LIMIT_COUNT),
]), Response::MODEL_FILE_LIST);
});

View file

@ -104,12 +104,14 @@ App::get('/v1/teams')
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForInternal */
$results = $dbForInternal->find('teams', [], $limit, $offset);
$sum = $dbForInternal->count('teams', [], APP_LIMIT_COUNT);
$queries = ($search) ? [new Query('name', Query::TYPE_SEARCH, [$search])] : [];
$results = $dbForInternal->find('teams', $queries, $limit, $offset, ['_id'], [$orderType]);
$sum = $dbForInternal->count('teams', $queries, APP_LIMIT_COUNT);
$response->dynamic2(new Document([
'teams' => $results,
'sum' => $sum,
'teams' => $results
]), Response::MODEL_TEAM_LIST);
});
@ -449,8 +451,8 @@ App::get('/v1/teams/:teamId/memberships')
}
$response->dynamic2(new Document([
'memberships' => $users,
'sum' => $sum,
'memberships' => $users
]), Response::MODEL_MEMBERSHIP_LIST);
});

View file

@ -91,8 +91,8 @@ App::get('/v1/users')
$sum = $dbForInternal->count('users', [], APP_LIMIT_COUNT);
$response->dynamic2(new Document([
'users' => $results,
'sum' => $sum,
'users' => $results
]), Response::MODEL_USER_LIST);
});
@ -193,8 +193,8 @@ App::get('/v1/users/:userId/sessions')
}
$response->dynamic2(new Document([
'sessions' => $sessions,
'sum' => count($sessions),
'sessions' => $sessions
]), Response::MODEL_SESSION_LIST);
}, ['response', 'dbForInternal', 'locale']);

View file

@ -45,7 +45,7 @@
"utopia-php/cache": "0.4.*",
"utopia-php/cli": "0.11.*",
"utopia-php/config": "0.2.*",
"utopia-php/database": "dev-feat-new-doc-methods",
"utopia-php/database": "dev-feat-mariadb-fulltext-support",
"utopia-php/locale": "0.3.*",
"utopia-php/registry": "0.4.*",
"utopia-php/preloader": "0.2.*",

53
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "1d24d85bcbddad6834435b58286703ca",
"content-hash": "d9816fe1eb62d29f71193b590b547171",
"packages": [
{
"name": "adhocore/jwt",
@ -355,16 +355,16 @@
},
{
"name": "composer/package-versions-deprecated",
"version": "1.11.99.1",
"version": "1.11.99.2",
"source": {
"type": "git",
"url": "https://github.com/composer/package-versions-deprecated.git",
"reference": "7413f0b55a051e89485c5cb9f765fe24bb02a7b6"
"reference": "c6522afe5540d5fc46675043d3ed5a45a740b27c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/7413f0b55a051e89485c5cb9f765fe24bb02a7b6",
"reference": "7413f0b55a051e89485c5cb9f765fe24bb02a7b6",
"url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/c6522afe5540d5fc46675043d3ed5a45a740b27c",
"reference": "c6522afe5540d5fc46675043d3ed5a45a740b27c",
"shasum": ""
},
"require": {
@ -408,7 +408,7 @@
"description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
"support": {
"issues": "https://github.com/composer/package-versions-deprecated/issues",
"source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.1"
"source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.2"
},
"funding": [
{
@ -424,7 +424,7 @@
"type": "tidelift"
}
],
"time": "2020-11-11T10:22:58+00:00"
"time": "2021-05-24T07:46:03+00:00"
},
{
"name": "dragonmantank/cron-expression",
@ -1919,11 +1919,17 @@
},
{
"name": "utopia-php/database",
"version": "dev-feat-new-doc-methods",
"version": "dev-feat-mariadb-fulltext-support",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/database",
"reference": "d4bd2ab55c87b290bd241b437c3095d945dcbf2f"
"url": "https://github.com/utopia-php/database.git",
"reference": "aa3f364d1a1140e9707bfeecc2dbbb29bb75fdef"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/database/zipball/aa3f364d1a1140e9707bfeecc2dbbb29bb75fdef",
"reference": "aa3f364d1a1140e9707bfeecc2dbbb29bb75fdef",
"shasum": ""
},
"require": {
"ext-mongodb": "*",
@ -1944,11 +1950,7 @@
"Utopia\\Database\\": "src/Database"
}
},
"autoload-dev": {
"psr-4": {
"Utopia\\Tests\\": "tests/Database"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -1970,7 +1972,11 @@
"upf",
"utopia"
],
"time": "2021-05-15T22:41:08+00:00"
"support": {
"issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/feat-mariadb-fulltext-support"
},
"time": "2021-05-18T07:51:42+00:00"
},
{
"name": "utopia-php/domains",
@ -5879,16 +5885,16 @@
},
{
"name": "twig/twig",
"version": "v2.14.5",
"version": "v2.14.6",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "c9dd15b3a80725bc4919730fae462bddcc960820"
"reference": "27e5cf2b05e3744accf39d4c68a3235d9966d260"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/c9dd15b3a80725bc4919730fae462bddcc960820",
"reference": "c9dd15b3a80725bc4919730fae462bddcc960820",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/27e5cf2b05e3744accf39d4c68a3235d9966d260",
"reference": "27e5cf2b05e3744accf39d4c68a3235d9966d260",
"shasum": ""
},
"require": {
@ -5942,7 +5948,7 @@
],
"support": {
"issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v2.14.5"
"source": "https://github.com/twigphp/Twig/tree/v2.14.6"
},
"funding": [
{
@ -5954,7 +5960,7 @@
"type": "tidelift"
}
],
"time": "2021-05-12T08:02:35+00:00"
"time": "2021-05-16T12:12:47+00:00"
},
{
"name": "vimeo/psalm",
@ -6115,8 +6121,7 @@
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"utopia-php/database": 20,
"appwrite/sdk-generator": 20
"utopia-php/database": 20
},
"prefer-stable": false,
"prefer-lowest": false,