aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files')
-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
3 files changed, 19 insertions, 10 deletions
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;
}