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
49 changes: 49 additions & 0 deletions src/Model/DefaultSearch/Query/BoolExistsQuery.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 BoolExistsQuery extends BoolQuery implements AsSubQueryInterface
{
public function __construct(
private readonly string $field
) {
parent::__construct([
ConditionType::FILTER->value => [
'bool' => [
'must_not' => [
'exists' => ['field' => $field],
],
],
],
]);
}

public function getField(): string
{
return $this->field;
}

public function toArrayAsSubQuery(): array
{
return [
'bool' => [
'must_not' => [
'exists' => ['field' => $this->field],
],
],
];
}
}
4 changes: 2 additions & 2 deletions src/Model/Search/Modifier/Filter/Basic/BooleanFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
public function __construct(
private string $fieldName,
private bool $searchTerm,
private null|bool $searchTerm,
private bool $enablePqlFieldNameResolution = true,
) {
}
Expand All @@ -29,7 +29,7 @@ public function getFieldName(): string
return $this->fieldName;
}

public function getSearchTerm(): bool
public function getSearchTerm(): null|bool
{
return $this->searchTerm;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Attribute\Search\AsSearchModifierHandler;
use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\FieldCategory\SystemField;
use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Modifier\SearchModifierContextInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Query\BoolExistsQuery;
use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Query\BoolQuery;
use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Query\TermFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\DefaultSearch\Query\TermsFilter;
Expand Down Expand Up @@ -77,11 +78,19 @@ public function handleBooleanFilter(BooleanFilter $booleanFilter, SearchModifier
);
}

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

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

$context->getSearch()->addQuery(
$query
);
}

Expand Down