Permalink
Browse files

Better behaviour for "-" course searches under MSSQL and Oracle. MDL-…

…7312
  • Loading branch information...
1 parent 296f1fc commit abc597e27bccacfd9e97e660136aa5749b877188 stronk7 committed Jan 1, 2008
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/datalib.php
View
@@ -805,9 +805,15 @@ function get_courses_search($searchterms, $sort='fullname ASC', $page=0, $record
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->dbtype == 'oci8po' || $CFG->dbtype == 'mssql' || $CFG->dbtype == 'mssql_n' || $CFG->dbtype == 'odbc_mssql') {
+ if (substr($searchterm, 0, 1) == '-') {
+ $NOT = ' NOT ';
+ }
$searchterm = trim($searchterm, '+-');
}
@@ -827,13 +833,13 @@ function get_courses_search($searchterms, $sort='fullname ASC', $page=0, $record
$summarysearch .= " summary $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
$fullnamesearch .= " fullname $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
} else {
- $summarysearch .= ' summary '. $LIKE .'\'%'. $searchterm .'%\' ';
- $fullnamesearch .= ' fullname '. $LIKE .'\'%'. $searchterm .'%\' ';
+ $summarysearch .= ' summary '. $NOT . $LIKE .' \'%'. $searchterm .'%\' ';
+ $fullnamesearch .= ' fullname '. $NOT . $LIKE .' \'%'. $searchterm .'%\' ';
}
}
- $selectsql = $CFG->prefix .'course WHERE ('. $fullnamesearch .' OR '. $summarysearch .') AND category > \'0\'';
+ $selectsql = $CFG->prefix .'course WHERE (('. $fullnamesearch .') OR ('. $summarysearch .')) AND category > \'0\'';
$totalcount = count_records_sql('SELECT COUNT(*) FROM '. $selectsql);

0 comments on commit abc597e

Please sign in to comment.