aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Search/QueryOptimizer/FlattenSingleArgumentBinaryOperation.php
blob: cb04351534ab7106d0228daadd12df75b72c25b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
	}
}