[BUGFIX] Invalid behavior of search for integer in Backend search
authorSoren Malling <soren.malling@gmail.com>
Fri, 21 Sep 2012 12:02:36 +0000 (14:02 +0200)
committerDmitry Dulepov <dmitry@typo3.org>
Fri, 16 Nov 2012 12:25:12 +0000 (13:25 +0100)
In fact current implementation does not replace the LIKE
operator with an SQL equal statement for numeric fields
but whenever a query that can be interpreted as integer
is encountered, regardless of the underlying column type.

Example: If you have pages "102 W", "102 E", you used
to be able to search for "102" and get them, but now
the query is casted to an integer and the page title
is search for an equality on "102" resulting in
an empty result list.

The underlying column type should be used
instead (code to cache this information is already
available within DBAL and Helmut started months
ago to backport it to Core itself: #28654).

Thanks to Clio Online for sponsoring this fix!

Resolves: #33700
Releases: 6.0, 4.7, 4.6

Change-Id: I8c4cceac5320b9135ccf9e99892cc57dcfffadc5
Reviewed-on: http://review.typo3.org/13990
Reviewed-by: Mattias Nilsson
Tested-by: Mattias Nilsson
Reviewed-by: Felix Kopp
Tested-by: Felix Kopp
Reviewed-by: Dmitry Dulepov
Tested-by: Dmitry Dulepov
typo3/sysext/backend/Classes/Search/LiveSearch/LiveSearch.php
typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php

index 905b7fa..5183f5a 100644 (file)
@@ -321,6 +321,13 @@ class LiveSearch {
                                        // Assemble the search condition only if the field is an integer, or is uid or pid
                                        if ($fieldName == 'uid' || $fieldName == 'pid' || $fieldConfig['type'] == 'input' && $fieldConfig['eval'] && \TYPO3\CMS\Core\Utility\GeneralUtility::inList($fieldConfig['eval'], 'int')) {
                                                $whereParts[] = $fieldName . '=' . $this->queryString;
                                        // Assemble the search condition only if the field is an integer, or is uid or pid
                                        if ($fieldName == 'uid' || $fieldName == 'pid' || $fieldConfig['type'] == 'input' && $fieldConfig['eval'] && \TYPO3\CMS\Core\Utility\GeneralUtility::inList($fieldConfig['eval'], 'int')) {
                                                $whereParts[] = $fieldName . '=' . $this->queryString;
+                                       } elseif (
+                                               $fieldConfig['type'] == 'text' ||
+                                               $fieldConfig['type'] == 'flex' ||
+                                               ($fieldConfig['type'] == 'input' && (!$fieldConfig['eval'] ||
+                                               !preg_match('/date|time|int/', $fieldConfig['eval'])))) {
+                                                       // Otherwise and if the field makes sense to be searched, assemble a like condition
+                                                       $whereParts[] = $fieldName . ' LIKE \'%' . $this->queryString . '%\'';
                                        }
                                }
                        }
                                        }
                                }
                        }
@@ -470,4 +477,4 @@ class LiveSearch {
 }
 
 
 }
 
 
-?>
\ No newline at end of file
+?>
index 027163e..a68d32d 100644 (file)
@@ -633,12 +633,18 @@ class AbstractDatabaseRecordList extends \TYPO3\CMS\Backend\RecordList\AbstractR
                                        foreach ($searchableFields as $fieldName) {
                                                if (isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) {
                                                        $fieldConfig = &$GLOBALS['TCA'][$table]['columns'][$fieldName]['config'];
                                        foreach ($searchableFields as $fieldName) {
                                                if (isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) {
                                                        $fieldConfig = &$GLOBALS['TCA'][$table]['columns'][$fieldName]['config'];
+                                                       $condition = $fieldName . '=' . $this->searchString;
                                                        if ($fieldConfig['type'] == 'input' && $fieldConfig['eval'] && \TYPO3\CMS\Core\Utility\GeneralUtility::inList($fieldConfig['eval'], 'int')) {
                                                        if ($fieldConfig['type'] == 'input' && $fieldConfig['eval'] && \TYPO3\CMS\Core\Utility\GeneralUtility::inList($fieldConfig['eval'], 'int')) {
-                                                               $condition = $fieldName . '=' . $this->searchString;
                                                                if (is_array($fieldConfig['search']) && in_array('pidonly', $fieldConfig['search']) && $currentPid > 0) {
                                                                        $condition = '(' . $condition . ' AND ' . $tablePidField . '=' . $currentPid . ')';
                                                                }
                                                                $whereParts[] = $condition;
                                                                if (is_array($fieldConfig['search']) && in_array('pidonly', $fieldConfig['search']) && $currentPid > 0) {
                                                                        $condition = '(' . $condition . ' AND ' . $tablePidField . '=' . $currentPid . ')';
                                                                }
                                                                $whereParts[] = $condition;
+                                                       } elseif (
+                                                               $fieldConfig['type'] == 'text' ||
+                                                               $fieldConfig['type'] == 'flex' ||
+                                                               ($fieldConfig['type'] == 'input' && (!$fieldConfig['eval'] || !preg_match('/date|time|int/', $fieldConfig['eval'])))) {
+                                                                       $condition = $fieldName . ' LIKE \'%' . $this->searchString . '%\'';
+                                                                       $whereParts[] = $condition;
                                                        }
                                                }
                                        }
                                                        }
                                                }
                                        }
@@ -964,4 +970,4 @@ class AbstractDatabaseRecordList extends \TYPO3\CMS\Backend\RecordList\AbstractR
 }
 
 
 }
 
 
-?>
\ No newline at end of file
+?>