SearchFilter
Should be used to filter items by text fields. SearchFilter
supports 3 strategies:
exact
- Filters items which matches exactly search term (WHERE property = "value"
in MySQL language). This is strategy used by default if no other is configured.
use SourceBroker\T3api\Annotation as T3api;
use SourceBroker\T3api\Filter\SearchFilter;
/**
* @T3api\ApiResource (
* collectionOperations={
* "get"={
* "path"="/users",
* },
* },
* )
*
* @T3api\ApiFilter(
* SearchFilter::class,
* properties={"firstName", "middleName", "lastName"}
* )
*/
class User extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
{
}
Copied!
partial
- Filters items which matches partially search term (WHERE property LIKE "%value%"
in MySQL language).
use SourceBroker\T3api\Annotation as T3api;
use SourceBroker\T3api\Filter\SearchFilter;
/**
* @T3api\ApiResource (
* collectionOperations={
* "get"={
* "path"="/users",
* },
* },
* )
*
* @T3api\ApiFilter(
* SearchFilter::class,
* properties={
* "firstName": "partial",
* "middleName": "partial",
* "lastName": "partial",
* "address.street": "partial",
* },
* )
*/
class User extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
{
}
Copied!
matchAgainst
- Filters items which matches search term using full text search (MATCH(property) AGAINST ("value" IN NATURAL LANGUAGE MODE)
in MySQL language). In it possible to extend query withWITH QUERY EXPANSION
by addingwithQueryExpansion
in arguments (Read more about query expansion)
use SourceBroker\T3api\Annotation as T3api;
use SourceBroker\T3api\Filter\SearchFilter;
/**
* @T3api\ApiResource (
* collectionOperations={
* "get"={
* "path"="/users",
* },
* },
* )
*
* @T3api\ApiFilter(
* SearchFilter::class,
* properties={
* "firstName": "matchAgainst",
* "middleName": "matchAgainst",
* "lastName": "matchAgainst",
* "address.street": "matchAgainst",
* },
* arguments={
* "withQueryExpansion": true,
* },
* )
*/
class User extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
{
}
Copied!
Real examples. Run "ddev restart && ddev ci 13" and try those links below.
- Get list of news filtered by search word "minima" and sort by datetime.