[FEATURE] Add metadata to filebrowser search 91/56891/4
authorGuido Schmechel <guido.schmechel@brandung.de>
Tue, 8 May 2018 20:14:58 +0000 (22:14 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Thu, 10 May 2018 13:03:13 +0000 (15:03 +0200)
Now also searching for metadata in the filebrowser is possible.
The corresponding files are then listed.

Resolves: #71644
Releases: master
Change-Id: Ibea04dfb716496247ded3c22e9fd326cce5427d8
Reviewed-on: https://review.typo3.org/56891
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Elena Bartolotti <bartolotti.elena@gmail.com>
Tested-by: Elena Bartolotti <bartolotti.elena@gmail.com>
Tested-by: Cristian Buja <cristian.buja@intera.it>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Classes/Resource/FileRepository.php
typo3/sysext/core/Classes/Resource/Index/FileIndexRepository.php
typo3/sysext/core/Documentation/Changelog/master/Feature-71644-AddMetadataToFilebrowserSearch.rst [new file with mode: 0644]

index 695c7d5..bd5f70b 100644 (file)
@@ -177,6 +177,7 @@ class FileRepository extends AbstractRepository
         $folders[$folder->getIdentifier()] = $folder;
 
         $fileRecords = $this->getFileIndexRepository()->findByFolders($folders, false, $fileName);
+        $fileRecords = array_merge($fileRecords, $this->getFileIndexRepository()->findBySearchWordInMetaData($fileName));
 
         $files = [];
         foreach ($fileRecords as $fileRecord) {
index ae01e70..e67bbf9 100644 (file)
@@ -557,6 +557,69 @@ class FileIndexRepository implements SingletonInterface
         $refIndexObj->updateRefIndexTable($this->table, $id);
     }
 
+    /**
+     * Search for files by search word in metadata
+     *
+     * @param string $searchWord search word
+     *
+     * @return array
+     */
+    public function findBySearchWordInMetaData($searchWord)
+    {
+        $metaDataTableName = 'sys_file_metadata';
+        $sysFileTableName = 'sys_file';
+
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($metaDataTableName);
+        $queryBuilder
+            ->select($sysFileTableName . '.*')
+            ->from($metaDataTableName)
+            ->join(
+                $metaDataTableName,
+                $sysFileTableName,
+                $sysFileTableName,
+                $queryBuilder->expr()->eq($metaDataTableName . '.file', $queryBuilder->quoteIdentifier($sysFileTableName . '.uid'))
+            );
+
+        if (null !== $searchWord) {
+            $nameParts = str_getcsv($searchWord, ' ');
+            foreach ($nameParts as $part) {
+                $part = trim($part);
+                if ($part !== '') {
+                    $queryBuilder->orWhere(
+                        $queryBuilder->expr()->like(
+                            $metaDataTableName . '.title',
+                            $queryBuilder->createNamedParameter(
+                                '%' . $queryBuilder->escapeLikeWildcards($part) . '%',
+                                \PDO::PARAM_STR
+                            )
+                        ),
+                        $queryBuilder->expr()->like(
+                            $metaDataTableName . '.description',
+                            $queryBuilder->createNamedParameter(
+                                '%' . $queryBuilder->escapeLikeWildcards($part) . '%',
+                                \PDO::PARAM_STR
+                            )
+                        ),
+                        $queryBuilder->expr()->like(
+                            $metaDataTableName . '.alternative',
+                            $queryBuilder->createNamedParameter(
+                                '%' . $queryBuilder->escapeLikeWildcards($part) . '%',
+                                \PDO::PARAM_STR
+                            )
+                        )
+                    );
+                }
+            }
+        }
+        $result = $queryBuilder->execute();
+        $fileRecords = [];
+        while ($fileRecord = $result->fetch()) {
+            $fileRecords[$fileRecord['identifier']] = $fileRecord;
+        }
+
+        return $fileRecords;
+    }
+
     /*
      * Get the SignalSlot dispatcher
      *
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-71644-AddMetadataToFilebrowserSearch.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-71644-AddMetadataToFilebrowserSearch.rst
new file mode 100644 (file)
index 0000000..94af4f7
--- /dev/null
@@ -0,0 +1,20 @@
+.. include:: ../../Includes.txt
+
+====================================================
+Feature: #71644 - Add metadata to filebrowser search
+====================================================
+
+See :issue:`71644`
+
+Description
+===========
+
+Now also searching for sys_file_metadata in the filebrowser is possible. The fields title, description and alternative are searched.
+
+
+Impact
+======
+
+Files are displayed whose metadata match the search word.
+
+.. index:: Backend, ext:filelist
\ No newline at end of file