Skip to content

Commit

Permalink
#9706: Updated doc for case-sensitive filter (#9710)
Browse files Browse the repository at this point in the history
* #9706: Updated doc for case-sensitive filter

* #9706: Updated doc for case-sensitive filter

Co-authored-by: Dylan Grech <dylangrech@innovativecodes.com>
  • Loading branch information
dylangrech92 and Dylan Grech committed Sep 25, 2020
1 parent 9753d83 commit effe5c2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/en/02_Developer_Guides/00_Model/06_SearchFilters.md
Expand Up @@ -9,6 +9,7 @@ icon: search
The `filter` and `exclude` operations specify exact matches by default. However, when filtering `DataList`s, there are a number of suffixes that
you can put on field names to change this behavior. These are represented as `SearchFilter` subclasses and include.

* [ExactMatchFilter](api:SilverStripe\ORM\Filters\ExactMatchFilter)
* [StartsWithFilter](api:SilverStripe\ORM\Filters\StartsWithFilter)
* [EndsWithFilter](api:SilverStripe\ORM\Filters\EndsWithFilter)
* [PartialMatchFilter](api:SilverStripe\ORM\Filters\PartialMatchFilter)
Expand Down Expand Up @@ -40,6 +41,31 @@ These suffixes can also take modifiers themselves. The modifiers currently suppo
comparison uses the database's default. For MySQL and MSSQL, this is case-insensitive. For PostgreSQL, this is
case-sensitive.

```php
// Fetch players that their FirstName is 'Sam'
// Caution: This might be case in-sensitive if MySQL or MSSQL is used
$players = Player::get()->filter([
'FirstName:ExactMatch' => 'Sam'
]);

// Fetch players that their FirstName is 'Sam' (force case-sensitive)
$players = Player::get()->filter([
'FirstName:ExactMatch:case' => 'Sam'
]);

// Fetch players that their FirstName is 'Sam' (force NOT case-sensitive)
$players = Player::get()->filter([
'FirstName:ExactMatch:nocase' => 'Sam'
]);
```

By default the `:ExactMatch` filter is applied, hence why we can shorthand the above to:
```php
$players = Player::get()->filter('FirstName', 'Sam'); // Default DB engine behaviour
$players = Player::get()->filter('FirstName:case', 'Sam'); // case-sensitive
$players = Player::get()->filter('FirstName:nocase', 'Sam'); // NOT case-sensitive
```

Note that all search filters (e.g. `:PartialMatch`) refer to services registered with [Injector](api:SilverStripe\Core\Injector\Injector)
within the `DataListFilter.` prefixed namespace. New filters can be registered using the below yml
config:
Expand Down

0 comments on commit effe5c2

Please sign in to comment.