public static function getTotal($term)
{
// advanced search
if (is_array($term)) {
// init vars
$where = array();
$join = array();
$params = array();
// loop all searches
foreach ($term as $field => $value) {
// get all terms to search for (including synonyms)
$terms = self::getSynonyms((string) $value);
// build search terms
$terms = self::buildTerm($terms);
$queryNr = count($where);
// add query
$where[$queryNr] = '(' . mb_substr(str_repeat('MATCH (i' . $queryNr . '.value) AGAINST (? IN BOOLEAN MODE) OR ', count($terms)), 0, -4) . ') AND i' . $queryNr . '.field = ? AND i' . $queryNr . '.language = ? AND i' . $queryNr . '.active = ? AND m' . $queryNr . '.searchable = ?';
$join[$queryNr] = 'search_index AS i' . $queryNr . ($join ? ' ON i' . $queryNr . '.module = i0.module AND i' . $queryNr . '.other_id = i0.other_id' : '') . ' INNER JOIN search_modules AS m' . $queryNr . ' ON m' . $queryNr . '.module = i' . $queryNr . '.module';
// add params
$params = array_merge($params, $terms, array((string) $field, LANGUAGE, 'Y', 'Y'));
}
// prepare query and params
$query = 'SELECT COUNT(module)
FROM
(
SELECT i0.module, i0.other_id
FROM ' . implode(' INNER JOIN ', $join) . '
WHERE ' . implode(' AND ', $where) . '
) AS results';
} else {
// simple search
// get all terms to search for (including synonyms)
$terms = self::getSynonyms((string) $term);
// build search terms
$terms = self::buildTerm($terms);
// prepare query and params
$query = 'SELECT COUNT(module)
FROM
(
SELECT i.module
FROM search_index AS i
INNER JOIN search_modules AS m ON i.module = m.module
WHERE (' . mb_substr(str_repeat('MATCH (i.value) AGAINST (? IN BOOLEAN MODE) OR ', count($terms)), 0, -4) . ') AND i.language = ? AND i.active = ? AND m.searchable = ?
GROUP BY i.module, i.other_id
) AS results';
$params = array_merge($terms, array(LANGUAGE, 'Y', 'Y'));
}
// get the search results
return (int) FrontendModel::getContainer()->get('database')->getVar($query, $params);
}