aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2006-03-15 23:20:04 +0000
committerNils Adermann <naderman@naderman.de>2006-03-15 23:20:04 +0000
commit7fd17b8251879e6f4592d7c4b5ebdc9faa405429 (patch)
treea59e660e49183d63f2d1816c38952ad662bf2c88 /phpBB/includes
parente221b03b957e49cb2248b91af303c453c4d1e975 (diff)
downloadforums-7fd17b8251879e6f4592d7c4b5ebdc9faa405429.tar
forums-7fd17b8251879e6f4592d7c4b5ebdc9faa405429.tar.gz
forums-7fd17b8251879e6f4592d7c4b5ebdc9faa405429.tar.bz2
forums-7fd17b8251879e6f4592d7c4b5ebdc9faa405429.tar.xz
forums-7fd17b8251879e6f4592d7c4b5ebdc9faa405429.zip
- removed search settings from load page
- no need to retrieve mysql information on every page => removed (fulltext_mysql) - added init() method to search plugins which is called when the search backend is changed - optional create/delete index functions for methods which don't need to loop through all posts (like fulltext_mysql) - index statistic functions for search plugins, displayed on acp search index page - only remove words above 60% (fulltext_phpbb) - added acp method to search plugins so they can display config options specific to a certain search backend - renamed fulltext_phpbb specific options to make clear that they are a part of the plugin - reordered lang entries for the load settings section added acp_search.php: - settings: general options / search backend / backend specific options - index: statistics / delete index / create index (progress popup while processing) git-svn-id: file:///svn/phpbb/trunk@5636 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/acp/acp_board.php37
-rw-r--r--phpBB/includes/acp/acp_search.php522
-rw-r--r--phpBB/includes/search/fulltext_mysql.php167
-rw-r--r--phpBB/includes/search/fulltext_phpbb.php96
4 files changed, 770 insertions, 52 deletions
diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php
index d386103df7..d39316226b 100644
--- a/phpBB/includes/acp/acp_board.php
+++ b/phpBB/includes/acp/acp_board.php
@@ -165,15 +165,7 @@ class acp_board
'load_moderators' => array('lang' => 'YES_MODERATORS', 'type' => 'radio:yes_no', 'explain' => false),
'load_jumpbox' => array('lang' => 'YES_JUMPBOX', 'type' => 'radio:yes_no', 'explain' => false),
'load_user_activity' => array('lang' => 'LOAD_USER_ACTIVITY','type' => 'radio:yes_no', 'explain' => true),
- 'load_tplcompile' => array('lang' => 'RECOMPILE_TEMPLATES', 'type' => 'radio:yes_no', 'explain' => true),
-
- 'legend3' => 'SEARCH_SETTINGS',
- 'load_search' => array('lang' => 'YES_SEARCH', 'type' => 'radio:yes_no', 'explain' => true),
- 'search_interval' => array('lang' => 'SEARCH_INTERVAL', 'type' => 'text:3:4', 'explain' => true),
- 'search_type' => array('lang' => 'SEARCH_TYPE', 'type' => 'select', 'method' => 'select_search_type', 'explain' => true),
- 'load_search_upd' => array('lang' => 'YES_SEARCH_UPDATE', 'type' => 'radio:yes_no', 'explain' => true),
- 'min_search_chars' => array('lang' => 'MIN_SEARCH_CHARS', 'type' => 'text:3:3', 'explain' => true),
- 'max_search_chars' => array('lang' => 'MAX_SEARCH_CHARS', 'type' => 'text:3:3', 'explain' => true)
+ 'load_tplcompile' => array('lang' => 'RECOMPILE_TEMPLATES', 'type' => 'radio:yes_no', 'explain' => true)
)
);
break;
@@ -571,33 +563,6 @@ class acp_board
return h_radio('config[board_disable]', $radio_ary, $value) . '<br /><input id="' . $key . '" type="text" name="config[board_disable_msg]" maxlength="255" size="40" value="' . $this->new_config['board_disable_msg'] . '" />';
}
-
- function select_search_type($selected_type, $key = '')
- {
- global $phpbb_root_path, $phpEx;
-
- $search_plugins = array();
-
- $dp = opendir($phpbb_root_path . 'includes/search');
- while (($file = readdir($dp)) !== false)
- {
- if ((preg_match('#\.' . $phpEx . '$#', $file)) && ($file != "search.$phpEx"))
- {
- $search_plugins[] = preg_replace('#^(.*?)\.' . $phpEx . '$#', '\1', $file);
- }
- }
-
- sort($search_plugins);
-
- $search_select = '';
- foreach ($search_plugins as $type)
- {
- $selected = ($selected_type == $type) ? ' selected="selected"' : '';
- $search_select .= '<option value="' . $type . '"' . $selected . '>' . ucfirst(strtolower(str_replace('_', ' ', $type))) . '</option>';
- }
-
- return $search_select;
- }
}
/**
diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php
new file mode 100644
index 0000000000..e174f9712e
--- /dev/null
+++ b/phpBB/includes/acp/acp_search.php
@@ -0,0 +1,522 @@
+<?php
+/**
+*
+* @package acp
+* @version $Id$
+* @copyright (c) 2005 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @package acp
+*/
+class acp_search
+{
+ var $u_action;
+ var $state;
+ var $search;
+ var $max_post_id;
+ var $batch_size = 4000;
+
+ function main($id, $mode)
+ {
+ global $user;
+
+ $user->add_lang('acp/search');
+
+ switch ($mode)
+ {
+ case 'settings':
+ $this->settings($id, $mode);
+ break;
+
+ case 'index':
+ $this->index($id, $mode);
+ break;
+ }
+ }
+
+ function settings($id, $mode)
+ {
+ global $db, $user, $auth, $template, $cache;
+ global $config, $SID, $phpbb_root_path, $phpbb_admin_path, $phpEx;
+
+ $submit = (isset($_POST['submit'])) ? true : false;
+
+ $search_types = $this->get_search_types();
+
+ $settings = array(
+ 'search_interval' => 'integer',
+ 'load_search' => 'bool',
+ 'limit_search_load' => 'float',
+ 'min_search_author_chars' => 'integer',
+ 'search_store_results' => 'integer',
+ );
+
+ $search = null;
+ $error = false;
+ $search_options = '';
+ foreach ($search_types as $type)
+ {
+ if ($this->init_search($type, $search, $error))
+ {
+ continue;
+ }
+
+ $name = ucfirst(strtolower(str_replace('_', ' ', $type)));
+ $selected = ($config['search_type'] == $type) ? ' selected="selected"' : '';
+ $search_options .= '<option value="' . $type . '"' . $selected . '>' . $name . '</option>';
+
+ if (method_exists($search, 'acp'))
+ {
+ $vars = $search->acp();
+
+ if (!$submit)
+ {
+ $template->assign_block_vars('backend', array(
+ 'NAME' => $name,
+ 'SETTINGS' => $vars['tpl'])
+ );
+ }
+ else if (is_array($vars['config']))
+ {
+ $settings = array_merge($settings, $vars['config']);
+ }
+ }
+ }
+ unset($search);
+ unset($error);
+
+ $cfg_array = (isset($_REQUEST['config'])) ? request_var('config', array('' => '')) : array();
+ $updated = request_var('updated', false);
+
+ foreach ($settings as $config_name => $var_type)
+ {
+ if (!isset($cfg_array[$config_name]))
+ {
+ continue;
+ }
+
+ $config_value = $cfg_array[$config_name];
+ settype($config_value, $var_type);
+
+ if ($submit)
+ {
+ set_config($config_name, $config_value);
+ $updated = true;
+ }
+ }
+
+ if ($submit)
+ {
+ $extra_message = '';
+ if ($updated)
+ {
+ add_log('admin', 'LOG_CONFIG_SEARCH');
+ }
+
+ if (isset($cfg_array['search_type']) && in_array($cfg_array['search_type'], $search_types, true) && ($cfg_array['search_type'] != $config['search_type']))
+ {
+ $search = null;
+ $error = false;
+
+ if (!$this->init_search($cfg_array['search_type'], $search, $error))
+ {
+ if (confirm_box(true))
+ {
+ if (!method_exists($search, 'init') || !($error = $search->init()))
+ {
+ set_config('search_type', $cfg_array['search_type']);
+
+ if (!$updated)
+ {
+ add_log('admin', 'LOG_CONFIG_SEARCH');
+ }
+ $extra_message = '<br />' . $user->lang['SWITCHED_SEARCH_BACKEND'] . "<br /><a href=\"{$phpbb_admin_path}index.$phpEx$SID&amp;i=search&amp;mode=index\">&raquo; " . $user->lang['GO_TO_SEARCH_INDEX'] . '</a>';
+ }
+ else
+ {
+ trigger_error($error);
+ }
+ }
+ else
+ {
+ confirm_box(false, $user->lang['CONFIRM_SEARCH_BACKEND'], build_hidden_fields(array(
+ 'i' => $id,
+ 'mode' => $mode,
+ 'submit' => true,
+ 'updated' => $updated,
+ 'config' => array('search_type' => $cfg_array['search_type']),
+ )));
+ }
+ }
+ else
+ {
+ trigger_error($error);
+ }
+ }
+
+ trigger_error($user->lang['CONFIG_UPDATED'] . $extra_message . adm_back_link($this->u_action));
+ }
+ unset($cfg_array);
+
+ $this->tpl_name = 'acp_search';
+ $this->page_title = 'ACP_SEARCH_SETTINGS';
+
+ $template->assign_vars(array(
+ 'LIMIT_SEARCH_LOAD' => $config['limit_search_load'],
+ 'MIN_SEARCH_AUTHOR_CHARS' => $config['min_search_author_chars'],
+ 'SEARCH_INTERVAL' => $config['search_interval'],
+ 'SEARCH_STORE_RESULTS' => $config['search_store_results'],
+
+ 'S_SEARCH_TYPES' => $search_options,
+ 'S_YES_SEARCH' => (bool) $config['load_search'],
+ 'S_SETTINGS' => true,
+
+ 'U_ACTION' => $this->u_action)
+ );
+ }
+
+ function index($id, $mode)
+ {
+ global $db, $user, $auth, $template, $cache;
+ global $config, $SID, $phpbb_root_path, $phpbb_admin_path, $phpEx;
+
+ $action = (isset($_REQUEST['action']) && is_array($_REQUEST['action'])) ? key(request_var('action', array('' => false))) : request_var('action', '');
+ $this->state = explode(',', $config['search_indexing_state']);
+
+ if ($action)
+ {
+ switch ($action)
+ {
+ case 'progress_bar':
+ $type = request_var('type', '');
+ $this->display_progress_bar($type);
+ break;
+
+ case 'delete':
+ $this->state[1] = 'delete';
+ break;
+
+ case 'create':
+ $this->state[1] = 'create';
+ break;
+
+ default:
+ trigger_error('NO_ACTION');
+ }
+
+ if (empty($this->state[0]))
+ {
+ $this->state[0] = request_var('search_type', '');
+ }
+
+ $this->search = null;
+ $error = false;
+ if ($this->init_search($this->state[0], $this->search, $error))
+ {
+ trigger_error($error);
+ }
+
+ $action = &$this->state[1];
+
+ @set_time_limit(0);
+
+ $this->max_post_id = $this->get_max_post_id();
+
+ $post_counter = (isset($this->state[2])) ? $this->state[2] : 0;
+ $this->state[2] = &$post_counter;
+ $this->save_state();
+
+ if ($action == 'delete')
+ {
+ if (method_exists($this->search, 'delete_index'))
+ {
+ // pass a reference to myself so the $search object can make use of save_state() and attributes
+ $this->search->delete_index($this, $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=delete");
+ }
+ else
+ {
+ $sql = 'SELECT post_id, poster_id
+ FROM ' . POSTS_TABLE . '
+ WHERE post_id >= ' . (int) ($post_counter + 1) . '
+ AND post_id < ' . (int) ($post_counter + $this->batch_size);
+ $result = $db->sql_query($sql);
+
+ $ids = $posters = array();
+ while (false !== ($row = $db->sql_fetchrow($result)))
+ {
+ $ids[] = $row['post_id'];
+ $posters[] = $row['poster_id'];
+ }
+ $db->sql_freeresult($result);
+
+ if (sizeof($ids))
+ {
+ $this->search->index_remove($ids, $posters);
+ }
+
+ $post_counter += $this->batch_size;
+
+ // save the current state
+ $this->save_state();
+
+ if ($post_counter <= $this->max_post_id)
+ {
+ redirect($phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=delete", 3);
+ }
+ }
+
+ $this->search->tidy();
+
+ $this->state = array('');
+ $this->save_state();
+
+ /**
+ * @todo remove Javascript
+ */
+ trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action) . '<script language="javascript" type="text/javascript">
+ <!--
+ close_waitscreen = 1;
+ //-->
+ </script>');
+ }
+ else
+ {
+ if (method_exists($this->search, 'create_index'))
+ {
+ // pass a reference to myself so the $search object can make use of save_state() and attributes
+ $this->search->create_index($this, $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=create");
+ }
+ else
+ {
+ $sql = 'SELECT post_id, post_subject, post_text, poster_id
+ FROM ' . POSTS_TABLE . '
+ WHERE post_id >= ' . (int) ($post_counter + 1) . '
+ AND post_id < ' . (int) ($post_counter + $this->batch_size);
+ $result = $db->sql_query($sql);
+
+ while (false !== ($row = $db->sql_fetchrow($result)))
+ {
+ $this->search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id']);
+ }
+ $db->sql_freeresult($result);
+
+ $post_counter += $this->batch_size;
+
+ // save the current state
+ $this->save_state();
+
+ if ($post_counter <= $this->max_post_id)
+ {
+ redirect($phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=create", 3);
+ }
+ }
+
+ $this->search->tidy();
+
+ $this->state = array('');
+ $this->save_state();
+
+ /**
+ * @todo remove Javascript
+ */
+ trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action) . '<script language="javascript" type="text/javascript">
+ <!--
+ close_waitscreen = 1;
+ //-->
+ </script>');
+ }
+ }
+
+ $search_types = $this->get_search_types();
+
+ $search = null;
+ $error = false;
+ $search_options = '';
+ foreach ($search_types as $type)
+ {
+ if ($this->init_search($type, $search, $error) || !method_exists($search, 'index_created'))
+ {
+ continue;
+ }
+
+ $name = ucfirst(strtolower(str_replace('_', ' ', $type)));
+
+ $data = array();
+ if (method_exists($search, 'index_stats'))
+ {
+ $data = $search->index_stats();
+ }
+
+ $statistics = array();
+ foreach ($data as $statistic => $value)
+ {
+ $n = sizeof($statistics);
+ if ($n && sizeof($statistics[$n - 1]) < 3)
+ {
+ $statistics[$n - 1] += array('statistic_2' => $statistic, 'value_2' => $value);
+ }
+ else
+ {
+ $statistics[] = array('statistic_1' => $statistic, 'value_1' => $value);
+ }
+ }
+
+ $template->assign_block_vars('backend', array(
+ 'L_NAME' => $name,
+ 'NAME' => $type,
+
+ 'S_ACTIVE' => ($type == $config['search_type']) ? true : false,
+ 'S_HIDDEN_FIELDS' => build_hidden_fields(array('search_type' => $type)),
+ 'S_INDEXED' => (bool) $search->index_created(),
+ 'S_STATS' => (bool) sizeof($statistics))
+ );
+
+ foreach ($statistics as $statistic)
+ {
+ $template->assign_block_vars('backend.data', array(
+ 'STATISTIC_1' => $statistic['statistic_1'],
+ 'VALUE_1' => $statistic['value_1'],
+ 'STATISTIC_2' => (isset($statistic['statistic_2'])) ? $statistic['statistic_2'] : '',
+ 'VALUE_2' => (isset($statistic['value_2'])) ? $statistic['value_2'] : '')
+ );
+ }
+ }
+ unset($search);
+ unset($error);
+ unset($statistics);
+ unset($data);
+
+ $this->tpl_name = 'acp_search';
+ $this->page_title = 'ACP_SEARCH_INDEX';
+
+ $template->assign_vars(array(
+ 'S_INDEX' => true,
+ 'U_ACTION' => $this->u_action,
+ 'U_PROGRESS_BAR' => $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=progress_bar") // don't use &amp; here
+ );
+
+ if (isset($this->state[1]))
+ {
+ $template->assign_vars(array(
+ 'S_CONTINUE_INDEXING' => $this->state[1],
+ 'U_CONTINUE_INDEXING' => $phpbb_admin_path . "index.$phpEx$SID&amp;i=$id&amp;mode=$mode&amp;action=" . $this->state[1],
+ 'L_CONTINUE' => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING'] : $user->lang['CONTINUE_INDEX_DELETING'],
+ 'L_CONTINUE_EXPLAIN' => ($this->state[1] == 'create') ? $user->lang['CONTINUE_INDEXING_EXPLAIN'] : $user->lang['CONTINUE_INDEX_DELETING_EXPLAIN'])
+ );
+ }
+ }
+
+ function display_progress_bar($type)
+ {
+ global $template, $user;
+ adm_page_header('PROGRESS_BAR');
+
+ $template->set_filenames(array(
+ 'body' => 'search_index_progress_bar.html')
+ );
+
+ $template->assign_vars(array(
+ 'L_PROGRESS' => ($type == 'create') ? $user->lang['INDEXING_IN_PROGRESS'] : $user->lang['DELETING_INDEX_IN_PROGRESS'],
+ 'L_PROGRESS_EXPLAIN' => ($type == 'create') ? $user->lang['INDEXING_IN_PROGRESS_EXPLAIN'] : $user->lang['DELETING_INDEX_IN_PROGRESS_EXPLAIN'])
+ );
+
+ adm_page_footer();
+ }
+
+ function get_search_types()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $search_types = array();
+
+ $dp = opendir($phpbb_root_path . 'includes/search');
+ while (($file = readdir($dp)) !== false)
+ {
+ if ((preg_match('#\.' . $phpEx . '$#', $file)) && ($file != "search.$phpEx"))
+ {
+ $search_types[] = preg_replace('#^(.*?)\.' . $phpEx . '$#', '\1', $file);
+ }
+ }
+ sort($search_types);
+
+ return $search_types;
+ }
+
+ function get_max_post_id()
+ {
+ global $db;
+
+ $sql = 'SELECT MAX(post_id) as max_post_id
+ FROM '. POSTS_TABLE;
+ $result = $db->sql_query($sql);
+
+ return $db->sql_fetchfield('max_post_id', 0, $result);
+ }
+
+ function save_state($state = false)
+ {
+ if ($state)
+ {
+ $this->state = $state;
+ }
+
+ ksort($this->state);
+
+ set_config('search_indexing_state', implode(',', $this->state), true);
+ }
+
+ /**
+ * Initialises a search backend object
+ *
+ * @return false if no error occured else an error message
+ */
+ function init_search($type, &$search, &$error)
+ {
+ global $phpbb_root_path, $phpEx, $user;
+
+ if (!preg_match('#^\w+$#', $type) || !file_exists("{$phpbb_root_path}includes/search/$type.$phpEx"))
+ {
+ $error = $user->lang['NO_SUCH_SEARCH_MODULE'];
+ return $error;
+ }
+
+ include_once("{$phpbb_root_path}includes/search/$type.$phpEx");
+
+ $error = false;
+ $search = new $type($error);
+
+ return $error;
+ }
+}
+
+/**
+* @package module_install
+*/
+class acp_search_info
+{
+ function module()
+ {
+ return array(
+ 'filename' => 'acp_search',
+ 'title' => 'ACP_SEARCH',
+ 'version' => '1.0.0',
+ 'modes' => array(
+ 'settings' => array('title' => 'ACP_SEARCH_SETTINGS', 'auth' => 'acl_a_server'),
+ 'index' => array('title' => 'ACP_SEARCH_INDEX', 'auth' => 'acl_a_server'),
+ ),
+ );
+ }
+
+ function install()
+ {
+ }
+
+ function uninstall()
+ {
+ }
+}
+
+?> \ No newline at end of file
diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php
index 26ca4a6e0d..3d5381e2bc 100644
--- a/phpBB/includes/search/fulltext_mysql.php
+++ b/phpBB/includes/search/fulltext_mysql.php
@@ -11,7 +11,7 @@
/**
* @ignore
*/
-include($phpbb_root_path . 'includes/search/search.' . $phpEx);
+include_once($phpbb_root_path . 'includes/search/search.' . $phpEx);
/**
* @package search
@@ -20,30 +20,49 @@ include($phpbb_root_path . 'includes/search/search.' . $phpEx);
*/
class fulltext_mysql extends search_backend
{
+ var $stats;
+
function fulltext_mysql(&$error)
{
- global $db;
+ $error = false;
+ }
- /**
- * @todo Move some of this to ACP
- * @todo Add SET SESSION ft_stopword_file = '' to ACP?
- */
+ /**
+ * Checks for correct MySQL version and stores max/min word length in the config
+ */
+ function init()
+ {
+ global $db, $user;
- $result = $db->sql_query('SELECT VERSION() AS mysql_version', 7200);
- $version = ($row = $db->sql_fetchrow($result)) ? $row['mysql_version'] : '';
+ if (strpos(SQL_LAYER, 'mysql') === false)
+ {
+ return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_VERSION'];
+ }
+
+ $result = $db->sql_query('SELECT VERSION() AS mysql_version');
+ $version = $db->sql_fetchfield('mysql_version', 0, $result);
$db->sql_freeresult($result);
+ if (!preg_match('#^4|5|6#s', $version))
+ {
+ return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_VERSION'];
+ }
+
$sql = 'SHOW VARIABLES
LIKE \'ft\_%\'';
- $result = $db->sql_query($sql, 7200);
+ $result = $db->sql_query($sql);
+ $mysql_info = array();
while ($row = $db->sql_fetchrow($result))
{
- $this->mysql_info[$row['Variable_name']] = $row['Value'];
+ $mysql_info[$row['Variable_name']] = $row['Value'];
}
$db->sql_freeresult($result);
- $error = (!preg_match('#^4|5|6#s', $version)) ? true : false;
+ set_config('fulltext_mysql_max_word_len', $mysql_info['ft_max_word_len']);
+ set_config('fulltext_mysql_min_word_len', $mysql_info['ft_min_word_len']);
+
+ return false;
}
/**
@@ -100,7 +119,7 @@ class fulltext_mysql extends search_backend
// check word length
$clean_len = strlen(str_replace('*', '', $clean_word));
- if (($clean_len < $this->mysql_info['ft_min_word_len']) || ($clean_len > $this->mysql_info['ft_max_word_len']))
+ if (($clean_len < $config['fulltext_mysql_min_word_len']) || ($clean_len > $config['fulltext_mysql_max_word_len']))
{
$this->common_words[] = $word;
unset($this->split_words[$i]);
@@ -146,7 +165,7 @@ class fulltext_mysql extends search_backend
for ($i = 0, $n = sizeof($text); $i < $n; $i++)
{
$text[$i] = trim($text[$i]);
- if (strlen($text[$i]) < $this->mysql_info['ft_min_word_len'] || strlen($text[$i]) > $this->mysql_info['ft_max_word_len'])
+ if (strlen($text[$i]) < $config['fulltext_mysql_min_word_len'] || strlen($text[$i]) > $this->config['fulltext_mysql_max_word_len'])
{
unset($text[$i]);
}
@@ -564,6 +583,128 @@ class fulltext_mysql extends search_backend
// destroy too old cached search results
$this->destroy_cache(array());
}
+
+ /**
+ * Create fulltext index
+ */
+ function create_index($acp_module, $u_action)
+ {
+ global $db;
+
+ if (strpos(SQL_LAYER, 'mysql') === false)
+ {
+ return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_VERSION'];
+ }
+
+ if (!is_array($this->stats))
+ {
+ $this->get_stats();
+ }
+
+ if (!isset($this->stats['post_subject']))
+ {
+ $db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ADD FULLTEXT (post_subject)');
+ }
+
+ if (!isset($this->stats['post_text']))
+ {
+ $db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ADD FULLTEXT (post_text)');
+ }
+
+ $db->sql_query('TRUNCATE ' . SEARCH_TABLE);
+ }
+
+ /**
+ * Drop fulltext index
+ */
+ function delete_index($acp_module, $u_action)
+ {
+ global $db;
+
+ if (strpos(SQL_LAYER, 'mysql') === false)
+ {
+ return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_VERSION'];
+ }
+
+ if (!is_array($this->stats))
+ {
+ $this->get_stats();
+ }
+
+ if (isset($this->stats['post_subject']))
+ {
+ $db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' DROP INDEX post_subject');
+ }
+
+ if (isset($this->stats['post_text']))
+ {
+ $db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' DROP INDEX post_text');
+ }
+
+ $db->sql_query('TRUNCATE ' . SEARCH_TABLE);
+ }
+
+ /**
+ * Returns true if both FULLTEXT indexes exist
+ */
+ function index_created()
+ {
+ if (!is_array($this->stats))
+ {
+ $this->get_stats();
+ }
+
+ return (isset($this->stats['post_text']) && isset($this->stats['post_subject'])) ? true : false;
+ }
+
+ /**
+ * Returns an associative array containing information about the indexes
+ */
+ function index_stats()
+ {
+ global $user;
+
+ if (!is_array($this->stats))
+ {
+ $this->get_stats();
+ }
+
+ return array(
+ $user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
+ $user->lang['FULLTEXT_MYSQL_TEXT_CARDINALITY'] => isset($this->stats['post_text']['Cardinality']) ? $this->stats['post_text']['Cardinality'] : 0,
+ $user->lang['FULLTEXT_MYSQL_SUBJECT_CARDINALITY'] => isset($this->stats['post_subject']['Cardinality']) ? $this->stats['post_subject']['Cardinality'] : 0);
+ }
+
+ function get_stats()
+ {
+ global $db;
+
+ $sql = 'SHOW INDEX
+ FROM ' . POSTS_TABLE;
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ if ($row['Index_type'] == 'FULLTEXT' || $row['Comment'] == 'FULLTEXT')
+ {
+ if ($row['Column_name'] == 'post_text')
+ {
+ $this->stats['post_text'] = $row;
+ }
+ else if ($row['Column_name'] == 'post_subject')
+ {
+ $this->stats['post_subject'] = $row;
+ }
+ }
+ }
+ $db->sql_freeresult($result);
+
+ $sql = 'SELECT COUNT(*) as total_posts
+ FROM ' . POSTS_TABLE;
+ $result = $db->sql_query($sql);
+ $this->stats['total_posts'] = $db->sql_fetchfield('total_posts', 0, $result);
+ $db->sql_freeresult($result);
+ }
}
?> \ No newline at end of file
diff --git a/phpBB/includes/search/fulltext_phpbb.php b/phpBB/includes/search/fulltext_phpbb.php
index 6259e7b984..341e9abb87 100644
--- a/phpBB/includes/search/fulltext_phpbb.php
+++ b/phpBB/includes/search/fulltext_phpbb.php
@@ -11,7 +11,7 @@
/**
* @ignore
*/
-include($phpbb_root_path . 'includes/search/search.' . $phpEx);
+include_once($phpbb_root_path . 'includes/search/search.' . $phpEx);
/**
* @package search
@@ -20,6 +20,8 @@ include($phpbb_root_path . 'includes/search/search.' . $phpEx);
*/
class fulltext_phpbb extends search_backend
{
+ var $stats;
+
function fulltext_phpbb(&$error)
{
$error = false;
@@ -887,13 +889,13 @@ class fulltext_phpbb extends search_backend
$destroy_cache_words = array();
- // Remove common (> 50% of posts ) words
+ // Remove common (> 60% of posts ) words
if ($config['num_posts'] >= 100)
{
$sql = 'SELECT word_id
FROM ' . SEARCH_MATCH_TABLE . '
GROUP BY word_id
- HAVING COUNT(word_id) > ' . floor($config['num_posts'] * 0.5);
+ HAVING COUNT(word_id) > ' . floor($config['num_posts'] * 0.6);
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result))
@@ -951,6 +953,94 @@ class fulltext_phpbb extends search_backend
// destroy cached search results containing any of the words that are now common or were removed
$this->destroy_cache(array_unique($destroy_cache_words));
}
+
+ /**
+ * Deletes all words from the index
+ */
+ function delete_index($acp_module, $u_action)
+ {
+ global $db;
+
+ $db->sql_query(((SQL_LAYER != 'sqlite') ? 'TRUNCATE ' : 'DELETE FROM ') . SEARCH_WORD_TABLE);
+ $db->sql_query(((SQL_LAYER != 'sqlite') ? 'TRUNCATE ' : 'DELETE FROM ') . SEARCH_MATCH_TABLE);
+ $db->sql_query(((SQL_LAYER != 'sqlite') ? 'TRUNCATE ' : 'DELETE FROM ') . SEARCH_TABLE);
+ }
+
+ /**
+ * Returns true if both FULLTEXT indexes exist
+ */
+ function index_created()
+ {
+ if (!is_array($this->stats))
+ {
+ $this->get_stats();
+ }
+
+ return ($this->stats['total_words'] && $this->stats['total_matches']) ? true : false;
+ }
+
+ /**
+ * Returns an associative array containing information about the indexes
+ */
+ function index_stats()
+ {
+ global $user;
+
+ if (!is_array($this->stats))
+ {
+ $this->get_stats();
+ }
+
+ return array(
+ $user->lang['TOTAL_WORDS'] => $this->stats['total_words'],
+ $user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']);
+ }
+
+ function get_stats()
+ {
+ global $db;
+
+ $sql = 'SELECT COUNT(*) as total_words
+ FROM ' . SEARCH_WORD_TABLE;
+ $result = $db->sql_query($sql);
+ $this->stats['total_words'] = $db->sql_fetchfield('total_words', 0, $result);
+ $db->sql_freeresult($result);
+
+ $sql = 'SELECT COUNT(*) as total_matches
+ FROM ' . SEARCH_MATCH_TABLE;
+ $result = $db->sql_query($sql);
+ $this->stats['total_matches'] = $db->sql_fetchfield('total_matches', 0, $result);
+ $db->sql_freeresult($result);
+ }
+
+ /**
+ * Returns a list of options for the ACP to display
+ */
+ function acp()
+ {
+ global $user, $config;
+
+ $tpl = '
+ <dl>
+ <dt><label for="fulltext_phpbb_load_search_upd">' . $user->lang['YES_SEARCH_UPDATE'] . ':</label><br /><span>' . $user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '</span></dt>
+ <dd><input type="radio" id="fulltext_phpbb_load_search_upd" name="config[fulltext_phpbb_load_search_upd]" value="1"' . (($config['fulltext_phpbb_load_search_upd']) ? ' checked="checked"' : '') . ' class="radio" />&nbsp;' . $user->lang['YES'] . '&nbsp;&nbsp;<input type="radio" name="config[fulltext_phpbb_load_search_upd]" value="0"' . ((!$config['fulltext_phpbb_load_search_upd']) ? ' checked="checked"' : '') . ' class="radio" />&nbsp;' . $user->lang['NO'] . '</dd>
+ </dl>
+ <dl>
+ <dt><label for="fulltext_phpbb_min_search_chars">' . $user->lang['MIN_SEARCH_CHARS'] . ':</label><br /><span>' . $user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
+ <dd><input id="fulltext_phpbb_min_search_chars" type="text" size="3" maxlength="3" name="config[fulltext_phpbb_min_search_chars]" value="' . $config['fulltext_phpbb_min_search_chars'] . '" /></dd>
+ </dl>
+ <dl>
+ <dt><label for="fulltext_phpbb_max_search_chars">' . $user->lang['MAX_SEARCH_CHARS'] . ':</label><br /><span>' . $user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
+ <dd><input id="fulltext_phpbb_max_search_chars" type="text" size="3" maxlength="3" name="config[fulltext_phpbb_max_search_chars]" value="' . $config['fulltext_phpbb_max_search_chars'] . '" /></dd>
+ </dl>
+ ';
+
+ // These are fields required in the config table
+ return array(
+ 'tpl' => $tpl,
+ 'config' => array('fulltext_phpbb_load_search_upd' => 'bool', 'fulltext_phpbb_min_search_chars' => 'integer', 'fulltext_phpbb_max_search_chars' => 'integer')
+ );
+ }
}
?> \ No newline at end of file