diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html
index 7aefdeafc9..267e4e0bff 100644
--- a/phpBB/docs/CHANGELOG.html
+++ b/phpBB/docs/CHANGELOG.html
@@ -124,6 +124,7 @@
[Fix] Restrict search for styles/../style.cfg to folders. (Bug #55665)
[Fix] Add ability to disable overall (aka board-wide) feed.
[Fix] Do not pass new_link parameter when creating a persistent connection with mysql. (Bug #55785)
+ [Fix] Improved search query performance through sorting words by their occurance. (Bug #21555)
[Change] Move redirect into a hidden field to avoid issues with mod_security. (Bug #54145)
[Change] Log activation through inactive users ACP. (Bug #30145)
[Change] Send time of last item instead of current time in ATOM Feeds. (Bug #53305)
diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php
index 5af3929ccd..e1ab02ba9d 100644
--- a/phpBB/includes/search/fulltext_native.php
+++ b/phpBB/includes/search/fulltext_native.php
@@ -202,7 +202,8 @@ class fulltext_native extends search_backend
{
$sql = 'SELECT word_id, word_text, word_common
FROM ' . SEARCH_WORDLIST_TABLE . '
- WHERE ' . $db->sql_in_set('word_text', $exact_words);
+ WHERE ' . $db->sql_in_set('word_text', $exact_words) . '
+ ORDER BY word_count ASC';
$result = $db->sql_query($sql);
// store an array of words and ids, remove common words
@@ -377,10 +378,6 @@ class fulltext_native extends search_backend
return false;
}
- sort($this->must_contain_ids);
- sort($this->must_not_contain_ids);
- sort($this->must_exclude_one_ids);
-
if (!empty($this->search_query))
{
return true;
@@ -420,11 +417,19 @@ class fulltext_native extends search_backend
return false;
}
+ $must_contain_ids = $this->must_contain_ids;
+ $must_not_contain_ids = $this->must_not_contain_ids;
+ $must_exclude_one_ids = $this->must_exclude_one_ids;
+
+ sort($must_contain_ids);
+ sort($must_not_contain_ids);
+ sort($must_exclude_one_ids);
+
// generate a search_key from all the options to identify the results
$search_key = md5(implode('#', array(
- serialize($this->must_contain_ids),
- serialize($this->must_not_contain_ids),
- serialize($this->must_exclude_one_ids),
+ serialize($must_contain_ids),
+ serialize($must_not_contain_ids),
+ serialize($must_exclude_one_ids),
$type,
$fields,
$terms,