поиск по сообщениям git-svn-id: https://torrentpier2.googlecode.com/svn/trunk@251 a8ac35ab-4ca4-ca47-4c2d-a49a94f06293
This commit is contained in:
nanosimbiot 2011-08-24 03:37:40 +00:00
commit bd14b5b363
4 changed files with 109 additions and 60 deletions

View file

@ -3,8 +3,8 @@ source torrentpier
type = mysql
sql_host = localhost
sql_user = user
sql_pass = user
sql_db = forum
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
@ -26,6 +26,35 @@ source topics: torrentpier
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
@ -41,6 +70,18 @@ index 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

View file

@ -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Попробуйте повторить запрос через несколько минут";

View file

@ -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('В данный момент поисковик недоступен<br /><br />Попробуйте повторить запрос через несколько секунд');
}
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;
}
// для более корректного поиска по словам содержащим одиночную кавычку

View file

@ -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);
}