|
39 | 39 | use OCP\Files\Folder; |
40 | 40 | use OCP\Files\IRootFolder; |
41 | 41 | use OCP\Files\Node; |
| 42 | +use OCP\Files\Search\ISearchComparison; |
42 | 43 | use OCP\Files\Search\ISearchOperator; |
43 | 44 | use OCP\Files\Search\ISearchOrder; |
44 | 45 | use OCP\Files\Search\ISearchQuery; |
@@ -367,22 +368,30 @@ private function transformSearchOperation(Operator $operator) { |
367 | 368 | if (count($operator->arguments) !== 2) { |
368 | 369 | throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation'); |
369 | 370 | } |
370 | | - if (!($operator->arguments[0] instanceof SearchPropertyDefinition)) { |
371 | | - throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property'); |
372 | | - } |
373 | 371 | if (!($operator->arguments[1] instanceof Literal)) { |
374 | 372 | throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal'); |
375 | 373 | } |
376 | | - |
| 374 | + $value = $operator->arguments[1]->value; |
| 375 | + case Operator::OPERATION_IS_DEFINED: |
| 376 | + if (!($operator->arguments[0] instanceof SearchPropertyDefinition)) { |
| 377 | + throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property'); |
| 378 | + } |
377 | 379 | $property = $operator->arguments[0]; |
378 | | - $value = $this->castValue($property, $operator->arguments[1]->value); |
| 380 | + |
379 | 381 | if (str_starts_with($property->name, FilesPlugin::FILE_METADATA_PREFIX)) { |
380 | | - return new SearchComparison($trimmedType, substr($property->name, strlen(FilesPlugin::FILE_METADATA_PREFIX)), $value, IMetadataQuery::EXTRA); |
| 382 | + $field = substr($property->name, strlen(FilesPlugin::FILE_METADATA_PREFIX)); |
| 383 | + $extra = IMetadataQuery::EXTRA; |
381 | 384 | } else { |
382 | | - return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($property), $value); |
| 385 | + $field = $this->mapPropertyNameToColumn($property); |
383 | 386 | } |
384 | 387 |
|
385 | | - // no break |
| 388 | + return new SearchComparison( |
| 389 | + ISearchComparison::COMPARE_DEFINED, |
| 390 | + $field, |
| 391 | + $this->castValue($property, $value ?? ''), |
| 392 | + $extra ?? '' |
| 393 | + ); |
| 394 | + |
386 | 395 | case Operator::OPERATION_IS_COLLECTION: |
387 | 396 | return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE); |
388 | 397 | default: |
@@ -416,7 +425,11 @@ private function mapPropertyNameToColumn(SearchPropertyDefinition $property) { |
416 | 425 | } |
417 | 426 |
|
418 | 427 | private function castValue(SearchPropertyDefinition $property, $value) { |
419 | | - switch ($property->dataType) { |
| 428 | + if ($value === '') { |
| 429 | + return ''; |
| 430 | + } |
| 431 | + |
| 432 | + switch ($property->dataType) { |
420 | 433 | case SearchPropertyDefinition::DATATYPE_BOOLEAN: |
421 | 434 | return $value === 'yes'; |
422 | 435 | case SearchPropertyDefinition::DATATYPE_DECIMAL: |
|
0 commit comments