Skip to content

Commit

Permalink
DOC Document changes from silverstripe/silverstripe-framework#10925 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Aug 29, 2023
1 parent 5b9afdd commit b45605e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion en/02_Developer_Guides/00_Model/02_Relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ Eager loading is only intended to be used in read-only scenarios such as when ou

Note that filtering or sorting an `EagerLoadedList` will be done in PHP rather than as part of the database query, since we have already loaded all its relevant data into memory.

Note also that `EagerLoadedList` can't currently filter or sort by fields on relations using dot syntax (e.g. `sort('MySubRelation.Title')` won't work), nor filter using [`SearchFilter` syntax](/developer_guides/model/searchfilters/) (e.g. `filter('Title:StartsWith', 'Prefix')`).
Note also that `EagerLoadedList` can't currently filter or sort by fields on relations using dot syntax (e.g. `sort('MySubRelation.Title')` won't work).
[/notice]

## Cascading deletions
Expand Down
25 changes: 20 additions & 5 deletions en/02_Developer_Guides/00_Model/06_SearchFilters.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ icon: search

# SearchFilter Modifiers

The [`filter()`](api:SilverStripe\ORM\DataList::filter()) and [`exclude()`](api:SilverStripe\ORM\DataList::exclude()) methods on `DataList` specify exact matches by default. However, when filtering a `DataList`, there are a number of suffixes that
The `filter()`, `exclude()`, and other related methods on [`DataList`](api:SilverStripe\ORM\DataList), [`ArrayList`](api:SilverStripe\ORM\ArrayList), and [`EagerLoadedList`](api:SilverStripe\ORM\EagerLoadedList) specify exact matches by default. However, when calling these methods, 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)
Expand Down Expand Up @@ -37,17 +37,32 @@ $players = Player::get()->filterAny([
```

[hint]
Notice the syntax - to invoke a `SearchFilter` in a `DataList`'s `filter()`/`filterAny()`/`filterByCallback()` or `exclude()`/`excludeAny()` methods, you add a colon after the field name, followed by the name of the filter (excluding the actual word "filter"). e.g. for a `StartsWithFilter`: `'FieldName:StartsWith'`
Notice the syntax - to invoke a `SearchFilter` in the `filter()`/`filterAny()`/`find()` or `exclude()`/`excludeAny()` methods, you add a colon after the field name, followed by the name of the filter (excluding the actual word "filter"). e.g. for a `StartsWithFilter`: `'FieldName:StartsWith'`
[hint]

Developers can define their own [SearchFilter](api:SilverStripe\ORM\Filters\SearchFilter) if needing to extend the ORM filter and exclude behaviors.

## Modifiers

`SearchFilter`s can also take modifiers. The modifiers currently supported are `":not"`, `":nocase"`, and
`":case"` (though you can implement custom modifiers on your own `SearchFilter` implementations). These negate the filter, make it case-insensitive and make it case-sensitive, respectively. The default
comparison uses the database's default. For MySQL and MSSQL, this is case-insensitive. For PostgreSQL, this is
case-sensitive.
`":case"` (though you can implement custom modifiers on your own `SearchFilter` implementations). These negate the filter, make it case-insensitive and make it case-sensitive, respectively.

[info]
The default comparison uses the database's default case sensitivity. For MySQL and MSSQL, this is case-insensitive. For PostgreSQL, this is case-sensitive. But you can declare the default
case sensitivity for your project by setting the `default_case_sensitive` configuration property on `SearchFilter` like so:

```yml
SilverStripe\ORM\Filters\SearchFilter:
default_case_sensitive: false
```
Though note that for backwards compatibility reasons, `ArrayList` is explicitly case sensitive by default. To change that, you must set `ArrayList.default_case_sensitive` to false.

```yml
SilverStripe\ORM\ArrayList:
default_case_sensitive: false
```
[/info]

```php
// Fetch players that their FirstName is exactly 'Sam'
Expand Down
8 changes: 8 additions & 0 deletions en/04_Changelogs/5.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ title: 5.1.0 (unreleased)
- [Security considerations](#security-considerations)
- [Features and enhancements](#features-and-enhancements)
- [Eager loading](#eager-loading)
- [ArrayList improvements](#arraylist-improvements)
- [Improvement to page search performance with Elemental](#cms-search-performance)
- [New `InheritedPermissions` option - only these members](#only-these-members)
- [Optimised queries when filtering against IDs](#filter-by-ids)
Expand Down Expand Up @@ -67,6 +68,12 @@ foreach ($teams as $team) {

Read more about [eager loading](/developer_guides/model/relations/#eager-loading) including its limitations in the developer docs.

### ArrayList improvements

- You can now use [`SearchFilter` syntax](/developer_guides/model/searchfilters/) when calling any of the filter or exclude methods on [`ArrayList`](api:SilverStripe\ORM\ArrayList).
- For backwards compatibility, `ArrayList` filters are explicitly case sensitive by default. This differs from `DataList` which uses the database configuration to determine its default case sensitivity. See [search filter modifiers](/developer_guides/model/searchfilters/#modifiers) for more details including how to configure this for your project.
- [`ArrayList`](api:SilverStripe\ORM\ArrayList) now has an [`excludeAny()`](api:SilverStripe\ORM\ArrayList::excludeAny()) method, which mirrors the [`DataList::excludeAny()`](api:SilverStripe\ORM\DataList::excludeAny()) method.

### Improvement to page search performance with Elemental {#cms-search-performance}

- The CMS search has been optimised to reduce the number of database queries made when searching for pages with elemental content blocks. This has resulted in a small performance improvement. In our test environment, with 1,000 pages each with 5 content blocks we observed a 9% performance improvement. Performance will vary with your environment.
Expand Down Expand Up @@ -136,6 +143,7 @@ SilverStripe\SessionManager\Models\LoginSession:

- [`BuildTask`](api:SilverStripe\Dev\BuildTask) now has boolean `is_enabled` configuration option which has precedence over the existing `BuildTask::enabled` protected class property. The `BuildTask::enabled` property has been marked as deprecated and will be removed in CMS 6 if favour of using `is_enabled` instead.
- Passing an argument for `$limit` that is not `array|string|null` in [`SilverStripe\ORM\Search\SearchContext::getQuery()`](api:SilverStripe\ORM\Search\SearchContext::getQuery()) will throw a deprecation warning. In CMS 6 the parameter type will be changed from dynamic to `array|string|null`.
- You can now declare the default case sensitivity used by `SearchFilter` implementations, which power the `DataList` filtering functionality. See [search filter modifiers](/developer_guides/model/searchfilters/#modifiers) for more details.

### silverstripe/elemental-fileblock

Expand Down

0 comments on commit b45605e

Please sign in to comment.