public static function search($term, $limit = 20, $offset = 0)
{
// revalidate searches
if (FrontendModel::get('fork.settings')->get('Search', 'validate_search', true) == true) {
self::validateSearch();
}
// @note: on heavy sites with a lot of inactive search indices better
// use a cronjob (which will automatically set this module setting to N)
// execute the actual search
$searchResults = self::execSearch($term, $limit, $offset);
// get the total amount of results (we'll get back to this later ;) )
$total = count($searchResults);
// none found? return empty :(
if (!$searchResults) {
return array();
}
// prepare to send to modules
$moduleResults = array();
// loop the result set
foreach ($searchResults as $searchResult) {
$moduleResults[$searchResult['module']][] = $searchResult['other_id'];
}
// pass the results to the modules
foreach ($moduleResults as $module => $otherIds) {
// check if this module actually is prepared to handle searches
$class = 'Frontend\\Modules\\' . $module . '\\Engine\\Model';
if (is_callable(array($class, 'search'))) {
// get the required info from our module
$moduleResults[$module] = call_user_func(array($class, 'search'), $otherIds);
} else {
// does not exist, let's get this module out of here
unset($moduleResults[$module]);
}
}
// now place the prepared data back in our original result set, which has our results in correct order
foreach ($searchResults as $i => $result) {
// loop parsed results for this specific module to find the one we want here
foreach ($moduleResults[$result['module']] as $otherId => $moduleResult) {
// that's the one..
if ($otherId == $result['other_id']) {
$searchResults[$i] = array_merge(array('module' => $result['module']), $moduleResult);
continue 2;
}
}
// if we made it here, we obviously did not get this result parsed by the module, so remove it!
unset($searchResults[$i]);
self::statusIndex($result['module'], (array) $result['other_id'], false);
}
// results got removed by the module? oh noes :o have another run,
// because now we've deactivated those responsible for the holes :)
if (count($searchResults) < $total && $total == $limit) {
$searchResults = self::search($term, $limit, $offset);
}
// return results
return $searchResults;
}