Full-Text Search

Contrexx contains a Full-Text Search application that is used to look up content in the available applications by a certain keyword.
As of version 4, the following applications have been integrated into the Full-Text Search application:

Functionality

This shall be changed, by moving those code snippets to the related component's directory and then get them included using the Contrexx Event System. Study the documentation of the Contrexx Event System.
The component Search shall therefore register an Event (called SearchFindContent) to which each component then registers an EventListener through which the search operation shall get performed. The Search component has already been extended by registering the new Event SearchFindContent (do update to newest SVN revision) in method preContentLoad in its ComponentController. Additionally, the Search component has been extended to now use the Event System for fetching the search results of each component instead of doing it on its own in method \Cx\Core_Modules\Search\Controller\Search::getPage().

$this->cx->getEvents()->addEventListener('SearchFindContent', new \Cx\Core_Modules\News\Model\Event\NewsEventListener());

}</highlightsyntax>

When the EventSearchFindContent is triggered, the instance of Full-Text Search component (\Cx\Core_Modules\Search\Controller\Search) is passed as the second argument $eventArgs to the registered Event Listeners.

public static function performSearch($search)
{
$term_db = $search->getTerm();
$query = "SELECT id, text AS content, title, date, redirect,
MATCH (text,title,teaser_text) AGAINST ('%$term_db%') AS score
FROM ".DBPREFIX."module_news AS tblN
INNER JOIN ".DBPREFIX."module_news_locale AS tblL ON tblL.news_id = tblN.id
WHERE ( text LIKE ('%$term_db%')
OR title LIKE ('%$term_db%')
OR teaser_text LIKE ('%$term_db%'))
AND lang_id=".FRONTEND_LANG_ID."
AND status=1
AND is_active=1
AND (startdate<='".date('Y-m-d')."' OR startdate='0000-00-00')
AND (enddate>='".date('Y-m-d')."' OR enddate='0000-00-00')";

I suggest to extend this method to allow the argument $pagevar to be either a String (as of now) or an Anonymous Function (new).

If an Anonymous Function is passed as argument $pagevar, the anonymous function must accept the two arguments $pageUri and $searchData. An example (for component Calendar) of such an Anonymous Function follows :
<highlightsyntax>function($pageUri, $searchData) {

The other parts of the component specific operations are to manipulate the actual search data.
To move that code to each component's own Event Listener I suggest to extend the method getResultArray() by an additional argument $parseSearchData (default null). The argument $parseSearchData shall accept an Anonymous Functions to be called to process the search data.
Such an Anonymous Function must accept the argument $searchData. An usage example follows:
<highlightsyntax>$parseSearchData = function(&$searchData) {