teaminmedias-pluswerk / ke_search

Search Extension for TYPO3 Content Management System, including faceting search functions.
https://extensions.typo3.org/extension/ke_search/
GNU General Public License v3.0
35 stars 62 forks source link

Add file size to indexed files #408

Closed ste101 closed 3 years ago

ste101 commented 3 years ago

I could do this. I think we need an additional field in tx_kesearch_index. Any thoughts?

christianbltr commented 3 years ago

What's the use case for this? Do you want to display the file size in the search result list? Then I would prefer to fetch the file size when rendering the result list (same as with the images) in order to keep the index table small.

ste101 commented 3 years ago

Yes this would be the case. I understand that you want to keep the index table slim but does fetching the size for every file not slow down the rendering? I don't know an easy way to do this. Do you know a way?

christianbltr commented 3 years ago

The filesize is already stored in sys_file and would be fetched only for the results currently displayed (usually 10 records at a time). So this should not cause any performance issues.

Without touching the ke_search code you could use the hook "additionalResultMarker". In the resultrow you have the "url" which you could use to resolve the sys_file record.

I think it would also be nice to add the sys_file record directly to the resultrow if the result is a file. I would propose to do this in the same way the "orig_row" is added to the result row (see https://github.com/teaminmedias-pluswerk/ke_search/blob/00d7085be5cd286a631010ae58dc6b34d28156ba/Classes/Lib/Pluginbase.php#L679). If you want, feel free to create a pull request for this feature.

ste101 commented 3 years ago

If you want, feel free to create a pull request for this feature.

Du bist so gut zu mir 😉

I found a way in Classes/Domain/Repository/GenericRepositroy.php line 53 but I'm not shure if this has side effects. For PDFs the type is 'file:pdf'.

--- GenericRepository.php.orig  2021-03-05 11:01:04.000000000 +0100
+++ GenericRepository.php   2021-03-28 01:45:11.000000000 +0100
@@ -50,13 +50,17 @@

         $row = false;
         $tableName = '';
-        switch ($type) {
+        $type = explode(':', $type);
+        switch ($type[0]) {
             case 'page':
                 $tableName = 'pages';
                 break;
             case 'news':
                 $tableName = 'tx_news_domain_model_news';
                 break;
+            case 'file':
+                $tableName = 'sys_file';
+                break;
             default:
                 // check if a table exists that matches the type name
                 $tableNameToCheck = strip_tags(htmlentities($type));
christianbltr commented 3 years ago

Du bist so gut zu mir

:wink:

Yes, I think this is a good solution. I made a slight change, because "type" should stay of type string, not array (it is used as a string in the default part of the switch condition).

Filesizes can now be shown in the ResultRow.html partial like this:

    <f:if condition="{resultrow.orig_row.size}"><br />{resultrow.orig_row.size -> f:format.bytes()}</f:if>

This only works if the file indexer is set to "Use FAL". Otherwise the orig_row will be false.