Skip to content

Commit

Permalink
Merge pull request #320 from BlackbitDevs/patch-2
Browse files Browse the repository at this point in the history
[MySQL engine] Update for wordlist overwrote num_docs + num_hits instead of adding to previous value
  • Loading branch information
nticaric authored Nov 13, 2024
2 parents 069e63e + c29fb8f commit e990987
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Engines/MysqlEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function saveWordlist($stems)
$insertRows[] = '('.$this->index->quote($key).', '.$this->index->quote($term['hits']).', '.$this->index->quote($term['docs']).')';
}

$this->index->exec('INSERT INTO '.$this->indexName.'_wordlist (term, num_hits, num_docs) VALUES '.implode(',', $insertRows).' ON DUPLICATE KEY UPDATE num_docs=VALUES(num_docs), num_hits=VALUES(num_docs)');
$this->index->exec('INSERT INTO '.$this->indexName.'_wordlist (term, num_hits, num_docs) VALUES '.implode(',', $insertRows).' ON DUPLICATE KEY UPDATE num_docs=num_docs+VALUES(num_docs), num_hits=num_hits+VALUES(num_docs)');

$termIds = $this->index->query('SELECT id, term FROM '.$this->indexName.'_wordlist WHERE term IN ('.implode(',', array_map([$this->index, 'quote'], array_keys($termChunk))).')');
foreach ($termIds as $termId) {
Expand Down Expand Up @@ -455,4 +455,4 @@ public function readDocumentsFromFileSystem()
$this->info("Total rows $counter");
$this->info("Index created: {$this->config['storage']}");
}
}
}

0 comments on commit e990987

Please sign in to comment.