Indexing of Single Selects in Concrete5

Doing a MySQL search on select values in concrete5 version 5.6.3.1 (perhaps earlier versions, too) is somewhat of a pain. In order to get each of the selected values of a mutliselect box, newline characters are added between values.
This causes big issues when you're using Page List+ select boxes and trying to do something like:
Show all 'House' pages that have 'x' number of bathrooms or more
The default functionality looks like this:
- public function getSearchIndexValue() {
- $str = "\n";
-
- $list = $this->getSelectedOptions();
- foreach($list as $l) {
- $str .= $l . "\n";
- }
- // remove line break for empty list
- if ($str == "\n") {
- return '';
- }
- return $str;
- }
-
You'll see that before and after each value in the index, a newline character, \n, is added.
To resolve this, I've used the default core overwrite functionality:
- Copy the file located at {root}/concrete/models/attribute/types/select/controller.php to {root}/models/attribute/types/select/controller.php
- Add the updated functionality (shown below) to the SelectAttributeTypeController class.
- Clear the overwrites cache.
- class SelectAttributeTypeController extends Concrete5_Controller_AttributeType_Select {
- public function getSearchIndexValue() {
- if (!$ignoreNewlines) {
- $str = "\n";
- }
- $list = $this->getSelectedOptions();
- foreach($list as $l) {
- $str .= $l;
- if (!$ignoreNewlines) {
- $str .= "\n";
- }
- }
- // remove line break for empty list
- if ($str == "\n") {
- return '';
- }
- return $str;
- }
- }
- class SelectAttributeTypeOption extends Concrete5_Model_SelectAttributeTypeOption {}
- class SelectAttributeTypeOptionList extends Concrete5_Model_SelectAttributeTypeOptionList {}
You can download this file here. Note that it is in text format; you'll need to change the extension.
Once in place, you'll also need to update the list of select attribute handles that you want it to affect. Change line 4 to do this.