aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Files/Cache/SearchBuilder.php19
-rw-r--r--lib/private/Files/Search/QueryOptimizer/SplitLargeIn.php3
-rw-r--r--lib/private/Files/Search/SearchComparison.php7
-rw-r--r--lib/public/Files/Search/ISearchComparison.php5
6 files changed, 25 insertions, 11 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 06977abf57f..c027075d160 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -1414,6 +1414,7 @@ return array(
'OC\\Files\\Search\\QueryOptimizer\\QueryOptimizer' => $baseDir . '/lib/private/Files/Search/QueryOptimizer/QueryOptimizer.php',
'OC\\Files\\Search\\QueryOptimizer\\QueryOptimizerStep' => $baseDir . '/lib/private/Files/Search/QueryOptimizer/QueryOptimizerStep.php',
'OC\\Files\\Search\\QueryOptimizer\\ReplacingOptimizerStep' => $baseDir . '/lib/private/Files/Search/QueryOptimizer/ReplacingOptimizerStep.php',
+ 'OC\\Files\\Search\\QueryOptimizer\\SplitLargeIn' => $baseDir . '/lib/private/Files/Search/QueryOptimizer/SplitLargeIn.php',
'OC\\Files\\Search\\SearchBinaryOperator' => $baseDir . '/lib/private/Files/Search/SearchBinaryOperator.php',
'OC\\Files\\Search\\SearchComparison' => $baseDir . '/lib/private/Files/Search/SearchComparison.php',
'OC\\Files\\Search\\SearchOrder' => $baseDir . '/lib/private/Files/Search/SearchOrder.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 9621351352d..238b667b5f4 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -1447,6 +1447,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Files\\Search\\QueryOptimizer\\QueryOptimizer' => __DIR__ . '/../../..' . '/lib/private/Files/Search/QueryOptimizer/QueryOptimizer.php',
'OC\\Files\\Search\\QueryOptimizer\\QueryOptimizerStep' => __DIR__ . '/../../..' . '/lib/private/Files/Search/QueryOptimizer/QueryOptimizerStep.php',
'OC\\Files\\Search\\QueryOptimizer\\ReplacingOptimizerStep' => __DIR__ . '/../../..' . '/lib/private/Files/Search/QueryOptimizer/ReplacingOptimizerStep.php',
+ 'OC\\Files\\Search\\QueryOptimizer\\SplitLargeIn' => __DIR__ . '/../../..' . '/lib/private/Files/Search/QueryOptimizer/SplitLargeIn.php',
'OC\\Files\\Search\\SearchBinaryOperator' => __DIR__ . '/../../..' . '/lib/private/Files/Search/SearchBinaryOperator.php',
'OC\\Files\\Search\\SearchComparison' => __DIR__ . '/../../..' . '/lib/private/Files/Search/SearchComparison.php',
'OC\\Files\\Search\\SearchOrder' => __DIR__ . '/../../..' . '/lib/private/Files/Search/SearchOrder.php',
diff --git a/lib/private/Files/Cache/SearchBuilder.php b/lib/private/Files/Cache/SearchBuilder.php
index fe021a62e9e..9d306db7748 100644
--- a/lib/private/Files/Cache/SearchBuilder.php
+++ b/lib/private/Files/Cache/SearchBuilder.php
@@ -37,8 +37,12 @@ use OCP\FilesMetadata\IMetadataQuery;
/**
* Tools for transforming search queries into database queries
+ *
+ * @psalm-import-type ParamSingleValue from ISearchComparison
+ * @psalm-import-type ParamValue from ISearchComparison
*/
class SearchBuilder {
+ /** @var array<string, string> */
protected static $searchOperatorMap = [
ISearchComparison::COMPARE_LIKE => 'iLike',
ISearchComparison::COMPARE_LIKE_CASE_SENSITIVE => 'like',
@@ -51,6 +55,7 @@ class SearchBuilder {
ISearchComparison::COMPARE_IN => 'in',
];
+ /** @var array<string, string> */
protected static $searchOperatorNegativeMap = [
ISearchComparison::COMPARE_LIKE => 'notLike',
ISearchComparison::COMPARE_LIKE_CASE_SENSITIVE => 'notLike',
@@ -63,6 +68,7 @@ class SearchBuilder {
ISearchComparison::COMPARE_IN => 'notIn',
];
+ /** @var array<string, string> */
protected static $fieldTypes = [
'mimetype' => 'string',
'mtime' => 'integer',
@@ -79,11 +85,14 @@ class SearchBuilder {
'owner' => 'string',
];
+ /** @var array<string, int> */
protected static $paramTypeMap = [
'string' => IQueryBuilder::PARAM_STR,
'integer' => IQueryBuilder::PARAM_INT,
'boolean' => IQueryBuilder::PARAM_BOOL,
];
+
+ /** @var array<string, int> */
protected static $paramArrayTypeMap = [
'string' => IQueryBuilder::PARAM_STR_ARRAY,
'integer' => IQueryBuilder::PARAM_INT_ARRAY,
@@ -186,7 +195,7 @@ class SearchBuilder {
/**
* @param ISearchComparison $operator
- * @return list{string, string|integer|\DateTime|(\DateTime|int|string)[], string, string}
+ * @return list{string, ParamValue, string, string}
*/
private function getOperatorFieldAndValue(ISearchComparison $operator): array {
$this->validateComparison($operator);
@@ -199,9 +208,9 @@ class SearchBuilder {
/**
* @param string $field
- * @param string|integer|\DateTime|(\DateTime|int|string)[] $value
+ * @param ParamValue $value
* @param string $type
- * @return list{string, string|integer|\DateTime|(\DateTime|int|string)[], string, string}
+ * @return list{string, ParamValue, string, string}
*/
private function getOperatorFieldAndValueInner(string $field, mixed $value, string $type, bool $pathEqHash): array {
$paramType = self::$fieldTypes[$field];
@@ -209,7 +218,7 @@ class SearchBuilder {
$resultField = $field;
$values = [];
foreach ($value as $arrayValue) {
- /** @var string|integer|\DateTime $arrayValue */
+ /** @var ParamSingleValue $arrayValue */
[$arrayField, $arrayValue] = $this->getOperatorFieldAndValueInner($field, $arrayValue, ISearchComparison::COMPARE_EQUAL, $pathEqHash);
$resultField = $arrayField;
$values[] = $arrayValue;
@@ -297,7 +306,7 @@ class SearchBuilder {
private function getExtraOperatorField(ISearchComparison $operator, IMetadataQuery $metadataQuery): array {
- $paramType = self::$fieldTypes[$field];
+ $paramType = self::$fieldTypes[$operator->getField()];
$field = $operator->getField();
$value = $operator->getValue();
$type = $operator->getType();
diff --git a/lib/private/Files/Search/QueryOptimizer/SplitLargeIn.php b/lib/private/Files/Search/QueryOptimizer/SplitLargeIn.php
index 450ffae42f1..6f85037b3e9 100644
--- a/lib/private/Files/Search/QueryOptimizer/SplitLargeIn.php
+++ b/lib/private/Files/Search/QueryOptimizer/SplitLargeIn.php
@@ -19,7 +19,7 @@ class SplitLargeIn extends ReplacingOptimizerStep {
count($operator->getValue()) > 1000
) {
$chunks = array_chunk($operator->getValue(), 1000);
- $chunkComparisons = array_map(function(array $values) use ($operator) {
+ $chunkComparisons = array_map(function (array $values) use ($operator) {
return new SearchComparison(ISearchComparison::COMPARE_IN, $operator->getField(), $values);
}, $chunks);
@@ -30,4 +30,3 @@ class SplitLargeIn extends ReplacingOptimizerStep {
return false;
}
}
-
diff --git a/lib/private/Files/Search/SearchComparison.php b/lib/private/Files/Search/SearchComparison.php
index 8ca05236105..b3c4832d776 100644
--- a/lib/private/Files/Search/SearchComparison.php
+++ b/lib/private/Files/Search/SearchComparison.php
@@ -27,12 +27,16 @@ namespace OC\Files\Search;
use OCP\Files\Search\ISearchComparison;
+/**
+ * @psalm-import-type ParamValue from ISearchComparison
+ */
class SearchComparison implements ISearchComparison {
private array $hints = [];
public function __construct(
private string $type,
private string $field,
+ /** @var ParamValue $value */
private \DateTime|int|string|bool|array $value,
private string $extra = ''
) {
@@ -52,9 +56,6 @@ class SearchComparison implements ISearchComparison {
return $this->field;
}
- /**
- * @return \DateTime|int|string|bool|(\DateTime|int|string)[]
- */
public function getValue(): string|int|bool|\DateTime|array {
return $this->value;
}
diff --git a/lib/public/Files/Search/ISearchComparison.php b/lib/public/Files/Search/ISearchComparison.php
index 65a245ead2e..a3842ffaec6 100644
--- a/lib/public/Files/Search/ISearchComparison.php
+++ b/lib/public/Files/Search/ISearchComparison.php
@@ -26,6 +26,9 @@ namespace OCP\Files\Search;
/**
* @since 12.0.0
+ *
+ * @psalm-type ParamSingleValue = \DateTime|int|string|bool
+ * @psalm-type ParamValue = ParamSingleValue|list<ParamSingleValue>
*/
interface ISearchComparison extends ISearchOperator {
/**
@@ -103,7 +106,7 @@ interface ISearchComparison extends ISearchOperator {
/**
* Get the value to compare the field with
*
- * @return string|integer|bool|\DateTime|(\DateTime|int|string)[]
+ * @return ParamValue
* @since 12.0.0
*/
public function getValue(): string|int|bool|\DateTime|array;