[TASK] Allow multiple search words for file search 58/50458/2
authorMarkus Klein <markus.klein@typo3.org>
Mon, 31 Oct 2016 19:26:26 +0000 (20:26 +0100)
committerPhilipp Gampe <philipp.gampe@typo3.org>
Tue, 1 Nov 2016 11:50:11 +0000 (12:50 +0100)
The file search must consider each word of the search text as
individual word and all of them must be present in the file name.

Search words can be bound together by quoting them with
double quotes.

Resolves: #78519
Releases: master, 7.6
Change-Id: I95dcdf3418bfc9090a16c4f199af60799437390e
Reviewed-on: https://review.typo3.org/50458
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
typo3/sysext/core/Classes/Resource/Index/FileIndexRepository.php

index 3e654c3..f5cbe11 100644 (file)
@@ -268,12 +268,19 @@ class FileIndexRepository implements SingletonInterface
             );
 
         if (isset($fileName)) {
-            $queryBuilder->andWhere(
-                $queryBuilder->expr()->like(
-                    'name',
-                    $queryBuilder->createNamedParameter('%' . $queryBuilder->escapeLikeWildcards($fileName) . '%', \PDO::PARAM_STR)
-                )
-            );
+            $nameParts = str_getcsv($fileName, ' ');
+            foreach ($nameParts as $part) {
+                $part = trim($part);
+                if ($part !== '') {
+                    $queryBuilder->andWhere(
+                        $queryBuilder->expr()->like(
+                            'name',
+                            $queryBuilder->createNamedParameter('%' . $queryBuilder->escapeLikeWildcards($part) . '%',
+                                \PDO::PARAM_STR)
+                        )
+                    );
+                }
+            }
         }
 
         if (!$includeMissing) {