Skip to content
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

Expand on tag filters #803

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
13 changes: 12 additions & 1 deletion src/GraphQL/Query/QueryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,18 @@ public function buildDataObjectQueries(&$config = [], $context = []): void
'type' => Type::string(),
'description' => 'Comma separated list of fullpath'
],
'tags' => ['type' => Type::string(), 'description' => 'Comma separated list of tag names'],
'tags' => [
'type' => Type::string(),
'description' => 'Comma separated list of tag names (or idPath if useTagIdPath is true)'
],
'useTagIdPath' => [
'type' => Type::boolean(),
'description' => 'Use idPath instead of name for tags in the tags argument'
],
'hasAllTags' => [
'type' => Type::boolean(),
'description' => 'Results must match all tags in the tags argument'
],
'defaultLanguage' => ['type' => Type::string()],
'first' => ['type' => Type::int()],
'after' => ['type' => Type::int()],
Expand Down
15 changes: 13 additions & 2 deletions src/GraphQL/Resolver/QueryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,21 @@ static function ($fullpath) use ($db) {
return $db->quote($tag);
}, $args['tags'])));

$conditionParts[] = "o_id IN (
$field = "name";
if (isset($args['useTagIdPath']) && $args['useTagIdPath']) {
$field = "idPath";
}

$statement = "o_id IN (
abrenoch marked this conversation as resolved.
Show resolved Hide resolved
SELECT cId FROM tags_assignment INNER JOIN tags ON tags.id = tags_assignment.tagid
WHERE
ctype = 'object' AND LOWER(tags.name) IN (" . $tags . '))';
ctype = 'object' AND LOWER(tags." . $field . ") IN (" . $tags . ')';

if (isset($args['hasAllTags']) && $args['hasAllTags']) {
$statement .= " GROUP BY cId HAVING COUNT(DISTINCT tags." . $field . ") = " . count($args['tags']);
}

$conditionParts[] = $statement . ")";
}

// paging
Expand Down