diff options
author | Nils Adermann <naderman@naderman.de> | 2006-03-26 01:36:26 +0000 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2006-03-26 01:36:26 +0000 |
commit | 8a32e0de742d9d4fd453402a48889bc6edd6a7f9 (patch) | |
tree | 83da50045e715ee7c47e8ea84e528a7fc17f58a6 /phpBB | |
parent | ed32b4d8dc396a656a6a0b84f9a40c5fce53278a (diff) | |
download | forums-8a32e0de742d9d4fd453402a48889bc6edd6a7f9.tar forums-8a32e0de742d9d4fd453402a48889bc6edd6a7f9.tar.gz forums-8a32e0de742d9d4fd453402a48889bc6edd6a7f9.tar.bz2 forums-8a32e0de742d9d4fd453402a48889bc6edd6a7f9.tar.xz forums-8a32e0de742d9d4fd453402a48889bc6edd6a7f9.zip |
- correctly use DISTINCT and GROUP BY in search related SQL [Bug #1256]
- always display views and replies in search results [Bug #1223]
- display error messages occuring during search index creation/deletion [Bug #1274]
- correctly align the ACP link on the search results page [Bug #1160]
- fixed the search forum box [Bug #1300] and added a search topic box (subBlue: can you please position this a little more visible, didn't want to mess with the CSS ;-))
- correctly check and use show_results on the search page
git-svn-id: file:///svn/phpbb/trunk@5727 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/includes/acp/acp_search.php | 46 | ||||
-rw-r--r-- | phpBB/includes/search/fulltext_mysql.php | 34 | ||||
-rw-r--r-- | phpBB/includes/search/fulltext_phpbb.php | 10 | ||||
-rw-r--r-- | phpBB/search.php | 29 | ||||
-rw-r--r-- | phpBB/styles/subSilver/template/search_body.html | 2 | ||||
-rw-r--r-- | phpBB/styles/subSilver/template/search_results.html | 6 | ||||
-rw-r--r-- | phpBB/styles/subSilver/template/searchbox.html | 7 | ||||
-rw-r--r-- | phpBB/viewforum.php | 2 | ||||
-rw-r--r-- | phpBB/viewtopic.php | 2 |
9 files changed, 80 insertions, 58 deletions
diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 58bcd66ec0..855bdea0f6 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -234,7 +234,12 @@ class acp_search if (method_exists($this->search, 'delete_index')) { // pass a reference to myself so the $search object can make use of save_state() and attributes - $this->search->delete_index($this, $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=delete"); + if ($error = $this->search->delete_index($this, $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=delete")) + { + $this->state = array(''); + $this->save_state(); + trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js()); + } } else { @@ -269,25 +274,23 @@ class acp_search } $this->search->tidy(); - + $this->state = array(''); $this->save_state(); - /** - * @todo remove Javascript - */ - trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action) . '<script language="javascript" type="text/javascript"> - <!-- - close_waitscreen = 1; - //--> - </script>'); + trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action) . $this->close_popup_js()); } else { if (method_exists($this->search, 'create_index')) { // pass a reference to myself so the $search object can make use of save_state() and attributes - $this->search->create_index($this, $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=create"); + if ($error = $this->search->create_index($this, $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=create")) + { + $this->state = array(''); + $this->save_state(); + trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js()); + } } else { @@ -319,14 +322,7 @@ class acp_search $this->state = array(''); $this->save_state(); - /** - * @todo remove Javascript - */ - trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action) . '<script language="javascript" type="text/javascript"> - <!-- - close_waitscreen = 1; - //--> - </script>'); + trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action) . $this->close_popup_js()); } } @@ -426,6 +422,18 @@ class acp_search adm_page_footer(); } + function close_popup_js() + { + /** + * @todo remove Javascript + */ + return '<script language="javascript" type="text/javascript"> + <!-- + close_waitscreen = 1; + //--> + </script>'; + } + function get_search_types() { global $phpbb_root_path, $phpEx; diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 3ef8fe0b2d..45597376fe 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -40,7 +40,7 @@ class fulltext_mysql extends search_backend } /** - * Checks for correct MySQL version and stores max/min word length in the config + * Checks for correct MySQL version and stores min/max word length in the config */ function init() { @@ -61,12 +61,18 @@ class fulltext_mysql extends search_backend } $result = $db->sql_query('SHOW TABLE STATUS LIKE \'' . POSTS_TABLE . '\''); - $engine = $db->sql_fetchfield('Engine', 0, $result); - if (!$engine) + $info = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $engine = ''; + if (isset($info['Engine'])) { - $engine = $db->sql_fetchfield('Type', 0, $result); + $engine = $info['Engine']; + } + else if (isset($info['Type'])) + { + $engine = $info['Type']; } - $db->sql_freeresult($result); if ($engine != 'MyISAM') { @@ -160,7 +166,7 @@ class fulltext_mysql extends search_backend } /** - * Turns text into an array of words that can be stored in the word list table + * Turns text into an array of words */ function split_message($text) { @@ -618,9 +624,10 @@ class fulltext_mysql extends search_backend { global $db; - if (strpos(SQL_LAYER, 'mysql') === false) + // Make sure we can actually use MySQL with fulltext indexes + if ($error = $this->init()) { - return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_VERSION']; + return $error; } if (!is_array($this->stats)) @@ -648,9 +655,10 @@ class fulltext_mysql extends search_backend { global $db; - if (strpos(SQL_LAYER, 'mysql') === false) + // Make sure we can actually use MySQL with fulltext indexes + if ($error = $this->init()) { - return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_VERSION']; + return $error; } if (!is_array($this->stats)) @@ -706,6 +714,12 @@ class fulltext_mysql extends search_backend { global $db; + if (strpos(SQL_LAYER, 'mysql') === false) + { + $this->stats = array(); + return; + } + $sql = 'SHOW INDEX FROM ' . POSTS_TABLE; $result = $db->sql_query($sql); diff --git a/phpBB/includes/search/fulltext_phpbb.php b/phpBB/includes/search/fulltext_phpbb.php index 6d9a33baaa..b01e70621b 100644 --- a/phpBB/includes/search/fulltext_phpbb.php +++ b/phpBB/includes/search/fulltext_phpbb.php @@ -405,15 +405,15 @@ class fulltext_phpbb extends search_backend if ($sql_in) { - $sql = "SELECT $sql_select, COUNT(DISTINCT m.word_id) as matches + $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_MATCH_TABLE . ' m, ' . SEARCH_WORD_TABLE . " w WHERE w.word_text IN ($sql_in) AND m.word_id = w.word_id AND w.word_common <> 1 AND p.post_id = m.post_id $sql_where_options - GROUP BY $field - ORDER BY $sql_sort"; + GROUP BY $field, " . $sort_by_sql[$sort_key] . ' + ORDER BY ' . $sql_sort; $result = $db->sql_query($sql); if (!($row = $db->sql_fetchrow($result))) @@ -689,8 +689,8 @@ class fulltext_phpbb extends search_backend AND t.topic_id = p.topic_id $sql_sort_join $sql_time - GROUP BY t.topic_id - ORDER BY $sql_sort"; + GROUP BY t.topic_id, " . $sort_by_sql[$sort_key] . ' + ORDER BY ' . $sql_sort; $field = 'topic_id'; } diff --git a/phpBB/search.php b/phpBB/search.php index 6b742d1a08..80ad3dccbe 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -28,10 +28,12 @@ $post_id = request_var('p', 0); $topic_id = request_var('t', 0); $view = request_var('view', ''); +$submit = request_var('submit', false); $keywords = request_var('keywords', ''); $add_keywords = request_var('add_keywords', ''); $author = request_var('author', ''); $show_results = ($topic_id) ? 'posts' : request_var('sr', 'posts'); +$show_results = ($show_results == 'posts') ? 'posts' : 'topics'; $search_terms = request_var('terms', 'all'); $search_fields = request_var('sf', 'all'); $search_child = request_var('sc', true); @@ -76,7 +78,7 @@ $sort_by_text = array('a' => $user->lang['SORT_AUTHOR'], 't' => $user->lang['SOR $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); -if ($keywords || $author || $search_id) +if ($keywords || $author || $search_id || $submit) { // clear arrays $id_ary = array(); @@ -231,6 +233,7 @@ if ($keywords || $author || $search_id) { // default to showing results as posts when performing an author search $show_results = ($topic_id) ? 'posts' : request_var('sr', ($search_id == 'egosearch') ? 'topics' : 'posts'); + $show_results = ($show_results == 'posts') ? 'posts' : 'topics'; } // define some variables needed for retrieving post_id/topic_id information @@ -241,9 +244,6 @@ if ($keywords || $author || $search_id) $sql = $field = ''; if ($search_id) { - // Build sql string for sorting - $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); - switch ($search_id) { // Oh holy Bob, bring us some activity... @@ -252,6 +252,7 @@ if ($keywords || $author || $search_id) $sort_key = 't'; $sort_dir = 'd'; $sort_by_sql['t'] = 't.topic_last_post_time'; + $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); if (!$sort_days) { @@ -262,7 +263,7 @@ if ($keywords || $author || $search_id) $last_post_time = (time() - ($sort_days * 24 * 3600)); - $sql = 'SELECT DISTINCT t.topic_id + $sql = 'SELECT DISTINCT t.topic_last_post_time, t.topic_id FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t WHERE p.post_time > $last_post_time AND t.topic_approved = 1 @@ -275,8 +276,10 @@ if ($keywords || $author || $search_id) case 'unanswered': $show_results = request_var('sr', 'topics'); + $show_results = ($show_results == 'posts') ? 'posts' : 'topics'; $sort_by_sql['t'] = ($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time'; $sort_by_sql['s'] = ($show_results == 'posts') ? 'p.post_subject' : 't.topic_title'; + $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); $sort_join = ($sort_key == 'f') ? FORUMS_TABLE . ' f, ' : ''; $sql_sort = ($sort_key == 'f') ? ' AND f.forum_id = p.forum_id ' . $sql_sort : $sql_sort; @@ -298,7 +301,7 @@ if ($keywords || $author || $search_id) } else { - $sql = "SELECT DISTINCT p.topic_id + $sql = 'SELECT DISTINCT ' . $sort_by_sql[$sort_key] . ", p.topic_id FROM $sort_join" . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t WHERE t.topic_replies = 0 AND p.topic_id = t.topic_id @@ -311,8 +314,10 @@ if ($keywords || $author || $search_id) case 'newposts': $show_results = request_var('sr', 'topics'); + $show_results = ($show_results == 'posts') ? 'posts' : 'topics'; $sort_by_sql['t'] = ($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time'; $sort_by_sql['s'] = ($show_results == 'posts') ? 'p.post_subject' : 't.topic_title'; + $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); $sort_join = ($sort_key == 'f') ? FORUMS_TABLE . ' f, ' : ''; $sql_sort = ($sort_key == 'f') ? ' AND f.forum_id = p.forum_id ' . $sql_sort : $sql_sort; @@ -339,7 +344,7 @@ if ($keywords || $author || $search_id) } else { - $sql = "SELECT DISTINCT p.topic_id + $sql = 'SELECT DISTINCT ' . $sort_by_sql[$sort_key] . ", p.topic_id FROM $sort_join" . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE p.post_time > ' . $user->data['user_lastvisit'] . " AND t.topic_id = p.topic_id @@ -418,7 +423,7 @@ if ($keywords || $author || $search_id) $hilit = htmlspecialchars(implode('|', str_replace(array('+', '-', '|'), '', $search->split_words))); $split_words = (sizeof($search->split_words)) ? htmlspecialchars(implode(' ', $search->split_words)) : ''; $u_hilit = urlencode($split_words); - $u_show_results = ($show_results != 'topic') ? '&sr=' . $show_results : ''; + $u_show_results = ($show_results != 'posts') ? '&sr=' . $show_results : ''; $u_search_forum = implode('&fid%5B%5D=', $search_forum); $u_search = "{$phpbb_root_path}search.$phpEx$SID"; @@ -585,10 +590,10 @@ if ($keywords || $author || $search_id) $view_topic_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$u_forum_id&t=$result_topic_id&hilit=$u_hilit"; + $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; + if ($show_results == 'topics') { - $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; - $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false, $folder_img, $folder_alt, $topic_type); @@ -601,8 +606,6 @@ if ($keywords || $author || $search_id) 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']), 'LAST_POST_AUTHOR' => ($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] : $user->lang['GUEST'], 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url), - 'REPLIES' => $replies, - 'VIEWS' => $row['topic_views'], 'TOPIC_TYPE' => $topic_type, 'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'), @@ -675,6 +678,8 @@ if ($keywords || $author || $search_id) 'FORUM_TITLE' => $row['forum_name'], 'TOPIC_TITLE' => $topic_title, + 'TOPIC_REPLIES' => $replies, + 'TOPIC_VIEWS' => $row['topic_views'], 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id", diff --git a/phpBB/styles/subSilver/template/search_body.html b/phpBB/styles/subSilver/template/search_body.html index 668edef756..61fc707270 100644 --- a/phpBB/styles/subSilver/template/search_body.html +++ b/phpBB/styles/subSilver/template/search_body.html @@ -42,7 +42,7 @@ <td class="row2" nowrap="nowrap"><select name="ch">{S_CHARACTER_OPTIONS}</select> <span class="genmed">{L_POST_CHARACTERS}</span></td> </tr> <tr> - <td class="cat" colspan="4" align="center">{S_HIDDEN_FIELDS}<input class="btnlite" type="submit" value="{L_SEARCH}" /> <input class="btnlite" type="reset" value="{L_RESET}" /></td> + <td class="cat" colspan="4" align="center">{S_HIDDEN_FIELDS}<input class="btnlite" name="submit" type="submit" value="{L_SEARCH}" /> <input class="btnlite" type="reset" value="{L_RESET}" /></td> </tr> </table></form> diff --git a/phpBB/styles/subSilver/template/search_results.html b/phpBB/styles/subSilver/template/search_results.html index c32aaad904..925bb6120d 100644 --- a/phpBB/styles/subSilver/template/search_results.html +++ b/phpBB/styles/subSilver/template/search_results.html @@ -54,8 +54,8 @@ <!-- ENDIF --> </td> <td class="row2" width="100" align="center"><p class="topicauthor">{searchresults.TOPIC_AUTHOR}</p></td> - <td class="row1" width="50" align="center"><p class="topicdetails">{searchresults.REPLIES}</p></td> - <td class="row2" width="50" align="center"><p class="topicdetails">{searchresults.VIEWS}</p></td> + <td class="row1" width="50" align="center"><p class="topicdetails">{searchresults.TOPIC_REPLIES}</p></td> + <td class="row2" width="50" align="center"><p class="topicdetails">{searchresults.TOPIC_VIEWS}</p></td> <td class="row1" width="120" align="center"> <p class="topicdetails">{searchresults.LAST_POST_TIME}</p> <p class="topicdetails"><!-- IF searchresults.U_LAST_POST_AUTHOR --><a href="{searchresults.U_LAST_POST_AUTHOR}">{searchresults.LAST_POST_AUTHOR}</a><!-- ELSE -->{searchresults.LAST_POST_AUTHOR}<!-- ENDIF --> @@ -132,6 +132,6 @@ <br clear="all" /> -<div style="float:right"><!-- INCLUDE jumpbox.html --></div> +<div align="right"><!-- INCLUDE jumpbox.html --></div> <!-- INCLUDE overall_footer.html -->
\ No newline at end of file diff --git a/phpBB/styles/subSilver/template/searchbox.html b/phpBB/styles/subSilver/template/searchbox.html index 4402836502..cb0bb5ba73 100644 --- a/phpBB/styles/subSilver/template/searchbox.html +++ b/phpBB/styles/subSilver/template/searchbox.html @@ -1,6 +1 @@ - -<form method="post" name="search" action="{S_SEARCHBOX_ACTION}"><table cellspacing="0" cellpadding="0" border="0"> - <tr> - <td nowrap="nowrap"><span class="gensmall">{L_SEARCH_FOR}:</span> <input class="post" type="text" name="search_keywords" size="20" /> <input class="btnlite" type="submit" value="{L_GO}" /></td> - </tr> -</table></form> +<form method="post" name="search" action="{S_SEARCHBOX_ACTION}"><span class="gensmall">{L_SEARCH_FOR}:</span> <input class="post" type="text" name="keywords" size="20" /> <input class="btnlite" type="submit" value="{L_GO}" /></form> diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 742f8be992..fa4316d5e1 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -254,7 +254,7 @@ if ($forum_data['forum_type'] == FORUM_POST || (($forum_data['forum_flags'] & 16 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'], 'S_FORUM_ACTION' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id&start=$start", 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('f_search', $forum_id)) ? true : false, - 'S_SEARCHBOX_ACTION' => "{$phpbb_root_path}search.$phpEx$SID&search_forum[]=$forum_id", + 'S_SEARCHBOX_ACTION' => "{$phpbb_root_path}search.$phpEx$SID&fid%5B%5D=$forum_id", 'U_MCP' => ($auth->acl_gets('m_', $forum_id)) ? "{$phpbb_root_path}mcp.$phpEx?sid=$user->session_id&f=$forum_id&i=main&mode=forum_view" : '', 'U_POST_NEW_TOPIC' => "{$phpbb_root_path}posting.$phpEx$SID&mode=post&f=$forum_id", diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 54d379475e..76c1907ccc 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -491,7 +491,7 @@ $template->assign_vars(array( 'S_MOD_ACTION' => "{$phpbb_root_path}mcp.$phpEx?sid=" . $user->session_id . "&t=$topic_id&f=$forum_id&quickmod=1", 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('f_search', $forum_id)) ? true : false, - 'S_SEARCHBOX_ACTION' => "{$phpbb_root_path}search.$phpEx$SID&search_forum[]=$forum_id", + 'S_SEARCHBOX_ACTION' => "{$phpbb_root_path}search.$phpEx$SID&t=$topic_id", 'U_TOPIC' => "{$server_path}viewtopic.$phpEx?f=$forum_id&t=$topic_id", 'U_FORUM' => $server_path, |