Maybe not exact answer but it works.
Case though XML
There is an answer in magento2/module-cms
.
Basically, there is responsible configuration for that:
<virtualType name="CmsGirdFilterPool" type="Magento\Framework\View\Element\UiComponent\DataProvider\FilterPool">
<arguments>
<argument name="appliers" xsi:type="array">
<item name="regular" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter</item>
<item name="fulltext" xsi:type="object">Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilter</item>
</argument>
</arguments>
</virtualType>
I didn't find a usage of CmsGirdFilterPool
but you may try to use this example of Adminhtml Grid implementation.
Case thought PHP code
Also, I found out a simple non-XML way to use "fulltext" filter by customizing method \Magento\Ui\DataProvider\AbstractDataProvider::addFilter()
.
namespace Vendor\ModuleName\Ui\Component;
use Magento\Framework\Api\Filter;
use Magento\Framework\View\Element\UiComponent\DataProvider\FilterApplierInterface;
use Magento\Framework\View\Element\UiComponent\DataProvider\FulltextFilterFactory;
use Magento\Ui\DataProvider\AbstractDataProvider;
/**
* Class GridDataProvider
*/
class GridDataProvider extends AbstractDataProvider
{
/**
* Fulltext filter
*
* @var FilterApplierInterface
*/
protected $fulltextFilter;
/**
* Construct
*
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
* @param object $collectionFactory
* @param FulltextFilterFactory $fulltextFilter
* @param array $meta
* @param array $data
*/
public function __construct(
$name,
$primaryFieldName,
$requestFieldName,
$collectionFactory,
FulltextFilterFactory $fulltextFilter,
array $meta = [],
array $data = []
) {
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->collection = $collectionFactory->create();
$this->fulltextFilter = $fulltextFilter->create();
}
/**
* Add processing fulltext query
*
* Some workaround for fulltext search.
*
* @param Filter $filter
* @return void
*/
public function addFilter(Filter $filter)
{
if ('fulltext' == $filter->getField()) {
$this->fulltextFilter->apply($this->collection, $filter);
} else {
parent::addFilter($filter);
}
}
/**
* Get data
*
* @return array
*/
public function getData()
{
$searchKey = $this->_request->getParam('search');
if($searchKey) {
return $this->getCollection()
->addFieldToFilter(['filed-1',
'filed-2',
'filed-3'],OR More,
[['eq'=>$searchKey],
['like'=> '%'.$searchKey.'%'],
['like'=> '%'.$searchKey.'%'],
OR More values])
->load()->toArray();
} else {
return $this->getCollection()
->load()->toArray();
}
}
}