Skip to content
Snippets Groups Projects
Commit f6b4201a authored by JediKev's avatar JediKev
Browse files

issue: List & Choice Searching

This addresses issues 3703, 3493, 2625, and others where searching for
List or Choice values in a Custom Field will yield no results. This was
due to us using `FIND_IN_SET()` and `IN()` to search, which will not work
with the way the values are stored in the database. This updates the
search methods to use `REGEXP()` to search for the IDs of the List and
Choice values which will give the correct results whether it's multiple
choice or not.
parent acac3707
No related branches found
No related tags found
No related merge requests found
......@@ -1809,11 +1809,12 @@ class SelectionField extends FormField {
function getSearchQ($method, $value, $name=false) {
$name = $name ?: $this->get('name');
$val = '"?'.implode('("|,|$)|"?', array_keys($value)).'("|,|$)';
switch ($method) {
case '!includes':
return Q::not(array("{$name}__intersect" => array_keys($value)));
return Q::not(array("{$name}__regex" => $val));
case 'includes':
return new Q(array("{$name}__intersect" => array_keys($value)));
return new Q(array("{$name}__regex" => $val));
default:
return parent::getSearchQ($method, $value, $name);
}
......
......@@ -1740,11 +1740,12 @@ class ChoiceField extends FormField {
function getSearchQ($method, $value, $name=false) {
$name = $name ?: $this->get('name');
$val = '"?'.implode('("|,|$)|"?', array_keys($value)).'("|,|$)';
switch ($method) {
case '!includes':
return Q::not(array("{$name}__in" => array_keys($value)));
return Q::not(array("{$name}__regex" => $val));
case 'includes':
return new Q(array("{$name}__in" => array_keys($value)));
return new Q(array("{$name}__regex" => $val));
default:
return parent::getSearchQ($method, $value, $name);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment