aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Search/QueryOptimizer/FlattenSingleArgumentBinaryOperation.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files/Search/QueryOptimizer/FlattenSingleArgumentBinaryOperation.php')
-rw-r--r--lib/private/Files/Search/QueryOptimizer/FlattenSingleArgumentBinaryOperation.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/private/Files/Search/QueryOptimizer/FlattenSingleArgumentBinaryOperation.php b/lib/private/Files/Search/QueryOptimizer/FlattenSingleArgumentBinaryOperation.php
new file mode 100644
index 00000000000..7e99c04f197
--- /dev/null
+++ b/lib/private/Files/Search/QueryOptimizer/FlattenSingleArgumentBinaryOperation.php
@@ -0,0 +1,31 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OC\Files\Search\QueryOptimizer;
+
+use OCP\Files\Search\ISearchBinaryOperator;
+use OCP\Files\Search\ISearchOperator;
+
+/**
+ * replace single argument AND and OR operations with their single argument
+ */
+class FlattenSingleArgumentBinaryOperation extends ReplacingOptimizerStep {
+ public function processOperator(ISearchOperator &$operator): bool {
+ parent::processOperator($operator);
+ if (
+ $operator instanceof ISearchBinaryOperator
+ && count($operator->getArguments()) === 1
+ && (
+ $operator->getType() === ISearchBinaryOperator::OPERATOR_OR
+ || $operator->getType() === ISearchBinaryOperator::OPERATOR_AND
+ )
+ ) {
+ $operator = $operator->getArguments()[0];
+ return true;
+ }
+ return false;
+ }
+}