aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/functions_admin.php5
-rw-r--r--phpBB/includes/search/fulltext_phpbb.php39
-rwxr-xr-xphpBB/includes/search/search.php48
3 files changed, 69 insertions, 23 deletions
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index f58dfe95fa..980880874d 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -521,7 +521,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true)
}
$post_ids = $topic_ids = $forum_ids = array();
- $sql = 'SELECT post_id, topic_id, forum_id
+ $sql = 'SELECT post_id, poster_id, topic_id, forum_id
FROM ' . POSTS_TABLE . "
WHERE $where_type " . ((!is_array($where_ids)) ? "= $where_ids" : 'IN (' . implode(', ', $where_ids) . ')');
$result = $db->sql_query($sql);
@@ -529,6 +529,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true)
while ($row = $db->sql_fetchrow($result))
{
$post_ids[] = $row['post_id'];
+ $poster_ids[] = $row['poster_id'];
$topic_ids[] = $row['topic_id'];
$forum_ids[] = $row['forum_id'];
}
@@ -570,7 +571,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true)
trigger_error($error);
}
- $search->index_remove($where_ids);
+ $search->index_remove($post_ids, $poster_ids);
delete_attachments('post', $post_ids, false);
diff --git a/phpBB/includes/search/fulltext_phpbb.php b/phpBB/includes/search/fulltext_phpbb.php
index 517a586579..3dadc08466 100644
--- a/phpBB/includes/search/fulltext_phpbb.php
+++ b/phpBB/includes/search/fulltext_phpbb.php
@@ -163,9 +163,9 @@ class fulltext_phpbb extends search_backend
// NCRs like   etc.
$match[] = '#(&|&)[\#a-z0-9]+?;#i';
// Do not index code
- $match[] = '#\[code=?.*?(\:?[0-9a-z]{5,})\].*?\[\/code(\:?[0-9a-z]{5,})\]#is';
+ $match[] = '#\[code(?:=.*?)?(\:?[0-9a-z]{5,})\].*?\[\/code(\:?[0-9a-z]{5,})\]#is';
// BBcode
- $match[] = '#\[\/?[a-z\*\+\-]+=?.*?(\:?[0-9a-z]{5,})\]#';
+ $match[] = '#\[\/?[a-z\*\+\-]+(?:=.*?)?(\:?[0-9a-z]{5,})\]#';
// Filter out ; and # but not &#[0-9]+;
//$match[] = '#(&\#[0-9]+;)|;|\#|&#';
@@ -243,6 +243,7 @@ class fulltext_phpbb extends search_backend
$result_count = 0;
$id_ary = array();
+ $join_topic = ($type == 'posts') ? false : true;
// Build sql strings for sorting
$sql_sort = $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
$sql_sort_table = $sql_sort_join = '';
@@ -250,11 +251,10 @@ class fulltext_phpbb extends search_backend
{
case 'u':
$sql_sort_table = USERS_TABLE . ' u, ';
- $sql_sort_join = 'AND u.user_id = p.poster_id ';
+ $sql_sort_join = ' AND u.user_id = p.poster_id ';
break;
case 't':
- $sql_sort_table = ($type == 'posts') ? TOPICS_TABLE . ' t, ' : '';
- $sql_sort_join = ($type == 'posts') ? ' AND t.topic_id = p.topic_id ' : '';
+ $join_topic = true;
break;
case 'f':
$sql_sort_table = FORUMS_TABLE . ' f, ';
@@ -266,26 +266,31 @@ class fulltext_phpbb extends search_backend
switch ($fields)
{
case 'titleonly':
- $sql_match = ' AND m.title_match = 1';
+ $sql_match = ' AND m.title_match = 1 AND p.post_id = t.topic_first_post_id';
+ $join_topic = true;
break;
case 'msgonly':
$sql_match = ' AND m.title_match = 0';
break;
+ case 'firstpost':
+ $sql_match = ' AND p.post_id = t.topic_first_post_id';
+ $join_topic = true;
+ break;
default:
$sql_match = '';
}
$sql_select = ($type == 'posts') ? 'm.post_id' : 'DISTINCT t.topic_id';
- $sql_from = ($type == 'posts') ? '' : TOPICS_TABLE . ' t, ';
+ $sql_from = ($join_topic) ? TOPICS_TABLE . ' t, ' : '';
$field = ($type == 'posts') ? 'm.post_id' : 't.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 .= ($type == 'posts') ? '' : 'AND t.topic_id = p.topic_id';
+ $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 .= (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 .= (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;
// split the words into three arrays (AND, OR, NOT)
@@ -557,7 +562,7 @@ class fulltext_phpbb extends search_backend
$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_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
// Build sql strings for sorting
$sql_sort = $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
@@ -566,7 +571,7 @@ class fulltext_phpbb extends search_backend
{
case 'u':
$sql_sort_table = USERS_TABLE . ' u, ';
- $sql_sort_join = 'AND u.user_id = p.poster_id ';
+ $sql_sort_join = ' AND u.user_id = p.poster_id ';
break;
case 't':
$sql_sort_table = ($type == 'posts') ? TOPICS_TABLE . ' t, ' : '';
@@ -657,7 +662,7 @@ class fulltext_phpbb extends search_backend
*
* @param string $mode contains the post mode: edit, post, reply, quote ...
*/
- function index($mode, $post_id, &$message, &$subject)
+ function index($mode, $post_id, &$message, &$subject, $poster_id)
{
global $config, $db;
@@ -801,7 +806,7 @@ class fulltext_phpbb extends search_backend
}
// destroy cached search results containing any of the words removed or added
- $this->destroy_cache(array_unique(array_merge($words['add']['post'], $words['add']['title'], $words['del']['post'], $words['del']['post'])));
+ $this->destroy_cache(array_unique(array_merge($words['add']['post'], $words['add']['title'], $words['del']['post'], $words['del']['post'])), array($poster_id));
unset($unique_add_words);
unset($words);
@@ -811,7 +816,7 @@ class fulltext_phpbb extends search_backend
/**
* Removes entries from the wordmatch table for the specified post_ids
*/
- function index_remove($post_ids)
+ function index_remove($post_ids, $author_ids)
{
global $db;
@@ -820,6 +825,8 @@ class fulltext_phpbb extends search_backend
$db->sql_query($sql);
// SEARCH_WORD_TABLE will be updated by tidy()
+
+ $this->destroy_cache(array(), $author_ids);
}
/**
diff --git a/phpBB/includes/search/search.php b/phpBB/includes/search/search.php
index 6f31e88ca4..daa3d62a4d 100755
--- a/phpBB/includes/search/search.php
+++ b/phpBB/includes/search/search.php
@@ -82,7 +82,7 @@ class search_backend
if (!isset($match_synonym[$user->lang_name]))
{
- preg_match_all('#^\s+(\S+)\s+(\S+)\s+$#m', file_get_contents($user->lang_path . '/search_synonyms.txt'), $match);
+ preg_match_all('#^\s*(\S+)\s+(\S+)\s*$#m', file_get_contents($user->lang_path . '/search_synonyms.txt'), $match);
$match_synonym[$user->lang_name]['replace']= &$match[1];
$match_synonym[$user->lang_name]['match'] = &$match[2];
@@ -170,6 +170,12 @@ class search_backend
$length = min(sizeof($id_ary), $config['search_block_size']);
+ // nothing to cache so exit
+ if (!$length)
+ {
+ return;
+ }
+
$store_ids = array_slice($id_ary, 0, $length);
// create a new resultset if there is none for this search_key yet
@@ -190,7 +196,7 @@ class search_backend
'search_key' => $search_key,
'search_time' => time(),
'search_keywords' => $keywords,
- 'search_authors' => implode(' ', $author_ary)
+ 'search_authors' => ' ' . implode(' ', $author_ary) . ' '
);
$sql = 'INSERT INTO ' . SEARCH_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
@@ -218,9 +224,19 @@ class search_backend
}
}
+ $store_ids = array_combine($id_range, $store_ids);
+
// append the ids
- $store += array_combine($id_range, $store_ids);
- $cache->put('_search_results_' . $search_key, $store, $config['search_store_results']);
+ if (is_array($store_ids))
+ {
+ $store += $store_ids;
+ $cache->put('_search_results_' . $search_key, $store, $config['search_store_results']);
+
+ $sql = 'UPDATE ' . SEARCH_TABLE . '
+ SET search_time = ' . time() . '
+ WHERE search_key = \'' . $db->sql_escape($search_key) . '\'';
+ $db->sql_query($sql);
+ }
unset($store);
unset($store_ids);
@@ -230,10 +246,11 @@ class search_backend
/**
* Removes old entries from the search results table and removes searches with keywords that contain a word in $words.
*/
- function destroy_cache($words)
+ function destroy_cache($words, $authors = false)
{
global $db, $cache, $config;
+ // clear all searches that searched for the specified words
if (sizeof($words))
{
$sql_where = '';
@@ -254,6 +271,27 @@ class search_backend
$db->sql_freeresult();
}
+ // clear all searches that searched for the specified authors
+ if (is_array($authors) && sizeof($authors))
+ {
+ $sql_where = '';
+ foreach ($authors as $author)
+ {
+ $sql_where .= (($sql_where) ? ' OR ' : '') . 'search_authors LIKE \'% ' . (int) $author . ' %\'';
+ }
+
+ $sql = 'SELECT search_key
+ FROM ' . SEARCH_TABLE . "
+ WHERE $sql_where";
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $cache->destroy('_search_results_' . $row['search_key']);
+ }
+ $db->sql_freeresult();
+ }
+
$sql = 'DELETE
FROM ' . SEARCH_TABLE . '
WHERE search_time < ' . (time() - $config['search_store_results']);