From bfb26c8a4afed016042e45ac909a8b5cc1f5a6fd Mon Sep 17 00:00:00 2001 From: Ludovic Arnaud Date: Tue, 4 Jul 2006 15:16:57 +0000 Subject: [PATCH] Changed: moved the thing that compares the amount of matches to the amount of terms from outside the query (in PHP) to inside of it, thanks to a well-placed HAVING clause git-svn-id: file:///svn/phpbb/trunk@6146 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/search/fulltext_native.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index eec7415dd8..873faec291 100755 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -438,6 +438,9 @@ class fulltext_native extends search_backend if ($sql_in) { + // A little trick so we only need one query: using DISTINCT makes every word unique so if the + // number of all words for one post_id equals the number of AND-words it has to contain all + // AND-words $sql = "SELECT $sql_select, COUNT(DISTINCT m.word_id) as matches, " . $sort_by_sql[$sort_key] . " FROM $sql_from$sql_sort_table" . POSTS_TABLE . ' p, ' . SEARCH_WORDMATCH_TABLE . ' m, ' . SEARCH_WORDLIST_TABLE . " w WHERE w.word_text IN ($sql_in) @@ -446,6 +449,7 @@ class fulltext_native extends search_backend AND p.post_id = m.post_id $sql_where_options GROUP BY $field, " . $sort_by_sql[$sort_key] . ' + HAVING matches = ' . sizeof($sql_words['AND']) . ' ORDER BY ' . $sql_sort; $result = $db->sql_query($sql); @@ -456,16 +460,10 @@ class fulltext_native extends search_backend return false; } - // A little trick so we only need one query: using DISTINCT makes every word unique so if the - // number of all words for one post_id equals the number of AND-words it has to contain all - // AND-words $ids = array(); do { - if ($row['matches'] == sizeof($sql_words['AND'])) - { - $ids[] = ($type == 'topics') ? $row['topic_id'] : $row['post_id']; - } + $ids[] = ($type == 'topics') ? $row['topic_id'] : $row['post_id']; } while ($row = $db->sql_fetchrow($result)); $db->sql_freeresult($result);