-
-
Save h3nn3s/6df3d951dbed596d9fd1a1361700301e to your computer and use it in GitHub Desktop.
| <?php | |
| /** | |
| * Created by PhpStorm. | |
| * User: hziegenhain | |
| * Date: 27.12.2016 | |
| * Time: 14:42 | |
| */ | |
| use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; | |
| use TYPO3\CMS\Core\Utility\GeneralUtility; | |
| class user_kesearchhooks | |
| { | |
| /** | |
| * needed to get all recursive pids | |
| * | |
| * @var \TYPO3\CMS\Core\Database\QueryGenerator | |
| */ | |
| protected $queryGen; | |
| public function registerIndexerConfiguration(&$params, $pObj) { | |
| // add item to "type" field | |
| $newArray = array( | |
| 'My Custom Extension', | |
| 'customindexer', | |
| ExtensionManagementUtility::extRelPath('myext') . 'ext_icon.gif' | |
| ); | |
| $params['items'][] = $newArray; | |
| } | |
| /** | |
| * Custom indexer for ke_search | |
| * | |
| * @param array $indexerConfig Configuration from TYPO3 Backend | |
| * @param array $indexerObject Reference to indexer class. | |
| * @return string Output. | |
| * @author Henrik Ziegenhain <[email protected]> | |
| * @since Tue Dec 27 2016 14:42:00 GMT+0100 | |
| */ | |
| public function customIndexer(&$indexerConfig, &$indexerObject) { | |
| if ($indexerConfig['type'] === 'machinery') { | |
| $content = ''; | |
| // get all the entries to index | |
| // don't index hidden or deleted elements, BUT | |
| // get the elements with frontend user group access restrictions | |
| // or time (start / stop) restrictions. | |
| // Copy those restrictions to the index. | |
| $fields = '*'; | |
| $table = 'tx_machinery_domain_model_machinery'; | |
| // get the pages from where to index the records | |
| $indexPids = $this->getPidList($indexerConfig['startingpoints_recursive'], $indexerConfig['sysfolder']); | |
| $where = 'pid IN (' . implode(',', $indexPids) . ') AND hidden = 0 AND deleted = 0'; | |
| $groupBy = ''; | |
| $orderBy = ''; | |
| $limit = ''; | |
| $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, $groupBy, $orderBy, $limit); | |
| $resCount = $GLOBALS['TYPO3_DB']->sql_num_rows($res); | |
| // Loop through the records and write them to the index. | |
| if ($resCount) { | |
| while (($record = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) { | |
| // compile the information which should go into the index | |
| // the field names depend on the table you want to index! | |
| $title = strip_tags($record['name']); | |
| $abstract = ''; | |
| //$abstract = strip_tags($record['teaser']); | |
| $content = strip_tags($record['description']); | |
| $fullContent = $title . "\n" . $content; | |
| $params = '&tx_myext_pi1[record]=' . $record['uid'] . '&tx_myext_pi1[action]=show&tx_myext_pi1[controller]=Record'; | |
| $tags = '#customindexer#'; | |
| $additionalFields = array( | |
| 'sortdate' => $record['tstamp'], | |
| 'orig_uid' => $record['uid'], | |
| 'orig_pid' => $record['pid'], | |
| ); | |
| // add something to the title, just to identify the entries | |
| // in the frontend | |
| //$title = $title; | |
| // ... and store the information in the index | |
| $indexerObject->storeInIndex( | |
| $indexerConfig['storagepid'], // storage PID | |
| $title, // record title | |
| 'customindexer', // content type | |
| $indexerConfig['targetpid'], // target PID: where is the single view? | |
| $fullContent, // indexed content, includes the title (linebreak after title) | |
| $tags, // tags for faceted search | |
| $params, // typolink params for singleview | |
| $abstract, // abstract; shown in result list if not empty | |
| $record['sys_language_uid'], // language uid | |
| $record['starttime'], // starttime | |
| $record['endtime'], // endtime | |
| $record['fe_group'], // fe_group | |
| false, // debug only? | |
| $additionalFields // additionalFields | |
| ); | |
| } | |
| $content = '<p><b>Indexer "' . $indexerConfig['title'] . '":</b><br />' . $resCount . ' Elements have been indexed.</p>'; | |
| } | |
| return $content; | |
| } | |
| } | |
| public function getPidList($startingPointsRecursive = '', $singlePages = '') { | |
| $this->queryGen = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\QueryGenerator'); | |
| $pidsRecursive = GeneralUtility::trimExplode(',', $startingPointsRecursive, true); | |
| $pidsNonRecursive = GeneralUtility::trimExplode(',', $singlePages, true); | |
| $pageList = ''; | |
| foreach ($pidsRecursive as $pid) { | |
| $pageList .= $this->queryGen->getTreeList($pid, 99, 0, '1=1') . ','; | |
| } | |
| foreach ($pidsNonRecursive as $pid) { | |
| $pageList .= $pid . ','; | |
| } | |
| return GeneralUtility::trimExplode(',', $pageList, true); | |
| } | |
| } |
| <?php | |
| // enable "sysfolder" and "startingpoints_recursive" field | |
| $GLOBALS['TCA']['tx_kesearch_indexerconfig']['columns']['sysfolder']['displayCond'] .= ',customindexer'; | |
| $GLOBALS['TCA']['tx_kesearch_indexerconfig']['columns']['startingpoints_recursive']['displayCond'] .= ',customindexer'; |
Currently not working with ke_search in Version 9.
Please may have a look into official documentation here: https://docs.typo3.org/p/teaminmedias-pluswerk/ke_search/3.1/en-us/Indexing/IndexerTypes/Custom.html
or the examples extension here: https://github.com/teaminmedias-pluswerk/ke_search_hooks - it should be up to date I think
I did and it works. But there is a bug.
If your extension uses multiple pages ("sysfolder"), where records can be stored, only the first one will be taken into account:
teaminmedias-pluswerk/ke_search_hooks#12
It would be also nice to add "startingpoints_recursive", but I'd be happy if multiple single pages work (as it did in the earlier versions).
so please be so kind and report it to the maintainers of ke_search and ke_search_hooks ;-)
I think any help there is welcome.
Very cool.
Unfortunatley this doesn't work for TYPO3 Version 9. How could I adapt this accordingly?