diff --git a/config/data_index_filters.yaml b/config/data_index_filters.yaml index 6879e0e1..0294e7b1 100644 --- a/config/data_index_filters.yaml +++ b/config/data_index_filters.yaml @@ -47,6 +47,9 @@ services: Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\IntegerFilter: tags: [ 'pimcore.studio_backend.open_search.filter' ] + Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FullTextFilter: + tags: [ 'pimcore.studio_backend.open_search.filter' ] + # DataObject Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\ClassNameFilter: tags: [ 'pimcore.studio_backend.open_search.data_object.filter' ] diff --git a/doc/03_Grid.md b/doc/03_Grid.md index 7aa1d575..4d960856 100644 --- a/doc/03_Grid.md +++ b/doc/03_Grid.md @@ -45,6 +45,7 @@ Available filters are: | system.pql | string | PQL Query | false | | system.id | integer | | false | | system.integer | integer | | true | +| system.fulltext | string | | false | diff --git a/src/DataIndex/Filter/FullTextFilter.php b/src/DataIndex/Filter/FullTextFilter.php new file mode 100644 index 00000000..44ab6126 --- /dev/null +++ b/src/DataIndex/Filter/FullTextFilter.php @@ -0,0 +1,50 @@ +getSimpleColumnFilterByType(ColumnType::SYSTEM_FULLTEXT->value); + + if (!$filter) { + return $query; + } + + if (!is_string($filter->getFilterValue())) { + throw new InvalidArgumentException('Filter value for the fulltext filter must be a string'); + } + + $query->filterFullText($filter->getFilterValue()); + + return $query; + } +} diff --git a/src/DataIndex/Query/AssetQuery.php b/src/DataIndex/Query/AssetQuery.php index b969ef5c..145689c3 100644 --- a/src/DataIndex/Query/AssetQuery.php +++ b/src/DataIndex/Query/AssetQuery.php @@ -27,6 +27,7 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\PathFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\TagFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\FullTextSearch\ElementKeySearch; +use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\FullTextSearch\FullTextSearch; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\FullTextSearch\WildcardSearch; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\QueryLanguage\PqlFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\OrderByField; @@ -182,4 +183,11 @@ public function filterInteger(string $field, int $value): QueryInterface return $this; } + + public function filterFullText(string $value): QueryInterface + { + $this->search->addModifier(new FullTextSearch($value)); + + return $this; + } } diff --git a/src/DataIndex/Query/DataObjectQuery.php b/src/DataIndex/Query/DataObjectQuery.php index da05d229..cad9da7e 100644 --- a/src/DataIndex/Query/DataObjectQuery.php +++ b/src/DataIndex/Query/DataObjectQuery.php @@ -26,6 +26,7 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\PathFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\TagFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\FullTextSearch\ElementKeySearch; +use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\FullTextSearch\FullTextSearch; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\QueryLanguage\PqlFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByIndexField; @@ -161,4 +162,11 @@ public function filterInteger(string $field, int $value): QueryInterface return $this; } + + public function filterFullText(string $value): QueryInterface + { + $this->search->addModifier(new FullTextSearch($value)); + + return $this; + } } diff --git a/src/DataIndex/Query/DocumentQuery.php b/src/DataIndex/Query/DocumentQuery.php index 4fd4f85d..e6b1ffd6 100644 --- a/src/DataIndex/Query/DocumentQuery.php +++ b/src/DataIndex/Query/DocumentQuery.php @@ -26,6 +26,7 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\PathFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\TagFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\FullTextSearch\ElementKeySearch; +use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\FullTextSearch\FullTextSearch; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\FullTextSearch\WildcardSearch; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\QueryLanguage\PqlFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\OrderByField; @@ -161,4 +162,11 @@ public function filterInteger(string $field, int $value): QueryInterface return $this; } + + public function filterFullText(string $value): QueryInterface + { + $this->search->addModifier(new FullTextSearch($value)); + + return $this; + } } diff --git a/src/DataIndex/Query/QueryInterface.php b/src/DataIndex/Query/QueryInterface.php index 5a94aab5..18cfb720 100644 --- a/src/DataIndex/Query/QueryInterface.php +++ b/src/DataIndex/Query/QueryInterface.php @@ -49,4 +49,6 @@ public function filterByPql(string $pqlQuery): self; public function setUser(UserInterface $user): self; public function filterInteger(string $field, int $value): self; + + public function filterFullText(string $value): self; } diff --git a/src/Grid/Column/ColumnType.php b/src/Grid/Column/ColumnType.php index fec5ee0a..61dca753 100644 --- a/src/Grid/Column/ColumnType.php +++ b/src/Grid/Column/ColumnType.php @@ -28,6 +28,7 @@ enum ColumnType: string case SYSTEM_DATETIME = 'system.datetime'; case SYSTEM_TAG = 'system.tag'; case SYSTEM_PQL_QUERY = 'system.pql'; + case SYSTEM_FULLTEXT = 'system.fulltext'; case METADATA_SELECT = 'metadata.select'; case METADATA_INPUT = 'metadata.input'; case METADATA_DATE = 'metadata.date'; diff --git a/tests/Unit/DataIndex/Filter/FullTextFilterTest.php b/tests/Unit/DataIndex/Filter/FullTextFilterTest.php new file mode 100644 index 00000000..de03ae7e --- /dev/null +++ b/tests/Unit/DataIndex/Filter/FullTextFilterTest.php @@ -0,0 +1,66 @@ +makeEmpty(SimpleColumnFiltersParameterInterface::class, [ + 'getSimpleColumnFilterByType' => $columnFilter, + ]); + + $query = $this->makeEmpty(QueryInterface::class); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Filter value for the fulltext filter must be a string'); + + $filter = new FullTextFilter(); + $filter->apply($parameter, $query); + } + + public function testIfFilterFullTextIsCalled(): void + { + $columnFilter = new SimpleColumnFilter('system.fulltext', 'term'); + $parameter = $this->makeEmpty(SimpleColumnFiltersParameterInterface::class, [ + 'getSimpleColumnFilterByType' => $columnFilter, + ]); + + $query = $this->makeEmpty(QueryInterface::class, [ + 'filterFullText' => Expected::once(function ($term) { + $this->assertSame('term', $term); + + return $this->makeEmpty(QueryInterface::class); + }), + ]); + + $filter = new FullTextFilter(); + $filter->apply($parameter, $query); + } +}