-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from ConductionNL/development
Make json objects in database searchable
- Loading branch information
Showing
14 changed files
with
372 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace OCA\OpenRegister\Service; | ||
|
||
use OCP\DB\QueryBuilder\IQueryBuilder; | ||
|
||
interface IDatabaseJsonService | ||
{ | ||
public function filterJson(IQueryBuilder $builder, array $filters): IQueryBuilder; | ||
public function getAggregations(IQueryBuilder $builder, array $fields, int $register, int $schema, array $filters = []): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(SELECT json_extract(object, '$.tooi') as gemeentecode, count(*) as count FROM nextcloud.oc_openregister_objects group by gemeentecode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT * FROM nextcloud.oc_openregister_objects where register = 1 and json_extract(object, '$.tooi') = 0935; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace OCA\OpenRegister\Service; | ||
|
||
use OCP\DB\Exception; | ||
use OCP\DB\QueryBuilder\IQueryBuilder; | ||
|
||
class MySQLJsonService implements IDatabaseJsonService | ||
{ | ||
function filterJson(IQueryBuilder $builder, array $filters): IQueryBuilder | ||
{ | ||
unset($filters['register'], $filters['schema'], $filters['updated'], $filters['created'], $filters['_queries']); | ||
|
||
foreach($filters as $filter=>$value) { | ||
$builder->createNamedParameter(value: $value, placeHolder: ":value$filter"); | ||
$builder->createNamedParameter(value: "$.$filter", placeHolder: ":path$filter"); | ||
|
||
$builder | ||
->andWhere("json_extract(object, :path$filter) = :value$filter"); | ||
} | ||
|
||
return $builder; | ||
} | ||
|
||
public function getAggregations(IQueryBuilder $builder, array $fields, int $register, int $schema, array $filters = []): array | ||
{ | ||
$facets = []; | ||
|
||
foreach($fields as $field) { | ||
$builder->createNamedParameter(value: "$.$field", placeHolder: ":$field"); | ||
|
||
|
||
$builder | ||
->selectAlias($builder->createFunction("json_unquote(json_extract(object, :$field))"), '_id') | ||
->selectAlias($builder->createFunction("count(*)"), 'count') | ||
->from('openregister_objects') | ||
->where( | ||
$builder->expr()->eq('register', $builder->createNamedParameter($register, IQueryBuilder::PARAM_INT)), | ||
$builder->expr()->eq('schema', $builder->createNamedParameter($schema, IQueryBuilder::PARAM_INT)), | ||
) | ||
->groupBy('_id'); | ||
|
||
$builder = $this->filterJson($builder, $filters); | ||
|
||
$result = $builder->executeQuery(); | ||
$facets[$field] = $result->fetchAll(); | ||
|
||
$builder->resetQueryParts(); | ||
$builder->setParameters([]); | ||
|
||
} | ||
return $facets; | ||
} | ||
} |
Oops, something went wrong.