From 9ac538f890a05819790c267ec4b2f8d4676f97f6 Mon Sep 17 00:00:00 2001 From: Tim59 Date: Mon, 8 Oct 2018 14:05:00 +0200 Subject: [PATCH 1/2] #601 - Add note for usage of multiple value search in Filters --- core/filters.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/filters.md b/core/filters.md index 50187cdbcb0..66008937405 100644 --- a/core/filters.md +++ b/core/filters.md @@ -136,6 +136,10 @@ Case insensitivity may already be enforced at the database level depending on th used. If you are using MySQL, note that the commonly used `utf8_unicode_ci` collation (and its sibling `utf8mb4_unicode_ci`) are already case insensitive, as indicated by the `_ci` part in their names. +Note : Search filters with the exact strategy can have multiple values for a same property (in this case the condition will be similar to a SQL IN clause) + +Syntax: `?property[]=foo&property[]=bar` + In the following example, we will see how to allow the filtering of a list of e-commerce offers: ```php @@ -160,6 +164,7 @@ class Offer `http://localhost:8000/api/offers?price=10` will return all offers with a price being exactly `10`. `http://localhost:8000/api/offers?name=shirt` will return all offers with a description containing the word "shirt". +`http://localhost:8000/api/offers?name[]=shirt&name[]=sweat` will return all offers with a description containing the word "shirt" or containing the word "sweat". Filters can be combined together: `http://localhost:8000/api/offers?price=10&name=shirt` @@ -680,7 +685,7 @@ final class RegexpFilter extends AbstractContextAwareFilter ) { return; } - + $parameterName = $queryNameGenerator->generateParameterName($property); // Generate a unique parameter name to avoid collisions with other filters $queryBuilder ->andWhere(sprintf('REGEXP(o.%s, :%s) = 1', $property, $parameterName)) @@ -1074,7 +1079,7 @@ class DummyCar * @ApiFilter(SearchFilter::class, properties={"colors.prop": "ipartial"}) */ private $colors; - + // ... } From 1ee690223fb3ff1a43686ce2cef649ad3d12c8de Mon Sep 17 00:00:00 2001 From: Tim59 Date: Mon, 8 Oct 2018 14:55:46 +0200 Subject: [PATCH 2/2] Typo fix on multiple search filter --- core/filters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/filters.md b/core/filters.md index 66008937405..e3e9ddeb224 100644 --- a/core/filters.md +++ b/core/filters.md @@ -136,7 +136,7 @@ Case insensitivity may already be enforced at the database level depending on th used. If you are using MySQL, note that the commonly used `utf8_unicode_ci` collation (and its sibling `utf8mb4_unicode_ci`) are already case insensitive, as indicated by the `_ci` part in their names. -Note : Search filters with the exact strategy can have multiple values for a same property (in this case the condition will be similar to a SQL IN clause) +Note: Search filters with the exact strategy can have multiple values for a same property (in this case the condition will be similar to a SQL IN clause). Syntax: `?property[]=foo&property[]=bar`