Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DefaultSearch\Search\Modifier\Filter\TreeFilters: ~
Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DefaultSearch\Search\Modifier\Filter\DependencyFilters: ~
Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DefaultSearch\Search\Modifier\Filter\FieldTypeFilters: ~
Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DefaultSearch\Search\Modifier\Filter\NestedTypeFilters: ~

Pimcore\Bundle\GenericDataIndexBundle\SearchIndexAdapter\DefaultSearch\Search\Modifier\FullTextSearch\FullTextSearchHandlers: ~

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $search->addModifier(new ParentIdFilter(1))
|--------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [IdFilter](https://github.com/pimcore/generic-data-index-bundle/blob/2.0/src/Model/Search/Modifier/Filter/Basic/IdFilter.php) | Basic filters | Filter by element ID |
| [IdsFilter](https://github.com/pimcore/generic-data-index-bundle/blob/2.0/src/Model/Search/Modifier/Filter/Basic/IdsFilter.php) | Basic filters | Filter by multiple element IDs |
| [BooleanFilter](https://github.com/pimcore/generic-data-index-bundle/blob/2.x/src/Model/Search/Modifier/Filter/Basic/BooleanFilter.php) | Basic filters | Filter boolean fields based on the value with [PQL field name resolution support](#pql-field-name-resolution) |
| [BooleanFilter](https://github.com/pimcore/generic-data-index-bundle/blob/2.x/src/Model/Search/Modifier/Filter/Basic/BooleanFilter.php) | Basic filters | Filter boolean fields based on the value with [PQL field name resolution support](#pql-field-name-resolution) |
| [IntegerFilter](https://github.com/pimcore/generic-data-index-bundle/blob/2.0/src/Model/Search/Modifier/Filter/Basic/IntegerFilter.php) | Basic filters | Filter integer fields based on the value with [PQL field name resolution support](#pql-field-name-resolution) |
| [ExcludeFoldersFilter](https://github.com/pimcore/generic-data-index-bundle/blob/2.0/src/Model/Search/Modifier/Filter/Basic/ExcludeFoldersFilter.php) | Basic filters | Exclude folders from search result |
| [ParentIdsFilter](https://github.com/pimcore/generic-data-index-bundle/blob/2.0/src/Model/Search/Modifier/Filter/Tree/ParentIdsFilter.php) | Tree related filters | Filter by parent ID |
Expand All @@ -28,8 +28,8 @@ $search->addModifier(new ParentIdFilter(1))
| [ElementWorkspacesQuery](https://github.com/pimcore/generic-data-index-bundle/blob/2.0/src/Model/Search/Modifier/Filter/Workspaces/WorkspaceQuery.php) | Workspace related filters | Filter based on the user workspaces and permissions respecting all element types (this query is added to the element search by default) |
| [MultiSelectFilter](https://github.com/pimcore/generic-data-index-bundle/blob/2.0/src/Model/Search/Modifier/Filter/FieldType/MultiSelectFilter.php) | Field type filters | Filter text fields by a list of exact strings. Supports [PQL field name resolution](#pql-field-name-resolution). |
| [DateFilter](https://github.com/pimcore/generic-data-index-bundle/blob/2.0/src/Model/Search/Modifier/Filter/FieldType/DateFilter.php) | Field type filters | Filter date fields based on an exact date or a range of dates. Supports [PQL field name resolution](#pql-field-name-resolution). |


| [ClassificationStoreFilter](https://github.com/pimcore/generic-data-index-bundle/blob/2.x/src/Model/Search/Modifier/Filter/FieldType/ClassificationStoreFilter.php) | Nested filters | Filter based on the classification store field values. Requires sub-modifier based on the filtered field type. Only fields types, which are supported by classificaiton store can be used for sub-modifier. |
| [NestedFilter](https://github.com/pimcore/generic-data-index-bundle/blob/2.x/src/Model/Search/Modifier/Filter/FieldType/NestedFilter.php) | Nested filters | Filter for nested fields. Requires sub-modifier based on the field type of nested field. |

### Full Text Search Queries

Expand Down
49 changes: 49 additions & 0 deletions src/Model/DefaultSearch/Query/NestedFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Query;

use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\DefaultSearch\ConditionType;

final class NestedFilter extends BoolQuery implements AsSubQueryInterface
{
public function __construct(
private readonly string $path,
private readonly array $subQuery,
) {
parent::__construct([
ConditionType::FILTER->value => [
'nested' => [
'path' => $this->path,
'query' => $this->subQuery,
],
],
]);
}

public function getPath(): string
{
return $this->path;
}

public function toArrayAsSubQuery(): array
{
return [
'nested' => [
'path' => $this->path,
'query' => $this->subQuery,
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\BooleanFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IntegerFilter;
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\SearchModifierInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\SearchIndexAdapter\MappingProperty;

final readonly class ClassificationStoreFilter implements SearchModifierInterface
{
public function __construct(
private string $fieldName,
private string $group,
private BooleanFilter|DateFilter|FullTextSearch|IntegerFilter|MultiSelectFilter|NumberRangeFilter|
WildcardSearch $subModifier,
private string $locale = MappingProperty::NOT_LOCALIZED_KEY,
) {
}

public function getFieldName(): string
{
return $this->fieldName;
}

public function getGroup(): string
{
return $this->group;
}

public function getSubModifier(): BooleanFilter|DateFilter|FullTextSearch|IntegerFilter|
MultiSelectFilter|NumberRangeFilter|WildcardSearch
{
return $this->subModifier;
}

public function getLocale(): string
{
return $this->locale;
}
}
35 changes: 35 additions & 0 deletions src/Model/Search/Modifier/Filter/FieldType/NestedFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\SearchModifierInterface;

final readonly class NestedFilter implements SearchModifierInterface
{
public function __construct(
private string $fieldName,
private SearchModifierInterface $subModifier
) {
}

public function getFieldName(): string
{
return $this->fieldName;
}

public function getSubModifier(): SearchModifierInterface
{
return $this->subModifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Query\BoolQuery;
use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Query\TermFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Query\TermsFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Interfaces\SearchInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\BooleanFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\ExcludeFoldersFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IdFilter;
Expand Down Expand Up @@ -51,46 +52,60 @@ public function handleIdFilter(IdFilter $idFilter, SearchModifierContextInterfac
#[AsSearchModifierHandler]
public function handleIntegerFilter(IntegerFilter $integerFilter, SearchModifierContextInterface $context): void
{
$context->getSearch()->addQuery(
$this->getIntegerQuery($integerFilter, null, $context->getOriginalSearch())
);
}

public function getIntegerQuery(
IntegerFilter $integerFilter,
?string $prefix = null,
?SearchInterface $search = null
): TermFilter {
$fieldName = $integerFilter->getFieldName();
if ($integerFilter->isPqlFieldNameResolutionEnabled()) {
$fieldName = $this->fieldNameTransformationService->transformFieldnameForSearch(
$context->getOriginalSearch(),
$fieldName
);
if ($prefix) {
$fieldName = $prefix . '.' . $fieldName;
}
if ($search && $integerFilter->isPqlFieldNameResolutionEnabled()) {
$fieldName = $this->fieldNameTransformationService->transformFieldnameForSearch($search, $fieldName);
}

$context->getSearch()->addQuery(
new TermFilter(
field: $fieldName,
term: $integerFilter->getSearchTerm(),
)
return new TermFilter(
field: $fieldName,
term: $integerFilter->getSearchTerm(),
);
}

#[AsSearchModifierHandler]
public function handleBooleanFilter(BooleanFilter $booleanFilter, SearchModifierContextInterface $context): void
{
$context->getSearch()->addQuery(
$this->getBooleanQuery($booleanFilter, null, $context->getOriginalSearch())
);
}

public function getBooleanQuery(
BooleanFilter $booleanFilter,
?string $prefix = null,
?SearchInterface $search = null
): BoolExistsQuery|TermFilter {
$fieldName = $booleanFilter->getFieldName();
if ($booleanFilter->isPqlFieldNameResolutionEnabled()) {
$fieldName = $this->fieldNameTransformationService->transformFieldnameForSearch(
$context->getOriginalSearch(),
$fieldName
);
if ($prefix) {
$fieldName = $prefix . '.' . $fieldName;
}
if ($search && $booleanFilter->isPqlFieldNameResolutionEnabled()) {
$fieldName = $this->fieldNameTransformationService->transformFieldnameForSearch($search, $fieldName);
}

$query = new BoolExistsQuery(
field: $fieldName,
);

if ($booleanFilter->getSearchTerm() !== null) {
$query = new TermFilter(
return new TermFilter(
field: $fieldName,
term: $booleanFilter->getSearchTerm(),
);
}

$context->getSearch()->addQuery(
$query
return new BoolExistsQuery(
field: $fieldName,
);
}

Expand Down
Loading