mirror of
https://github.com/nextcloud/server.git
synced 2026-04-24 15:53:36 -04:00
fix types + autoloader
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
7ca516773f
commit
63ffaab95e
6 changed files with 25 additions and 11 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue