" . $conditionBuilder . "
GROUP BY tag_to_object.objectID
HAVING COUNT(*) >= " . round(count($this->tags) * ARTICLE_RELATED_ARTICLES_MATCH_THRESHOLD / 100) . "
- ORDER BY count DESC, RAND()";
- $statement = WCF::getDB()->prepareStatement($sql, ARTICLE_RELATED_ARTICLES);
+ ORDER BY count DESC, MAX(article.time) DESC";
+ $statement = WCF::getDB()->prepareStatement($sql, ARTICLE_RELATED_ARTICLES * 4);
$statement->execute($conditionBuilder->getParameters());
$articleIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
if (!empty($articleIDs)) {
+ if (count($articleIDs) > ARTICLE_RELATED_ARTICLES) {
+ shuffle($articleIDs);
+ $articleIDs = array_slice($articleIDs, 0, ARTICLE_RELATED_ARTICLES);
+ }
+
$this->relatedArticles = new AccessibleArticleList();
$this->relatedArticles->getConditionBuilder()->add('article.articleID IN (?)', [$articleIDs]);
$this->relatedArticles->sqlOrderBy = 'article.time';