Skip to content

Instantly share code, notes, and snippets.

@nickdunn
Created March 21, 2011 14:21
Show Gist options
  • Save nickdunn/879512 to your computer and use it in GitHub Desktop.
Save nickdunn/879512 to your computer and use it in GitHub Desktop.
<?
$like = '';
$keywords = urldecode($keywords);
$keywords = preg_replace("/[^a-zA-Z0-9\s]/", '', $keywords);
$words = explode(' ', $keywords);
foreach($words as $word) {
$word = trim($word);
$like .= 'index.data REGEXP "[[:<:]]'.Symphony::Database()->cleanValue($word).'[[:>:]]" AND ';
}
$like = trim($like, ' AND ');
$sql = sprintf(
"SELECT
SQL_CALC_FOUND_ROWS
e.id as `entry_id`,
e.section_id as `section_id`,
UNIX_TIMESTAMP(e.creation_date) AS `creation_date`
FROM
sym_search_index as `index`
JOIN sym_entries as `e` ON (index.entry_id = e.id)
WHERE
%1\$s
AND e.section_id IN ('%2\$s')
ORDER BY
e.creation_date DESC
LIMIT %4\$d, %5\$d",
$like,
// list of section IDs
implode("','", array_keys($sections)),
// order by
Symphony::Database()->cleanValue($order_by),
// limit start
max(0, ($this->dsParamSTARTPAGE - 1) * $this->dsParamLIMIT),
// limit
(int)$this->dsParamLIMIT
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment