diff --git a/administrator/components/com_finder/helpers/indexer/driver/sqlsrv.php b/administrator/components/com_finder/helpers/indexer/driver/sqlsrv.php index 538f6e7c2816d..2b7480a3baecb 100644 --- a/administrator/components/com_finder/helpers/indexer/driver/sqlsrv.php +++ b/administrator/components/com_finder/helpers/indexer/driver/sqlsrv.php @@ -528,73 +528,4 @@ public function optimize() return true; } - - /** - * Method to add a set of tokens to the database. - * - * @param mixed $tokens An array or single FinderIndexerToken object. - * @param mixed $context The context of the tokens. See context constants. [optional] - * - * @return integer The number of tokens inserted into the database. - * - * @since 3.1 - * @throws Exception on database error. - */ - protected function addTokensToDb($tokens, $context = '') - { - // Get the database object. - $db = $this->db; - - $query = clone $this->addTokensToDbQueryTemplate; - - // Force tokens to an array. - $tokens = is_array($tokens) ? $tokens : array($tokens); - - // Count the number of token values. - $values = 0; - - // Set some variables to count the iterations - $totalTokens = count($tokens); - $remaining = $totalTokens; - $iterations = 0; - $loop = true; - - do - { - // Shift the token off the array - $token = array_shift($tokens); - - $query->values( - $db->quote($token->term) . ', ' - . $db->quote($token->stem) . ', ' - . (int) $token->common . ', ' - . (int) $token->phrase . ', ' - . (float) $token->weight . ', ' - . (int) $context . ', ' - . $db->quote($token->language) - ); - ++$values; - ++$iterations; - --$remaining; - - // Run the query if we've reached 1000 iterations or there are no tokens remaining - if ($iterations === 1000 || $remaining === 0) - { - $db->setQuery($query); - $db->execute(); - - // Reset the query - $query = clone $this->addTokensToDbQueryTemplate; - } - - // If there's nothing remaining, we're done looping - if ($remaining === 0) - { - $loop = false; - } - } - while ($loop === true); - - return $values; - } } diff --git a/administrator/components/com_finder/helpers/indexer/indexer.php b/administrator/components/com_finder/helpers/indexer/indexer.php index 8db56071bc59f..22885b72703b7 100644 --- a/administrator/components/com_finder/helpers/indexer/indexer.php +++ b/administrator/components/com_finder/helpers/indexer/indexer.php @@ -517,22 +517,30 @@ protected function addTokensToDb($tokens, $context = '') // Count the number of token values. $values = 0; - // Iterate through the tokens to create SQL value sets. - foreach ($tokens as $token) + // Break into chunks of no more than 1000 items + $chunks = array_chunk($tokens, 1000); + + foreach ($chunks as $tokens) { - $query->values( - $db->quote($token->term) . ', ' - . $db->quote($token->stem) . ', ' - . (int) $token->common . ', ' - . (int) $token->phrase . ', ' - . (float) $token->weight . ', ' - . (int) $context . ', ' - . $db->quote($token->language) - ); - ++$values; - } + $query->clear('values'); - $db->setQuery($query)->execute(); + // Iterate through the tokens to create SQL value sets. + foreach ($tokens as $token) + { + $query->values( + $db->quote($token->term) . ', ' + . $db->quote($token->stem) . ', ' + . (int) $token->common . ', ' + . (int) $token->phrase . ', ' + . (float) $token->weight . ', ' + . (int) $context . ', ' + . $db->quote($token->language) + ); + ++$values; + } + + $db->setQuery($query)->execute(); + } return $values; }