foreach ($searchterms as $searchterm) {
+ $NOT = ''; /// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
+ /// will use it to simulate the "-" operator with LIKE clause
+
/// Under Oracle and MSSQL, trim the + and - operators and perform
- /// simpler LIKE search
+ /// simpler LIKE (or NOT LIKE) queries
if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') {
+ if (substr($searchterm, 0, 1) == '-') {
+ $NOT = ' NOT ';
+ }
$searchterm = trim($searchterm, '+-');
}
$summarysearch .= " c.summary $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
$fullnamesearch .= " c.fullname $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
} else {
- $summarysearch .= ' c.summary '. $LIKE .' \'%'. $searchterm .'%\' ';
- $fullnamesearch .= ' c.fullname '. $LIKE .' \'%'. $searchterm .'%\' ';
+ $summarysearch .= ' summary '. $NOT . $LIKE .' \'%'. $searchterm .'%\' ';
+ $fullnamesearch .= ' fullname '. $NOT . $LIKE .' \'%'. $searchterm .'%\' ';
}
}
FROM {$CFG->prefix}course c
JOIN {$CFG->prefix}context ctx
ON (c.id = ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.")
- WHERE ( $fullnamesearch OR $summarysearch )
+ WHERE (( $fullnamesearch ) OR ( $summarysearch ))
AND category > 0
ORDER BY " . $sort;