forked from Wavyzz/dolibarr
NEW Can filter on string with spaces if search criteria is inside quote.
This commit is contained in:
@@ -11882,6 +11882,24 @@ function dol_getmypid()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate natural SQL search string for a criteria (this criteria can be tested on one or several fields)
|
||||
*
|
||||
* @param string $input String to explode
|
||||
* @return array<string> Array of string values
|
||||
*/
|
||||
function dolExplodeKeepIfQuotes($input)
|
||||
{
|
||||
// Use regexp to capture words and section in quotes
|
||||
$matches = array();
|
||||
preg_match_all('/"([^"]*)"|\'([^\']*)\'|(\S+)/', $input, $matches);
|
||||
|
||||
// Merge result and delete empty values
|
||||
return array_filter(array_map(function ($a, $b, $c) {
|
||||
return $a ?: ($b ?: $c);
|
||||
}, $matches[1], $matches[2], $matches[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate natural SQL search string for a criteria (this criteria can be tested on one or several fields)
|
||||
*
|
||||
@@ -11918,7 +11936,9 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
|
||||
|
||||
$value = preg_replace('/\s*\|\s*/', '|', $value);
|
||||
|
||||
$crits = explode(' ', $value);
|
||||
// Split criteria on ' ' but not if we are inside quotes
|
||||
$crits = dolExplodeKeepIfQuotes($value);
|
||||
|
||||
$res = '';
|
||||
if (!is_array($fields)) {
|
||||
$fields = array($fields);
|
||||
|
||||
Reference in New Issue
Block a user