From: Marc Neuhaus Date: Mon, 3 Aug 2015 11:45:57 +0000 (+0200) Subject: [BUGFIX] Fix QueryBuilding in IndexSearchRepository X-Git-Tag: 7.5.0~545 X-Git-Url: http://git.typo3.org/Packages/TYPO3.CMS.git/commitdiff_plain/242ce5bd77a958beb0d5a0723708b591856c6eee [BUGFIX] Fix QueryBuilding in IndexSearchRepository This changeset fixes an issue in the indexSearchRepository that creates invalid sql queries. Main issue is the missing of several wSelClauses, that need to be collected, because they are imploded into the query. Resolves: #67843 Releases: master, 6.2 Change-Id: Ib53b28660acfd92233de748431131f70e69f5125 Reviewed-on: http://review.typo3.org/42219 Reviewed-by: Markus Klein Tested-by: Markus Klein Reviewed-by: Daniel Goerz Tested-by: Daniel Goerz Reviewed-by: Marc Neuhaus Reviewed-by: Alexander Opitz Tested-by: Alexander Opitz --- diff --git a/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php b/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php index dca247bffec0..d9064894c945 100644 --- a/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php +++ b/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php @@ -15,6 +15,7 @@ namespace TYPO3\CMS\IndexedSearch\Domain\Repository; */ use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\MathUtility; use TYPO3\CMS\IndexedSearch\Indexer; use TYPO3\CMS\IndexedSearch\Utility\IndexedSearchUtility; @@ -217,7 +218,7 @@ class IndexSearchRepository { // Total search-result count $count = $this->getDatabaseConnection()->sql_num_rows($res); // The pointer is set to the result page that is currently being viewed - $pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->resultpagePointer, 0, floor($count / $this->numberOfResults)); + $pointer = MathUtility::forceIntegerInRange($this->resultpagePointer, 0, floor($count / $this->numberOfResults)); // Initialize result accumulation variables: $c = 0; // Result pointer: Counts up the position in the current search-result @@ -329,6 +330,7 @@ class IndexSearchRepository { $c = 0; // This array accumulates the phash-values $totalHashList = array(); + $this->wSelClauses = array(); // Traverse searchwords; for each, select all phash integers and merge/diff/intersect them with previous word (based on operator) foreach ($searchWords as $k => $v) { // Making the query for a single search word based on the search-type @@ -339,7 +341,6 @@ class IndexSearchRepository { $theType = 20; } $this->getTimeTracker()->push('SearchWord "' . $sWord . '" - $theType=' . $theType); - $wSel = ''; // Perform search for word: switch ($theType) { case '1': @@ -381,8 +382,6 @@ class IndexSearchRepository { // Distinct word $res = $this->searchDistinct($sWord); } - // Accumulate the word-select clauses - $this->wSelClauses[] = $wSel; // If there was a query to do, then select all phash-integers which resulted from this. if ($res) { // Get phash list by searching for it: @@ -442,6 +441,7 @@ class IndexSearchRepository { $wildcard_left = $mode & self::WILDCARD_LEFT ? '%' : ''; $wildcard_right = $mode & self::WILDCARD_RIGHT ? '%' : ''; $wSel = 'IW.baseword LIKE \'' . $wildcard_left . $this->getDatabaseConnection()->quoteStr($sWord, 'index_words') . $wildcard_right . '\''; + $this->wSelClauses[] = $wSel; return $this->execPHashListQuery($wSel, ' AND is_stopword=0'); } @@ -453,6 +453,7 @@ class IndexSearchRepository { */ protected function searchDistinct($sWord) { $wSel = 'IW.wid=' . $this->md5inthash($sWord); + $this->wSelClauses[] = $wSel; return $this->execPHashListQuery($wSel, ' AND is_stopword=0'); } @@ -463,6 +464,7 @@ class IndexSearchRepository { * @return bool|\mysqli_result SQL result pointer */ protected function searchSentence($sWord) { + $this->wSelClauses[] = '1=1'; return $this->getDatabaseConnection()->exec_SELECTquery( 'ISEC.phash', 'index_section ISEC, index_fulltext IFT', @@ -481,6 +483,7 @@ class IndexSearchRepository { */ protected function searchMetaphone($sWord) { $wSel = 'IW.metaphone=' . $sWord; + $this->wSelClauses[] = $wSel; return $this->execPHashListQuery($wSel, ' AND is_stopword=0'); } @@ -682,8 +685,11 @@ class IndexSearchRepository { $grsel = 'SUM(IR.freq) AS order_val'; $orderBy = 'order_val' . $this->getDescendingSortOrderFlag(); } - // So, words are imploded into an OR statement (no "sentence search" should be done here - may deselect results) - $wordSel = '(' . implode(' OR ', $this->wSelClauses) . ') AND '; + $wordSel = ''; + if (!empty($this->wSelClauses)) { + // So, words are imploded into an OR statement (no "sentence search" should be done here - may deselect results) + $wordSel = '(' . implode(' OR ', $this->wSelClauses) . ') AND '; + } $res = $this->getDatabaseConnection()->exec_SELECTquery( 'ISEC.*, IP.*, ' . $grsel, 'index_words IW,