[feature/soft-delete] Try to fix search.php

at least it's running now, but the performance is not very good.

PHPBB3-9657
This commit is contained in:
Joas Schilling 2012-08-30 19:47:16 +02:00
parent 1c043254c0
commit 5b54ec2d64
2 changed files with 20 additions and 34 deletions

View file

@ -819,7 +819,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
* @param int $per_page number of ids each page is supposed to contain * @param int $per_page number of ids each page is supposed to contain
* @return boolean|int total number of results * @return boolean|int total number of results
*/ */
public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{ {
// No author? No posts. // No author? No posts.
if (!sizeof($author_ary)) if (!sizeof($author_ary))
@ -838,7 +838,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$sort_key, $sort_key,
$topic_id, $topic_id,
implode(',', $ex_fid_ary), implode(',', $ex_fid_ary),
// @TODO implode(',', $m_approve_fid_ary), $post_visibility,
implode(',', $author_ary), implode(',', $author_ary),
$author_name, $author_name,
))); )));
@ -888,20 +888,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base
break; 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 ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
*/
$select = ($type == 'posts') ? 'p.post_id' : 't.topic_id'; $select = ($type == 'posts') ? 'p.post_id' : 't.topic_id';
$is_mysql = false; $is_mysql = false;
@ -924,7 +910,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
WHERE $sql_author WHERE $sql_author
$sql_topic_id $sql_topic_id
$sql_firstpost $sql_firstpost
$m_approve_fid_sql $post_visibility
$sql_fora $sql_fora
$sql_time"; $sql_time";
} }
@ -944,7 +930,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
WHERE $sql_author WHERE $sql_author
$sql_topic_id $sql_topic_id
$sql_firstpost $sql_firstpost
$m_approve_fid_sql $post_visibility
$sql_fora $sql_fora
AND t.topic_id = p.topic_id AND t.topic_id = p.topic_id
$sql_time" . (($this->db->sql_layer == 'sqlite') ? ')' : ''); $sql_time" . (($this->db->sql_layer == 'sqlite') ? ')' : '');
@ -970,7 +956,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
WHERE $sql_author WHERE $sql_author
$sql_topic_id $sql_topic_id
$sql_firstpost $sql_firstpost
$m_approve_fid_sql $post_visibility
$sql_fora $sql_fora
$sql_sort_join $sql_sort_join
$sql_time $sql_time
@ -984,7 +970,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
WHERE $sql_author WHERE $sql_author
$sql_topic_id $sql_topic_id
$sql_firstpost $sql_firstpost
$m_approve_fid_sql $post_visibility
$sql_fora $sql_fora
AND t.topic_id = p.topic_id AND t.topic_id = p.topic_id
$sql_sort_join $sql_sort_join

View file

