-
Notifications
You must be signed in to change notification settings - Fork 54
ke_search integration
Fabian Auer edited this page Aug 21, 2014
·
1 revision
here is a simple ke_search indexer:
<?php
class mmforumext_kesearchhooks {
var $startMicrotime = 0;
`function registerIndexerConfiguration(&$params, $pObj) {`
`// add item to "type" field`
`$newArray = array(`
`'Forum indexer',`
`'curo_forum',`
`t3lib_extMgm::extRelPath('mm_forum') . 'ext_icon.gif'`
`);`
`$params['items'][] = $newArray;`
`// enable "sysfolder" field`
`$GLOBALS['TCA']['tx_kesearch_indexerconfig']['columns']['sysfolder']['displayCond'] .= ',curo_forum';`
`}`
/**
* Custom indexer for ke_search
*
* @param array $indexerConfig Configuration from TYPO3 Backend
* @param array $indexerObject Reference to indexer class.
* @return string Output.
* @author Fabian Auer <[email protected]>
* @since Fri June 27 2014 13:01:51 GMT+0100
*/
public function customIndexer(&$indexerConfig, &$indexerObject) {
$this->startMicrotime = microtime(true);
if($indexerConfig['type'] == 'curo_forum') {
$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 = 'post.*, topic.subject, topic.forum , GROUP_CONCAT( post.text SEPARATOR " ") ';`
`$table = 'tx_mmforum_domain_model_forum_post post, tx_mmforum_domain_model_forum_topic topic';`
`$where = 'post.pid IN (' . $indexerConfig['sysfolder'] . ') AND post.topic = topic.uid AND post.hidden = 0 AND post.deleted = 0 AND topic.hidden = 0 AND topic.deleted = 0';`
`$groupBy = 'topic.uid';`
`$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)) ) {`
`# print_r($record);`
`// compile the information which should go into the index`
`// the field names depend on the table you want to index!`
`$title = strip_tags($record['subject']); //Categorie Title`
`$abstract = strip_tags($record['text']);`
`$content = strip_tags($record['GROUP_CONCAT( post.text SEPARATOR " ")']);`
`#print $content;`
`#print $record['text'];`
`$fullContent = $title . "\n" . $content; `
`#$fullContent = $content; `
`$params = '&tx_mmforum_pi1[forum]='. $record['forum'].'&tx_mmforum_pi1[topic]='. $record['topic'].'&tx_mmforum_pi1[action]=show&tx_mmforum_pi1[controller]=Topic#post'.$record['uid'];`
`$additionalFields = array(`
`'sortdate' => $record['crdate'],`
`'orig_uid' => $record['uid'],`
`'orig_pid' => $record['pid'],`
`'sortdate' => $record['datetime'],`
`);`
`// add something to the title, just to identify the entries`
`// in the frontend`
`// ... and store the information in the index`
`$indexerObject->storeInIndex(`
`$indexerConfig['storagepid'], // storage PID`
`$title, // record title`
`'curo_forum', // 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 . ' Forum Elements have been indexed.</p>';`
`$content .= $this->showTime();`
`}`
`return $content;`
`}`
`}`
`/**`
`* shows time used`
`*`
`* @author Christian Buelter <[email protected]>`
`* @return string`
`*/`
`public function showTime() {`
`// calculate duration of indexing process`
`$endMicrotime = microtime(true);`
`$duration = ceil(($endMicrotime - $this->startMicrotime) * 1000);`
`// show sec or ms?`
`if ($duration > 10000) {`
`$duration /= 1000;`
`$duration = intval($duration);`
`return '<p><i>Indexing process for "Forum" took '.$duration.' s.</i> </p>'."\n\n";`
`} else {`
`return '<p><i>Indexing process for "Forum" took '.$duration.' ms.</i> </p>'."\n\n";`
`}`
`}`
}
?>