Fixed bug #17177: Live Search: Search query loops over all tables even after max...
authorIngo Renner <ingo.renner@typo3.org>
Sat, 22 Jan 2011 18:24:11 +0000 (18:24 +0000)
committerIngo Renner <ingo.renner@typo3.org>
Sat, 22 Jan 2011 18:24:11 +0000 (18:24 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@10264 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/search/class.t3lib_search_livesearch.php

index 6006c19..28f7dd3 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,7 @@
        * Follow-up to #17213: icons to add content were shifted down a bit, credits Steffen Gebert
        * Fixed bug #16681: Live-Search: Taking focus from search field should show tooltip "Enter search term" again, credits Jeff Segars
        * Fixed issue #17147: Update plugin layout to match other content elements, credits Jeff Segars
+       * Fixed bug #17177: Live Search: Search query loops over all tables even after max search results have been found, credits Jeff Segars
 
 2011-01-22  Jeff Segars  <jeff@webempoweredchurch.org>
 
index cb97012..ec2cc0c 100644 (file)
@@ -131,12 +131,9 @@ class t3lib_search_livesearch {
                        }
                } else {
                        $this->setQueryString($searchQuery);
-                       $recordArray = $this->findByGlobalTableList($pageIdList, $limit);
+                       $recordArray = $this->findByGlobalTableList($pageIdList);
                }
 
-                       // @todo Need to make sure we don't return too many records. How do we handle this when querying across multiple tables?
-               $recordArray = array_slice($recordArray, 0, $this->limitCount);
-
                return $recordArray;
        }
 
@@ -161,13 +158,22 @@ class t3lib_search_livesearch {
         * Find records from all registered TCA table & column values.
         *
         * @param string $pageIdList Comma seperated list of page IDs
-        * @param string $limit MySql Limit notation
         * @return array Records found in the database matching the searchQuery
         */
-       protected function findByGlobalTableList($pageIdList, $limit) {
+       protected function findByGlobalTableList($pageIdList) {
+               $limit = $this->limitCount;
                $getRecordArray = array();
                foreach ($GLOBALS['TCA'] as $tableName => $value) {
-                       $getRecordArray[] = $this->findByTable($tableName, $pageIdList, $limit);
+                       $recordArray = $this->findByTable($tableName, $pageIdList, '0,' . $limit);
+                       $recordCount = count($recordArray);
+                       if ($recordCount) {
+                               $limit = $limit - $recordCount;
+                               $getRecordArray[] = $recordArray;
+
+                               if ($limit <= 0) {
+                                       break;
+                               }
+                       }
                }
 
                return $getRecordArray;