@ -266,7 +266,8 @@ if ($keywords || $author || $author_id || $search_id || $submit)
$m_approve_fid_sql = ' AND p.post_approved = 1'; $m_approve_fid_sql = ' AND p.post_approved = 1';
} }
*/ */
$m_approve_fid_sql = ' AND ' . phpbb_content_visibility::get_visibility_sql_global('post', $ex_fid_ary, 'p.'); $m_approve_posts_fid_sql = ' AND ' . phpbb_content_visibility::get_visibility_sql_global('post', $ex_fid_ary, 'p.');
$m_approve_topics_fid_sql = ' AND ' . phpbb_content_visibility::get_visibility_sql_global('topic', $ex_fid_ary, 't.');
if ($reset_search_forum) if ($reset_search_forum)
{ {
@ -334,7 +335,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
FROM ' . TOPICS_TABLE . " t FROM ' . TOPICS_TABLE . " t
WHERE t.topic_moved_id = 0 WHERE t.topic_moved_id = 0
$last_post_time_sql $last_post_time_sql
" . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . ' " . $m_approve_topics_fid_sql . '
' . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . ' ' . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . '
ORDER BY t.topic_last_post_time DESC'; ORDER BY t.topic_last_post_time DESC';
$field = 'topic_id'; $field = 'topic_id';
@ -372,7 +373,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
WHERE t.topic_replies = 0 WHERE t.topic_replies = 0
AND p.topic_id = t.topic_id AND p.topic_id = t.topic_id
$last_post_time $last_post_time
$m_approve_fid_sql $m_approve_posts_fid_sql
" . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . " " . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . "
$sql_sort"; $sql_sort";
$field = 'post_id'; $field = 'post_id';
@ -385,7 +386,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
AND t.topic_moved_id = 0 AND t.topic_moved_id = 0
AND p.topic_id = t.topic_id AND p.topic_id = t.topic_id
$last_post_time $last_post_time
$m_approve_fid_sql $m_approve_topics_fid_sql
" . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . " " . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . "
$sql_sort"; $sql_sort";
$field = 'topic_id'; $field = 'topic_id';
@ -401,7 +402,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
$sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
$sql_where = 'AND t.topic_moved_id = 0 $sql_where = 'AND t.topic_moved_id = 0
' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . ' ' . $m_approve_topics_fid_sql . '
' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : ''); ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '');
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
@ -424,9 +425,9 @@ if ($keywords || $author || $author_id || $search_id || $submit)
{ {
$sql = 'SELECT p.post_id $sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p FROM ' . POSTS_TABLE . ' p
WHERE p.post_time > ' . $user->data['user_lastvisit'] . " WHERE p.post_time > ' . $user->data['user_lastvisit'] . '
$m_approve_fid_sql ' . $m_approve_posts_fid_sql . '
" . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . " ' . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . "
$sql_sort"; $sql_sort";
$field = 'post_id'; $field = 'post_id';
} }
@ -436,7 +437,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
FROM ' . TOPICS_TABLE . ' t FROM ' . TOPICS_TABLE . ' t
WHERE t.topic_last_post_time > ' . $user->data['user_lastvisit'] . ' WHERE t.topic_last_post_time > ' . $user->data['user_lastvisit'] . '
AND t.topic_moved_id = 0 AND t.topic_moved_id = 0
' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . ' ' . $m_approve_topics_fid_sql . '
' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . " ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . "
$sql_sort"; $sql_sort";
/* /*
@ -448,8 +449,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
WHERE p.post_time > ' . $user->data['user_lastvisit'] . ' WHERE p.post_time > ' . $user->data['user_lastvisit'] . '
AND t.topic_id = p.topic_id AND t.topic_id = p.topic_id
AND t.topic_moved_id = 0 AND t.topic_moved_id = 0
' . $m_approve_fid_sql . ' ' . $m_approve_topics_fid_sql . "
' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . "
GROUP BY t.topic_id GROUP BY t.topic_id
$sql_sort"; $sql_sort";
*/ */
@ -530,12 +530,12 @@ if ($keywords || $author || $author_id || $search_id || $submit)
if (!empty($search->search_query)) if (!empty($search->search_query))
{ {
$total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_sql, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page); $total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_posts_fid_sql, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page);
} }
else if (sizeof($author_id_ary)) else if (sizeof($author_id_ary))
{ {
$firstpost_only = ($search_fields === 'firstpost' || $search_fields == 'titleonly') ? true : false; $firstpost_only = ($search_fields === 'firstpost' || $search_fields == 'titleonly') ? true : false;
$total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_sql, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page); $total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_posts_fid_sql, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page);
} }
// For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options. // For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options.
@ -550,7 +550,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
{ {
$sql_where .= $db->sql_in_set(($show_results == 'posts') ? 'p.post_id' : 't.topic_id', $id_ary); $sql_where .= $db->sql_in_set(($show_results == 'posts') ? 'p.post_id' : 't.topic_id', $id_ary);
$sql_where .= (sizeof($ex_fid_ary)) ? ' AND (' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . ' OR f.forum_id IS NULL)' : ''; $sql_where .= (sizeof($ex_fid_ary)) ? ' AND (' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . ' OR f.forum_id IS NULL)' : '';
$sql_where .= ($show_results == 'posts') ? $m_approve_fid_sql : str_replace(array('p.post_visibility', 'p.forum_id'), array('t.topic_visibility', 't.forum_id'), $m_approve_fid_sql); $sql_where .= ($show_results == 'posts') ? $m_approve_posts_fid_sql : $m_approve_topics_fid_sql;
} }
if ($show_results == 'posts') if ($show_results == 'posts')