Merge pull request #19971 from atm-quentin/NEW_exclude_natural_search

NEW Can use ! to make a search that exclude a string
This commit is contained in:
Laurent Destailleur 2022-02-04 12:51:26 +01:00 committed by GitHub
commit a81b437d04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9148,12 +9148,15 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
if (preg_match('/\.(id|rowid)$/', $field)) { // Special case for rowid that is sometimes a ref so used as a search field
$newres .= $field." = ".(is_numeric(trim($tmpcrit)) ? ((float) trim($tmpcrit)) : '0');
} else {
$newres .= $field." LIKE '";
$tmpcrit = trim($tmpcrit);
$tmpcrit2 = $tmpcrit;
$tmpbefore = '%';
$tmpafter = '%';
if (preg_match('/^!/', $tmpcrit)) {
$newres .= $field." NOT LIKE '"; // ! as exclude character
$tmpcrit2 = preg_replace('/^!/', '', $tmpcrit2);
} else $newres .= $field." LIKE '";
if (preg_match('/^[\^\$]/', $tmpcrit)) {
$tmpbefore = '';
$tmpcrit2 = preg_replace('/^[\^\$]/', '', $tmpcrit2);