Skip to content

Commit

Permalink
Merge pull request #6524 in SW/shopware from sw-21426/5.4/make-search…
Browse files Browse the repository at this point in the history
…-batch-configurable to 5.4

* commit '44b5dbad9e1638e189e12956e4fa2d18e8e16da8':
  SW-21426 - Reduce indexer batchsize and make it configurable
  • Loading branch information
soebbing committed Apr 26, 2018
2 parents 97df0dc + 44b5dba commit 4089fca
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion UPGRADE-5.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ This changelog references changes done in Shopware 5.4 patch versions.
* Changed the notification box behaviour when products are out of stock
* Changed API behaviour on update, when the lastStock parameter is set for a product its applied to its mainDetail aswell (like on creation)
* Changed newsletter recipient count to work correctly with customer streams
* Changed position of serveral privacy options to the privacy basic setting category
* Changed position of several privacy options to the privacy basic setting category
* Changed search indexer to make the keyword batch size configurable using the key `search.indexer.batchsize` in the `config.php`

### Removals

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,27 @@ class SearchIndexer implements SearchIndexerInterface
*/
private $termHelper;

/**
* @var int
*/
private $batchSize;

/**
* @param \Shopware_Components_Config $config
* @param Connection $connection
* @param TermHelperInterface $termHelper
* @param int $batchSize
*/
public function __construct(
\Shopware_Components_Config $config,
Connection $connection,
TermHelperInterface $termHelper
TermHelperInterface $termHelper,
$batchSize = 4000
) {
$this->config = $config;
$this->connection = $connection;
$this->termHelper = $termHelper;
$this->batchSize = $batchSize > 0 ? $batchSize : 4000;
}

/**
Expand All @@ -71,7 +79,7 @@ public function validate()
{
$strategy = $this->config->get('searchRefreshStrategy', 3);

//search index refresh strategy is configured for "live refresh"?
// Search index refresh strategy is configured for "live refresh"?
if ($strategy !== 3) {
return;
}
Expand Down Expand Up @@ -131,7 +139,7 @@ public function build()
if (!empty($tables)) {
foreach ($tables as $table) {
// Set primary key
$table['elementID'] = empty($table['foreign_key']) && $table['table'] != 's_articles' ? 'articleID' : 'id';
$table['elementID'] = empty($table['foreign_key']) && $table['table'] !== 's_articles' ? 'articleID' : 'id';

if ($table['table'] === 's_articles_attributes') {
$table['elementID'] = '(SELECT articleID FROM s_articles_details WHERE id = articledetailsID LIMIT 1)';
Expand Down Expand Up @@ -188,6 +196,7 @@ public function build()
$keyword = $this->connection->quote($keyword);
$keywords[] = $keyword;
}
unset($keyword);

// SQL-queries to fill s_search_index
$sqlIndex[] = 'SELECT sk.id as keywordID, ' . $row['id'] . ' as elementID, ' . $fieldID . ' as fieldID '
Expand All @@ -201,7 +210,7 @@ public function build()
}

// If last row or more then 5000 keywords fetched, write results to index
if ($currentRow == count($getTableKeywords) - 1 || count($keywords) > 5000) {
if ($currentRow == count($getTableKeywords) - 1 || count($keywords) > $this->batchSize) {
$keywords = array_unique($keywords); // Remove duplicates
$sql_keywords = 'INSERT IGNORE INTO `s_search_keywords` (`keyword`) VALUES';
$sql_keywords .= ' (' . implode('), (', $keywords) . ')';
Expand Down
1 change: 1 addition & 0 deletions engine/Shopware/Bundle/SearchBundleDBAL/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<argument type="service" id="config" />
<argument type="service" id="dbal_connection" />
<argument type="service" id="shopware_searchdbal.search_term_helper" />
<argument>%shopware.search.indexer.batchsize%</argument>
</service>

<service id="shopware_searchdbal.search_term_helper" class="Shopware\Bundle\SearchBundleDBAL\SearchTerm\TermHelper">
Expand Down
5 changes: 5 additions & 0 deletions engine/Shopware/Configs/Default.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@
'php_modifiers' => include __DIR__ . '/smarty_functions.php',
'php_functions' => include __DIR__ . '/smarty_functions.php',
],
'search' => [
'indexer' => [
'batchsize' => 4000,
],
],
'app' => [
'rootDir' => $this->DocPath(),
'downloadsDir' => $this->DocPath('files_downloads'),
Expand Down

0 comments on commit 4089fca

Please sign in to comment.