-
Notifications
You must be signed in to change notification settings - Fork 0
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 #3 from itk-dev/feature/418-filter-and-pagination
418: Added paginator to search results
- Loading branch information
Showing
14 changed files
with
292 additions
and
70 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
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,50 @@ | ||
<?php | ||
|
||
namespace App\Api\Filter; | ||
|
||
use ApiPlatform\Elasticsearch\Filter\AbstractFilter; | ||
use ApiPlatform\Metadata\Operation; | ||
use Symfony\Component\PropertyInfo\Type; | ||
|
||
/** | ||
* This class represents a filter that performs a search based on matching properties in a given resource. | ||
*/ | ||
final class MatchFilter extends AbstractFilter | ||
{ | ||
public function apply(array $clauseBody, string $resourceClass, Operation $operation = null, array $context = []): array | ||
{ | ||
$properties = $this->getProperties($resourceClass); | ||
$matches = []; | ||
|
||
/** @var string $property */ | ||
foreach ($properties as $property) { | ||
$matches[] = ['match' => [$property => $context['filters'][$property]]]; | ||
} | ||
|
||
return isset($matches[1]) ? ['bool' => ['should' => $matches]] : $matches[0]; | ||
} | ||
|
||
public function getDescription(string $resourceClass): array | ||
{ | ||
if (!$this->properties) { | ||
return []; | ||
} | ||
|
||
$description = []; | ||
foreach ($this->properties as $filterParameterName => $value) { | ||
$description[$filterParameterName] = [ | ||
'property' => $filterParameterName, | ||
'type' => Type::BUILTIN_TYPE_STRING, | ||
'required' => false, | ||
'description' => 'Search field based on value given', | ||
'openapi' => [ | ||
'allowReserved' => false, | ||
'allowEmptyValue' => true, | ||
'explode' => false, | ||
], | ||
]; | ||
} | ||
|
||
return $description; | ||
} | ||
} |
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
Oops, something went wrong.