aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Search/QueryOptimizer/FlattenNestedBool.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files/Search/QueryOptimizer/FlattenNestedBool.php')
-rw-r--r--lib/private/Files/Search/QueryOptimizer/FlattenNestedBool.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/private/Files/Search/QueryOptimizer/FlattenNestedBool.php b/lib/private/Files/Search/QueryOptimizer/FlattenNestedBool.php
new file mode 100644
index 00000000000..bb7bef2ed63
--- /dev/null
+++ b/lib/private/Files/Search/QueryOptimizer/FlattenNestedBool.php
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OC\Files\Search\QueryOptimizer;
+
+use OC\Files\Search\SearchBinaryOperator;
+use OCP\Files\Search\ISearchBinaryOperator;
+use OCP\Files\Search\ISearchOperator;
+
+class FlattenNestedBool extends QueryOptimizerStep {
+ public function processOperator(ISearchOperator &$operator) {
+ if (
+ $operator instanceof SearchBinaryOperator && (
+ $operator->getType() === ISearchBinaryOperator::OPERATOR_OR
+ || $operator->getType() === ISearchBinaryOperator::OPERATOR_AND
+ )
+ ) {
+ $newArguments = [];
+ foreach ($operator->getArguments() as $oldArgument) {
+ if ($oldArgument instanceof SearchBinaryOperator && $oldArgument->getType() === $operator->getType()) {
+ $newArguments = array_merge($newArguments, $oldArgument->getArguments());
+ } else {
+ $newArguments[] = $oldArgument;
+ }
+ }
+ $operator->setArguments($newArguments);
+ }
+ parent::processOperator($operator);
+ }
+}