diff options
author | Nils Adermann <naderman@naderman.de> | 2006-03-06 18:21:54 +0000 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2006-03-06 18:21:54 +0000 |
commit | 21f3fbc4be201a4fa277e65d30e694f0f75cb6ff (patch) | |
tree | 661005ebcac042d700535a8e19d373110b022fae /phpBB/includes/search | |
parent | 2246c8d6002660488914015a46cab8898f9a3943 (diff) | |
download | forums-21f3fbc4be201a4fa277e65d30e694f0f75cb6ff.tar forums-21f3fbc4be201a4fa277e65d30e694f0f75cb6ff.tar.gz forums-21f3fbc4be201a4fa277e65d30e694f0f75cb6ff.tar.bz2 forums-21f3fbc4be201a4fa277e65d30e694f0f75cb6ff.tar.xz forums-21f3fbc4be201a4fa277e65d30e694f0f75cb6ff.zip |
Me, me, me!
- only search unapproved posts/topics in forums where the user got the m_approve permission
- resize the search cache when it grows too huge (drop distant pages)
- added unread link to search results page
- streamlined search results and viewforum html code for displaying topics
so we're waiting for David now :)
git-svn-id: file:///svn/phpbb/trunk@5607 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/search')
-rw-r--r-- | phpBB/includes/search/fulltext_mysql.php | 43 | ||||
-rw-r--r-- | phpBB/includes/search/fulltext_phpbb.php | 48 | ||||
-rwxr-xr-x | phpBB/includes/search/search.php | 25 |
3 files changed, 103 insertions, 13 deletions
diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 795772d626..26ca4a6e0d 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -163,7 +163,7 @@ class fulltext_mysql extends search_backend * @param int $per_page number of ids each page is supposed to contain * @return total number of results */ - function keyword_search($type, &$fields, &$terms, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) + function keyword_search($type, &$fields, &$terms, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) { global $config, $db; @@ -183,6 +183,7 @@ class fulltext_mysql extends search_backend $sort_key, $topic_id, implode(',', $ex_fid_ary), + implode(',', $m_approve_fid_ary), implode(',', $author_ary) ))); @@ -241,16 +242,30 @@ class fulltext_mysql extends search_backend $sql_match_where = ''; } + if (!sizeof($m_approve_fid_ary)) + { + $m_approve_fid_sql = ' AND p.post_approved = 1'; + } + else if ($m_approve_fid_ary === array(-1)) + { + $m_approve_fid_sql = ''; + } + else + { + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR p.forum_id NOT IN (' . implode(', ', $m_approve_fid_ary) . '))'; + } + $sql_select = (!$result_count) ? 'SQL_CALC_FOUND_ROWS ' : ''; $sql_select = ($type == 'posts') ? $sql_select . 'p.post_id' : 'DISTINCT ' . $sql_select . 't.topic_id'; $sql_from = ($join_topic) ? TOPICS_TABLE . ' t, ' : ''; - $field = ($type == 'posts') ? 'p.post_id' : 't.topic_id'; + $field = ($type == 'posts') ? 'post_id' : 'topic_id'; $sql_author = (sizeof($author_ary) == 1) ? ' = ' . $author_ary[0] : 'IN (' . implode(',', $author_ary) . ')'; $sql_where_options = $sql_sort_join; $sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : ''; $sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : ''; $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND p.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ')' : ''; + $sql_where_options .= $m_approve_fid_sql; $sql_where_options .= (sizeof($author_ary)) ? ' AND p.poster_id ' . $sql_author : ''; $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_where_options .= $sql_match_where; @@ -301,7 +316,7 @@ class fulltext_mysql extends search_backend while ($row = $db->sql_fetchrow($result)) { - $id_ary[] = ($type == 'topics') ? $row['topic_id'] : $row['post_id']; + $id_ary[] = $row[$field]; } $db->sql_freeresult($result); @@ -340,7 +355,7 @@ class fulltext_mysql extends search_backend * @param int $per_page number of ids each page is supposed to contain * @return total number of results */ - function author_search($type, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) + function author_search($type, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) { global $config, $db; @@ -360,6 +375,7 @@ class fulltext_mysql extends search_backend $sort_key, $topic_id, implode(',', $ex_fid_ary), + implode(',', $m_approve_fid_ary), implode(',', $author_ary) ))); @@ -375,7 +391,7 @@ class fulltext_mysql extends search_backend // Create some display specific sql strings $sql_author = 'p.poster_id ' . ((sizeof($author_ary) > 1) ? 'IN (' . implode(',', $author_ary) . ')' : '= ' . $author_ary[0]); $sql_fora = (sizeof($ex_fid_ary)) ? ' AND p.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ')' : ''; - $sql_topic_id = (sizeof($ex_fid_ary)) ? ' AND p.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ')' : ''; + $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; // Build sql strings for sorting @@ -399,6 +415,19 @@ class fulltext_mysql extends search_backend break; } + if (!sizeof($m_approve_fid_ary)) + { + $m_approve_fid_sql = ' AND p.post_approved = 1'; + } + else if ($m_approve_fid_ary == array(-1)) + { + $m_approve_fid_sql = ''; + } + else + { + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR p.forum_id IN (' . implode($m_approve_fid_ary) . '))'; + } + // If the cache was completely empty count the results $calc_results = ($result_count) ? '' : 'SQL_CALC_FOUND_ROWS '; @@ -408,6 +437,8 @@ class fulltext_mysql extends search_backend $sql = "SELECT {$calc_results}p.post_id FROM " . $sql_sort_table . POSTS_TABLE . " p WHERE $sql_author + $sql_topic_id + $m_approve_fid_sql $sql_fora $sql_sort_join $sql_time @@ -419,6 +450,8 @@ class fulltext_mysql extends search_backend $sql = "SELECT {$calc_results}t.topic_id FROM " . $sql_sort_table . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p WHERE $sql_author + $sql_topic_id + $m_approve_fid_sql $sql_fora AND t.topic_id = p.topic_id $sql_sort_join diff --git a/phpBB/includes/search/fulltext_phpbb.php b/phpBB/includes/search/fulltext_phpbb.php index d9a61d4d6b..6259e7b984 100644 --- a/phpBB/includes/search/fulltext_phpbb.php +++ b/phpBB/includes/search/fulltext_phpbb.php @@ -179,7 +179,6 @@ class fulltext_phpbb extends search_backend if (sizeof($this->ignore_words)) { - $stopped_words = array_intersect($text, $this->ignore_words); $text = array_diff($text, $this->ignore_words); } @@ -210,7 +209,7 @@ class fulltext_phpbb extends search_backend * @param int $per_page number of ids each page is supposed to contain * @return total number of results */ - function keyword_search($type, &$fields, &$terms, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) + function keyword_search($type, &$fields, &$terms, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) { global $config, $db; @@ -230,6 +229,7 @@ class fulltext_phpbb extends search_backend $sort_key, $topic_id, implode(',', $ex_fid_ary), + implode(',', $m_approve_fid_ary), implode(',', $author_ary) ))); @@ -286,6 +286,19 @@ class fulltext_phpbb extends search_backend $sql_match = ''; } + if (!sizeof($m_approve_fid_ary)) + { + $m_approve_fid_sql = ' AND p.post_approved = 1'; + } + else if ($m_approve_fid_ary === array(-1)) + { + $m_approve_fid_sql = ''; + } + else + { + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR p.forum_id NOT IN (' . implode(', ', $m_approve_fid_ary) . '))'; + } + $sql_select = ($type == 'posts') ? 'm.post_id' : 'DISTINCT t.topic_id'; $sql_from = ($join_topic) ? TOPICS_TABLE . ' t, ' : ''; $field = ($type == 'posts') ? 'm.post_id' : 't.topic_id'; @@ -295,6 +308,7 @@ class fulltext_phpbb extends search_backend $sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : ''; $sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : ''; $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND p.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ')' : ''; + $sql_where_options .= $m_approve_fid_sql; $sql_where_options .= (sizeof($author_ary)) ? ' AND p.poster_id ' . $sql_author : ''; $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; $sql_where_options .= $sql_match; @@ -438,7 +452,6 @@ class fulltext_phpbb extends search_backend } $sql_where = ($sql_in) ? $sql_where . (($sql_where) ? ' OR ' : '') . 'w.word_text IN (' . $sql_in . ')' : $sql_where; - $sql_and = (sizeof($result_ary['AND'])) ? "AND $field IN (" . implode(', ', $result_ary['AND']) . ')' : ''; $sql = "SELECT $sql_select FROM $sql_from$sql_sort_table" . POSTS_TABLE . ' p, ' . SEARCH_MATCH_TABLE . ' m, ' . SEARCH_WORD_TABLE . " w WHERE ($sql_where) @@ -486,7 +499,6 @@ class fulltext_phpbb extends search_backend } $sql_where = ($sql_in) ? $sql_where . (($sql_where) ? ' OR ' : '') . 'w.word_text IN (' . $sql_in . ')' : $sql_where; - $sql_and = "AND $field IN (" . implode(', ', $id_ary) . ')'; $sql = "SELECT $sql_select FROM $sql_from" . POSTS_TABLE . ' p, ' . SEARCH_MATCH_TABLE . ' m, ' . SEARCH_WORD_TABLE . " w WHERE ($sql_where) @@ -532,7 +544,7 @@ class fulltext_phpbb extends search_backend * @param int $per_page number of ids each page is supposed to contain * @return total number of results */ - function author_search($type, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) + function author_search($type, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) { global $config, $db; @@ -552,6 +564,7 @@ class fulltext_phpbb extends search_backend $sort_key, $topic_id, implode(',', $ex_fid_ary), + implode(',', $m_approve_fid_ary), implode(',', $author_ary) ))); @@ -567,8 +580,8 @@ class fulltext_phpbb extends search_backend // Create some display specific sql strings $sql_author = 'p.poster_id ' . ((sizeof($author_ary) > 1) ? 'IN (' . implode(',', $author_ary) . ')' : '= ' . $author_ary[0]); $sql_fora = (sizeof($ex_fid_ary)) ? ' AND p.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ')' : ''; - $sql_topic_id = (sizeof($ex_fid_ary)) ? ' AND p.forum_id NOT IN (' . implode(',', $ex_fid_ary) . ')' : ''; $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; + $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; // Build sql strings for sorting $sql_sort = $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); @@ -591,6 +604,19 @@ class fulltext_phpbb extends search_backend break; } + if (!sizeof($m_approve_fid_ary)) + { + $m_approve_fid_sql = ' AND p.post_approved = 1'; + } + else if ($m_approve_fid_ary == array(-1)) + { + $m_approve_fid_sql = ''; + } + else + { + $m_approve_fid_sql = ' AND (p.post_approved = 1 OR p.forum_id IN (' . implode($m_approve_fid_ary) . '))'; + } + // If the cache was completely empty count the results if (!$result_count) { @@ -599,6 +625,8 @@ class fulltext_phpbb extends search_backend $sql = 'SELECT COUNT(p.post_id) as result_count FROM ' . POSTS_TABLE . " p WHERE $sql_author + $sql_topic_id + $m_approve_fid_sql $sql_fora $sql_time"; } @@ -607,6 +635,8 @@ class fulltext_phpbb extends search_backend $sql = 'SELECT COUNT(DISTINCT t.topic_id) as result_count FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p WHERE $sql_author + $sql_topic_id + $m_approve_fid_sql $sql_fora AND t.topic_id = p.topic_id $sql_time"; @@ -624,8 +654,10 @@ class fulltext_phpbb extends search_backend if ($type == 'posts') { $sql = 'SELECT p.post_id - FROM ' . $sql_sort_table . POSTS_TABLE . " p + FROM ' . $sql_sort_table . POSTS_TABLE . ' p' . (($topic_id) ? ', ' . TOPICS_TABLE . ' t' : '') . " WHERE $sql_author + $sql_topic_id + $m_approve_fid_sql $sql_fora $sql_sort_join $sql_time @@ -637,6 +669,8 @@ class fulltext_phpbb extends search_backend $sql = 'SELECT t.topic_id FROM ' . $sql_sort_table . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p WHERE $sql_author + $sql_topic_id + $m_approve_fid_sql $sql_fora AND t.topic_id = p.topic_id $sql_sort_join diff --git a/phpBB/includes/search/search.php b/phpBB/includes/search/search.php index daa3d62a4d..7a8a5ac1c3 100755 --- a/phpBB/includes/search/search.php +++ b/phpBB/includes/search/search.php @@ -211,7 +211,7 @@ class search_backend } else { - // we use one set of resuts for both sort directions so we have to calculate the indizes + // we use one set of results for both sort directions so we have to calculate the indizes // for the reversed array and we also have to reverse the ids themselves if ($store[-2] != $sort_dir) { @@ -230,6 +230,29 @@ class search_backend if (is_array($store_ids)) { $store += $store_ids; + + // if the cache is too big + if (sizeof($store) - 2 > 20 * $config['search_block_size']) + { + // remove everything in front of two blocks in front of the current start index + for ($i = 0, $n = $id_range[0] - 2 * $config['search_block_size']; $i < $n; $i++) + { + if (isset($store[$i])) + { + unset($store[$i]); + } + } + + // remove everything after two blocks after the current stop index + end($id_range); + for ($i = $store[-1] - 1, $n = current($id_range) + 2 * $config['search_block_size']; $i > $n; $i--) + { + if (isset($store[$i])) + { + unset($store[$i]); + } + } + } $cache->put('_search_results_' . $search_key, $store, $config['search_store_results']); $sql = 'UPDATE ' . SEARCH_TABLE . ' |