1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

- added search by author_id to solve problems with looking up posts of users with a name containing wildcards

- user based flood control (seperate limits for users and guests) [Bug #1357]
- inform the user about ignored words if he receives a "no words specified" message
- solve problems with the number of entries per page [Bug #1973]
- different height for popup window ["Bug" #1814]
- speed improvements for posting and search reindexing in fulltext_native
 -> use php files for ignore words and synonyms


git-svn-id: file:///svn/phpbb/trunk@5981 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Nils Adermann
2006-05-28 19:06:21 +00:00
parent b84ebb999d
commit ebf4f4ec8e
21 changed files with 553 additions and 472 deletions

View File

@@ -47,11 +47,12 @@ class acp_search
$search_types = $this->get_search_types();
$settings = array(
'search_interval' => 'float',
'load_search' => 'bool',
'limit_search_load' => 'float',
'search_interval' => 'float',
'search_anonymous_interval' => 'float',
'load_search' => 'bool',
'limit_search_load' => 'float',
'min_search_author_chars' => 'integer',
'search_store_results' => 'integer',
'search_store_results' => 'integer',
);
$search = null;
@@ -168,6 +169,7 @@ class acp_search
'LIMIT_SEARCH_LOAD' => (float) $config['limit_search_load'],
'MIN_SEARCH_AUTHOR_CHARS' => (int) $config['min_search_author_chars'],
'SEARCH_INTERVAL' => (float) $config['search_interval'],
'SEARCH_GUEST_INTERVAL' => (float) $config['search_anonymous_interval'],
'SEARCH_STORE_RESULTS' => (int) $config['search_store_results'],
'S_SEARCH_TYPES' => $search_options,

View File

@@ -160,6 +160,7 @@ class fulltext_mysql extends search_backend
if (sizeof($this->split_words))
{
$this->split_words = array_values($this->split_words);
sort($this->split_words);
return true;
}
return false;

View File

@@ -88,14 +88,17 @@ class fulltext_native extends search_backend
$this->split_words = array_diff($this->split_words, $this->ignore_words);
}
if (sizeof($this->replace_synonym))
if (sizeof($this->match_synonym))
{
$this->split_words = str_replace($this->replace_synonym, $this->match_synonym, $this->split_words);
$this->split_words = str_replace($this->match_synonym, $this->replace_synonym, $this->split_words);
}
$prefixes = array('+', '-', '|');
$prefixed = false;
$in_words = '';
$lengths = $this->get_word_lengths($this->split_words);
foreach ($this->split_words as $i => $word)
{
if (in_array($word, $prefixes))
@@ -105,8 +108,7 @@ class fulltext_native extends search_backend
}
// check word length
$clean_len = $this->word_length($word);
if (($clean_len < $config['fulltext_native_min_chars']) || ($clean_len > $config['fulltext_native_max_chars']))
if (($lengths[$i] < $config['fulltext_native_min_chars']) || ($lengths[$i] > $config['fulltext_native_max_chars']))
{
if ($prefixed)
{
@@ -124,6 +126,8 @@ class fulltext_native extends search_backend
$prefixed = false;
}
unset($lengths);
if ($in_words)
{
// identify common words and ignore them
@@ -151,17 +155,23 @@ class fulltext_native extends search_backend
if (sizeof($this->split_words))
{
$this->split_words = array_values($this->split_words);
sort($this->split_words);
return true;
}
return false;
}
/**
* Returns the string length but it counts multibyte characters as single characters and ignores "*"
* Returns any array of string lengths for the given array of strings
* It counts multibyte entities as single characters and ignores "*"
*
* @param array $words an array of strings
*
* @return Array of string lengths
*/
function word_length($word)
function get_word_lengths($words)
{
return strlen(str_replace('*', '', preg_replace('#&\#[0-9]+;#', 'x', $word)));
return array_map('strlen', str_replace('*', '', preg_replace('#&\#[0-9]+;#', 'x', $words)));
}
/**
@@ -210,17 +220,19 @@ class fulltext_native extends search_backend
$text = array_diff($text, $this->ignore_words);
}
if (sizeof($this->replace_synonym))
if (sizeof($this->match_synonym))
{
$text = str_replace($this->replace_synonym, $this->match_synonym, $text);
$text = str_replace($this->match_synonym, $this->replace_synonym, $text);
}
// remove too short or too long words
$text = array_values($text);
$text = array_map('trim', array_values($text));
$lengths = $this->get_word_lengths($text);
for ($i = 0, $n = sizeof($text); $i < $n; $i++)
{
$text[$i] = trim($text[$i]);
if ($this->word_length($text[$i]) < $config['fulltext_native_min_chars'] || $this->word_length($text[$i]) > $config['fulltext_native_max_chars'])
if ($lengths[$i] < $config['fulltext_native_min_chars'] || $lengths[$i] > $config['fulltext_native_max_chars'])
{
unset($text[$i]);
}

View File

@@ -43,31 +43,21 @@ class search_backend
}
/**
* Stores a list of common words that should be ignored in $this->ignore_words and caches them
* Retrieves a language dependend list of words that should be ignored by the search
*/
function get_ignore_words()
{
if (!sizeof($this->ignore_words))
{
global $user, $cache;
global $user, $phpEx;
$ignore_words = $cache->get('_ignore_words');
$words = array();
if (!$ignore_words)
{
$ignore_words = array();
}
// include the file containing ignore words
include("{$user->lang_path}/search_ignore_words.$phpEx");
if (!isset($ignore_words[$user->lang_name]))
{
$ignore_words[$user->lang_name] = explode("\n", str_replace("\n\n", "\n", str_replace("\r", "\n", file_get_contents($user->lang_path . '/search_ignore_words.txt'))));
$cache->put('_ignore_words', $ignore_words, 7200);
}
$this->ignore_words = $ignore_words[$user->lang_name];
unset($ignore_words);
$this->ignore_words = $words;
unset($words);
}
}
@@ -78,28 +68,17 @@ class search_backend
{
if (!sizeof($this->match_synonym))
{
global $user, $cache;
global $user, $phpEx;
$match_synonym = $cache->get('_match_synonym');
$synonyms = array();
if (!$match_synonym)
{
$match_synonym = array();
}
// include the file containing synonyms
include("{$user->lang_path}/search_synonyms.$phpEx");
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);
$match_synonym[$user->lang_name]['replace']= &$match[1];
$match_synonym[$user->lang_name]['match'] = &$match[2];
$this->match_synonym = array_keys($synonyms);
$this->replace_synonym = array_values($synonyms);
$cache->put('_match_synonym', $match_synonym, 7200);
}
$this->replace_synonym = $match_synonym[$user->lang_name]['replace'];
$this->match_synonym = $match_synonym[$user->lang_name]['match'];
unset($match_synonym);
unset($synonyms);
}
}
@@ -173,7 +152,7 @@ class search_backend
*/
function save_ids($search_key, $keywords, $author_ary, $result_count, &$id_ary, $start, $sort_dir)
{
global $cache, $config, $db;
global $cache, $config, $db, $user;
$length = min(sizeof($id_ary), $config['search_block_size']);
@@ -211,7 +190,11 @@ class search_backend
}
$db->sql_freeresult($result);
}
set_config('last_search_time', time());
//set_config('last_search_time', time());
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_last_search = ' . time() . '
WHERE user_id = ' . $user->data['user_id'];
$db->sql_query($sql);
$store = array(-1 => $result_count, -2 => $sort_dir);
$id_range = range($start, $start + $length - 1);

View File

@@ -173,7 +173,7 @@ class ucp_main
// 'S_GROUP_OPTIONS' => $group_options,
'S_SHOW_ACTIVITY' => ($config['load_user_activity']) ? true : false,
'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? "{$phpbb_root_path}search.$phpEx$SID&amp;author=" . urlencode($user->data['username']) . "&amp;sr=posts" : '',
'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? "{$phpbb_root_path}search.$phpEx$SID&amp;author_id=" . $user->data['user_id'] . "&amp;sr=posts" : '',
)
);
break;