diff --git a/install/sphinx/sphinx.conf b/install/sphinx/sphinx.conf index 0f23247f9..ef2679995 100644 --- a/install/sphinx/sphinx.conf +++ b/install/sphinx/sphinx.conf @@ -1,10 +1,10 @@ source torrentpier { - type = mysql - sql_host = localhost - sql_user = user - sql_pass = user - sql_db = forum + type = mysql + sql_host = localhost + sql_user = user + sql_pass = pass + sql_db = dbase sql_query_pre = SET NAMES utf8 sql_query_pre = SET CHARACTER_SET_RESULTS=utf8 sql_query_pre = SET CHARACTER_SET_CLIENT=utf8 @@ -13,46 +13,87 @@ source torrentpier source topics: torrentpier { - sql_query = \ + sql_query = \ SELECT topic_id, forum_id, topic_title \ FROM bb_topics \ WHERE topic_id BETWEEN $start AND $end - sql_query_range = SELECT MIN(topic_id), MAX(topic_id) FROM bb_topics - sql_range_step = 100000 + sql_query_range = SELECT MIN(topic_id), MAX(topic_id) FROM bb_topics + sql_range_step = 100000 - sql_attr_uint = forum_id - sql_ranged_throttle = 50 - sql_query_info = SELECT * FROM bb_topics WHERE topic_id = $id + sql_attr_uint = forum_id + sql_ranged_throttle = 50 + sql_query_info = SELECT * FROM bb_topics WHERE topic_id = $id +} + +source posts: torrentpier +{ + sql_query = \ + SELECT pt.post_id, pt.post_text, t.topic_title, t.topic_id, t.forum_id \ + FROM bb_posts_text pt \ + LEFT JOIN bb_topics t on pt.post_id = t.topic_first_post_id \ + WHERE pt.post_id BETWEEN $start AND $end + + sql_query_range = SELECT MIN(post_id), MAX(post_id) FROM bb_posts_text + sql_range_step = 100000 + + sql_attr_uint = topic_id + sql_attr_uint = forum_id + sql_ranged_throttle = 50 + sql_query_info = SELECT * FROM bb_posts_text WHERE post_id = $id +} + +source users: torrentpier +{ + sql_query = \ + SELECT user_id, username \ + FROM bb_users \ + WHERE user_id BETWEEN $start AND $end + + sql_query_range = SELECT (SELECT user_id FROM bb_users WHERE user_id = 1), MAX(user_id) FROM bb_users + sql_range_step = 1000 + sql_query_info = SELECT * FROM bb_users WHERE user_id = $id } index topics { - docinfo = extern - morphology = stem_enru - charset_type = utf-8 - charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42C->U+430..U+44C, U+42E..U+42F->U+44E..U+44F, U+430..U+44C, U+44E..U+44F, U+0401->U+0435, U+0451->U+0435, U+042D->U+0435, U+044D->U+0435 - min_prefix_len = 2 - min_infix_len = 0 - min_word_len = 1 - enable_star = 1 - html_strip = 1 - path = ./sphinx/data/topics - source = topics + docinfo = extern + morphology = stem_enru + charset_type = utf-8 + charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42C->U+430..U+44C, U+42E..U+42F->U+44E..U+44F, U+430..U+44C, U+44E..U+44F, U+0401->U+0435, U+0451->U+0435, U+042D->U+0435, U+044D->U+0435 + min_prefix_len = 2 + min_infix_len = 0 + min_word_len = 1 + enable_star = 1 + html_strip = 1 + path = ./sphinx/data/topics + source = topics +} + +index posts: topics +{ + path = ./sphinx/data/posts + source = posts +} + +index users: topics +{ + path = ./sphinx/data/users + source = users } indexer { - mem_limit = 256M + mem_limit = 256M } searchd { - listen = 127.0.0.1:3312 - log = ./sphinx/log/searchd.log - query_log = ./sphinx/log/query.log - read_timeout = 5 - max_children = 15 - max_matches = 5000 - pid_file = ./sphinx/searchd.pid + listen = 127.0.0.1:3312 + log = ./sphinx/log/searchd.log + query_log = ./sphinx/log/query.log + read_timeout = 5 + max_children = 15 + max_matches = 5000 + pid_file = ./sphinx/searchd.pid } \ No newline at end of file diff --git a/upload/config.php b/upload/config.php index 640872691..66bd551d0 100644 --- a/upload/config.php +++ b/upload/config.php @@ -57,8 +57,8 @@ $bb_cfg['css_ver'] = 1; // Increase number of revision after update $bb_cfg['tp_version'] = '2.1 Stable'; -$bb_cfg['tp_release_state'] = 'R250'; -$bb_cfg['tp_release_date'] = '23-08-2011'; +$bb_cfg['tp_release_state'] = 'R251'; +$bb_cfg['tp_release_date'] = '24-08-2011'; $bb_cfg['board_disabled_msg'] = 'форум временно отключен'; // 'forums temporarily disabled'; // show this msg if board has been disabled via ON/OFF trigger $bb_cfg['srv_overloaded_msg'] = "Извините, в данный момент сервер перегружен\nПопробуйте повторить запрос через несколько минут"; diff --git a/upload/includes/functions.php b/upload/includes/functions.php index 2f9b1a2c8..09f6e4a08 100644 --- a/upload/includes/functions.php +++ b/upload/includes/functions.php @@ -2608,19 +2608,19 @@ function log_sphinx_error ($err_type, $err_msg, $query = '') function get_title_match_topics ($title_match_sql, $limit = 500, $forum_ids = array()) { - global $bb_cfg, $sphinx, $userdata; + global $bb_cfg, $sphinx, $userdata, $title_match; - $topic_ids = array(); + $where_ids = array(); $limit = (int) $limit; - $forum_ids = (array) $forum_ids; + if($forum_ids) $forum_ids = array_diff($forum_ids, array(0 => 0)); $title_match_sql = encode_text_match($title_match_sql); if ($bb_cfg['search_engine_type'] == 'sphinx') { - global $user, $title_match; //$title_match - для поиска по постам и топикам (ещё не реализовано) - init_sphinx(); + $where = ($title_match) ? 'topics' : 'posts'; + $sphinx->SetServer($bb_cfg['sphinx_topic_titles_host'], $bb_cfg['sphinx_topic_titles_port']); $sphinx->SetLimits(0, $limit, $limit, $limit); if ($forum_ids) @@ -2631,18 +2631,17 @@ function get_title_match_topics ($title_match_sql, $limit = 500, $forum_ids = ar { $sphinx->SetMatchMode(SPH_MATCH_PHRASE); } - if ($result = $sphinx->Query($title_match_sql, 'topics', $userdata['username'] .' ('. CLIENT_IP .')')) + if ($result = $sphinx->Query($title_match_sql, $where, $userdata['username'] .' ('. CLIENT_IP .')')) { if (!empty($result['matches'])) { - $topic_ids = array_keys($result['matches']); + $where_ids = array_keys($result['matches']); } } else if ($error = $sphinx->GetLastError()) { if (strpos($error, 'errno=110')) { - bb_log(' ', 'misc/sphinx_conn_err_110'); bb_die('В данный момент поисковик недоступен

Попробуйте повторить запрос через несколько секунд'); } log_sphinx_error('ERR', $error, $title_match_sql); @@ -2654,18 +2653,30 @@ function get_title_match_topics ($title_match_sql, $limit = 500, $forum_ids = ar } else if ($bb_cfg['search_engine_type'] == 'mysql') { - $in_forums = ($forum_ids) ? "AND forum_id IN(". join(',', $forum_ids) .")" : ''; - $sql = " - SELECT topic_id - FROM ". BB_TOPICS ." - WHERE topic_title LIKE '%$title_match_sql%' - $in_forums - ORDER BY NULL - LIMIT $limit - "; + $where_forum = ($forum_ids) ? "AND forum_id IN(". join(',', $forum_ids) .")" : ''; + $search_bool_mode = ($bb_cfg['allow_search_in_bool_mode']) ? ' IN BOOLEAN MODE' : ''; + + if($title_match) + { + $where_id = 'topic_id'; + $sql = "SELECT topic_id FROM ". BB_TOPICS ." + WHERE MATCH (topic_title) AGAINST ('$title_match_sql'$search_bool_mode) + $where_forum + LIMIT $limit"; + } + else + { + $where_id = 'post_id'; + $sql = "SELECT p.post_id FROM ". BB_POSTS ." p, ". BB_POSTS_SEARCH ." ps + WHERE ps.post_id = p.post_id + AND MATCH (ps.search_words) AGAINST ('$title_match_sql'$search_bool_mode) + $where_forum + LIMIT $limit"; + } + foreach (DB()->fetch_rowset($sql) as $row) { - $topic_ids[] = $row['topic_id']; + $where_ids[] = $row[$where_id]; } } else @@ -2673,7 +2684,7 @@ function get_title_match_topics ($title_match_sql, $limit = 500, $forum_ids = ar bb_die('Поиск временно отключен'); } - return $topic_ids; + return $where_ids; } // для более корректного поиска по словам содержащим одиночную кавычку diff --git a/upload/search.php b/upload/search.php index 05c16eec8..a7b9e6866 100644 --- a/upload/search.php +++ b/upload/search.php @@ -54,7 +54,6 @@ $forums_tbl = BB_FORUMS .' f'; $posts_tbl = BB_POSTS .' p'; $posts_text_tbl = BB_POSTS_TEXT .' pt'; $posts_html_tbl = BB_POSTS_HTML .' h'; -$search_tbl = BB_POSTS_SEARCH .' ps'; $tr_snap_tbl = BB_BT_TRACKER_SNAP .' sn'; $topics_tbl = BB_TOPICS .' t'; $torrents_tbl = BB_BT_TORRENTS .' tor'; @@ -430,7 +429,6 @@ if ($post_mode) // FROM if ($join_t) $SQL['FROM'][] = $topics_tbl; if ($join_p) $SQL['FROM'][] = $posts_tbl; - if ($join_s) $SQL['FROM'][] = $search_tbl; if (!$SQL['FROM']) { @@ -440,7 +438,6 @@ if ($post_mode) // WHERE if ($join_p && $join_t) $SQL['WHERE'][] = "t.topic_id = p.topic_id"; - if ($join_s) $SQL['WHERE'][] = "ps.post_id = p.post_id"; if ($excluded_forums_csv) $SQL['WHERE'][] = "$tbl.forum_id NOT IN($excluded_forums_csv)"; @@ -455,7 +452,6 @@ if ($post_mode) if ($text_match_sql) { $search_match_topics_csv = ''; - if(!is_array($forum_selected)) $forum_selected = array(); $title_match_topics = get_title_match_topics($text_match_sql, 500, $forum_selected); if (!$search_match_topics_csv = join(',', $title_match_topics)) @@ -463,7 +459,9 @@ if ($post_mode) bb_die($lang['NO_SEARCH_MATCH']); } - $SQL['WHERE'][] = "$tbl.topic_id IN($search_match_topics_csv)"; + $where_id = ($title_match) ? 'topic_id' : 'post_id'; + + $SQL['WHERE'][] = "$tbl.$where_id IN($search_match_topics_csv)"; prevent_huge_searches($SQL); } @@ -600,7 +598,6 @@ else // FROM if ($join_t) $SQL['FROM'][] = $topics_tbl; - if ($join_s) $SQL['FROM'][] = $search_tbl; if ($join_p) $SQL['FROM'][] = $posts_tbl; if (!$SQL['FROM']) @@ -611,7 +608,6 @@ else // WHERE if ($join_p && $join_t) $SQL['WHERE'][] = "t.topic_id = p.topic_id"; - if ($join_s) $SQL['WHERE'][] = "ps.post_id = p.post_id"; if ($excluded_forums_csv) $SQL['WHERE'][] = "$tbl.forum_id NOT IN($excluded_forums_csv)"; @@ -627,7 +623,6 @@ else if ($text_match_sql) { $search_match_topics_csv = ''; - if(!is_array($forum_selected)) $forum_selected = array(); $title_match_topics = get_title_match_topics($text_match_sql, 500, $forum_selected); if (!$search_match_topics_csv = join(',', $title_match_topics)) @@ -635,7 +630,9 @@ else bb_die($lang['NO_SEARCH_MATCH']); } - $SQL['WHERE'][] = "$tbl.topic_id IN($search_match_topics_csv)"; + $where_id = ($title_match) ? 'topic_id' : 'post_id'; + + $SQL['WHERE'][] = "$tbl.$where_id IN($search_match_topics_csv)"; prevent_huge_searches($SQL); }