diff options
| author | Ludovic Arnaud <ludovic_arnaud@users.sourceforge.net> | 2006-07-04 15:16:57 +0000 |
|---|---|---|
| committer | Ludovic Arnaud <ludovic_arnaud@users.sourceforge.net> | 2006-07-04 15:16:57 +0000 |
| commit | bfb26c8a4afed016042e45ac909a8b5cc1f5a6fd (patch) | |
| tree | 4495e55978b12178df13028d9d013cba975dae78 | |
| parent | 291ab6216e4b4832fd49c237b933cc1abf83e588 (diff) | |
| download | forums-bfb26c8a4afed016042e45ac909a8b5cc1f5a6fd.tar forums-bfb26c8a4afed016042e45ac909a8b5cc1f5a6fd.tar.gz forums-bfb26c8a4afed016042e45ac909a8b5cc1f5a6fd.tar.bz2 forums-bfb26c8a4afed016042e45ac909a8b5cc1f5a6fd.tar.xz forums-bfb26c8a4afed016042e45ac909a8b5cc1f5a6fd.zip | |
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
| -rwxr-xr-x | phpBB/includes/search/fulltext_native.php | 12 |
1 files 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); |
