diff options
author | Nils Adermann <naderman@naderman.de> | 2006-05-28 19:06:21 +0000 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2006-05-28 19:06:21 +0000 |
commit | ebf4f4ec8e787153e16cc6cec6fc5fefadc97107 (patch) | |
tree | 1dd320eb12a0915a11565bbb0b64c699ca6a6e61 /phpBB/includes | |
parent | b84ebb999d1e7f0340fbb6ff7fbf113be9a81816 (diff) | |
download | forums-ebf4f4ec8e787153e16cc6cec6fc5fefadc97107.tar forums-ebf4f4ec8e787153e16cc6cec6fc5fefadc97107.tar.gz forums-ebf4f4ec8e787153e16cc6cec6fc5fefadc97107.tar.bz2 forums-ebf4f4ec8e787153e16cc6cec6fc5fefadc97107.tar.xz forums-ebf4f4ec8e787153e16cc6cec6fc5fefadc97107.zip |
- 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
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/acp/acp_search.php | 10 | ||||
-rw-r--r-- | phpBB/includes/search/fulltext_mysql.php | 1 | ||||
-rwxr-xr-x | phpBB/includes/search/fulltext_native.php | 36 | ||||
-rwxr-xr-x | phpBB/includes/search/search.php | 57 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_main.php | 2 |
5 files changed, 52 insertions, 54 deletions
diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index f9726a7df8..c6bbbf18f7 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -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, diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 8b2abde4f5..bd619a9ffe 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -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; diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 2593136f10..34a832d6ef 100755 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -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]); } diff --git a/phpBB/includes/search/search.php b/phpBB/includes/search/search.php index 16d87947d2..28f805bca5 100755 --- a/phpBB/includes/search/search.php +++ b/phpBB/includes/search/search.php @@ -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(); - } - - 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]; + // include the file containing ignore words + include("{$user->lang_path}/search_ignore_words.$phpEx"); - 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); diff --git a/phpBB/includes/ucp/ucp_main.php b/phpBB/includes/ucp/ucp_main.php index 7421cdd53f..336c050fad 100644 --- a/phpBB/includes/ucp/ucp_main.php +++ b/phpBB/includes/ucp/ucp_main.php @@ -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&author=" . urlencode($user->data['username']) . "&sr=posts" : '', + 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? "{$phpbb_root_path}search.$phpEx$SID&author_id=" . $user->data['user_id'] . "&sr=posts" : '', ) ); break; |