mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 13:28:55 +00:00
[ticket/15540] Remove delete_index and move create_index to fulltext_native
PHPBB3-15540
This commit is contained in:
parent
5805a6906e
commit
cc0d4efc8f
3 changed files with 82 additions and 124 deletions
|
@ -300,55 +300,12 @@ class acp_search
|
||||||
switch ($action)
|
switch ($action)
|
||||||
{
|
{
|
||||||
case 'delete':
|
case '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
|
||||||
|
if ($error = $this->search->delete_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=delete&hash=" . generate_link_hash('acp_search'), false)))
|
||||||
{
|
{
|
||||||
// pass a reference to myself so the $search object can make use of save_state() and attributes
|
$this->state = array('');
|
||||||
if ($error = $this->search->delete_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=delete&hash=" . generate_link_hash('acp_search'), false)))
|
|
||||||
{
|
|
||||||
$this->state = array('');
|
|
||||||
$this->save_state();
|
|
||||||
trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$starttime = microtime(true);
|
|
||||||
$row_count = 0;
|
|
||||||
while (still_on_time() && $post_counter <= $this->max_post_id)
|
|
||||||
{
|
|
||||||
$sql = 'SELECT post_id, poster_id, forum_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 = $forum_ids = array();
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
$ids[] = $row['post_id'];
|
|
||||||
$posters[] = $row['poster_id'];
|
|
||||||
$forum_ids[] = $row['forum_id'];
|
|
||||||
}
|
|
||||||
$db->sql_freeresult($result);
|
|
||||||
$row_count += count($ids);
|
|
||||||
|
|
||||||
if (count($ids))
|
|
||||||
{
|
|
||||||
$this->search->index_remove($ids, $posters, $forum_ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
$post_counter += $this->batch_size;
|
|
||||||
}
|
|
||||||
// save the current state
|
|
||||||
$this->save_state();
|
$this->save_state();
|
||||||
|
trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
|
||||||
if ($post_counter <= $this->max_post_id)
|
|
||||||
{
|
|
||||||
$totaltime = microtime(true) - $starttime;
|
|
||||||
$rows_per_second = $row_count / $totaltime;
|
|
||||||
meta_refresh(1, append_sid($this->u_action . '&action=delete&skip_rows=' . $post_counter . '&hash=' . generate_link_hash('acp_search')));
|
|
||||||
trigger_error($user->lang('SEARCH_INDEX_DELETE_REDIRECT', (int) $row_count, $post_counter) . $user->lang('SEARCH_INDEX_DELETE_REDIRECT_RATE', $rows_per_second));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->search->tidy();
|
$this->search->tidy();
|
||||||
|
@ -361,82 +318,12 @@ class acp_search
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'create':
|
case 'create':
|
||||||
if (method_exists($this->search, 'create_index'))
|
// pass a reference to acp_search so the $search object can make use of save_state() and attributes
|
||||||
|
if ($error = $this->search->create_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=create", false)))
|
||||||
{
|
{
|
||||||
// pass a reference to acp_search so the $search object can make use of save_state() and attributes
|
$this->state = array('');
|
||||||
if ($error = $this->search->create_index($this, append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&mode=$mode&action=create", false)))
|
|
||||||
{
|
|
||||||
$this->state = array('');
|
|
||||||
$this->save_state();
|
|
||||||
trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$sql = 'SELECT forum_id, enable_indexing
|
|
||||||
FROM ' . FORUMS_TABLE;
|
|
||||||
$result = $db->sql_query($sql, 3600);
|
|
||||||
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
$forums[$row['forum_id']] = (bool) $row['enable_indexing'];
|
|
||||||
}
|
|
||||||
$db->sql_freeresult($result);
|
|
||||||
|
|
||||||
$starttime = microtime(true);
|
|
||||||
$row_count = 0;
|
|
||||||
while (still_on_time() && $post_counter <= $this->max_post_id)
|
|
||||||
{
|
|
||||||
$sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_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);
|
|
||||||
|
|
||||||
$buffer = $db->sql_buffer_nested_transactions();
|
|
||||||
|
|
||||||
if ($buffer)
|
|
||||||
{
|
|
||||||
$rows = $db->sql_fetchrowset($result);
|
|
||||||
$rows[] = false; // indicate end of array for while loop below
|
|
||||||
|
|
||||||
$db->sql_freeresult($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
while ($row = ($buffer ? $rows[$i++] : $db->sql_fetchrow($result)))
|
|
||||||
{
|
|
||||||
// Indexing enabled for this forum
|
|
||||||
if (isset($forums[$row['forum_id']]) && $forums[$row['forum_id']])
|
|
||||||
{
|
|
||||||
$this->search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']);
|
|
||||||
}
|
|
||||||
$row_count++;
|
|
||||||
}
|
|
||||||
if (!$buffer)
|
|
||||||
{
|
|
||||||
$db->sql_freeresult($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
$post_counter += $this->batch_size;
|
|
||||||
}
|
|
||||||
// save the current state
|
|
||||||
$this->save_state();
|
$this->save_state();
|
||||||
|
trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js(), E_USER_WARNING);
|
||||||
// pretend the number of posts was as big as the number of ids we indexed so far
|
|
||||||
// just an estimation as it includes deleted posts
|
|
||||||
$num_posts = $config['num_posts'];
|
|
||||||
$config['num_posts'] = min($config['num_posts'], $post_counter);
|
|
||||||
$this->search->tidy();
|
|
||||||
$config['num_posts'] = $num_posts;
|
|
||||||
|
|
||||||
if ($post_counter <= $this->max_post_id)
|
|
||||||
{
|
|
||||||
$totaltime = microtime(true) - $starttime;
|
|
||||||
$rows_per_second = $row_count / $totaltime;
|
|
||||||
meta_refresh(1, append_sid($this->u_action . '&action=create&skip_rows=' . $post_counter . '&hash=' . generate_link_hash('acp_search')));
|
|
||||||
trigger_error($user->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $row_count, $post_counter) . $user->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $rows_per_second));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->search->tidy();
|
$this->search->tidy();
|
||||||
|
|
|
@ -1667,6 +1667,78 @@ class fulltext_native extends base implements search_backend_interface
|
||||||
$this->config->set('search_last_gc', time(), false);
|
$this->config->set('search_last_gc', time(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function create_index($acp_module, $u_action)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT forum_id, enable_indexing
|
||||||
|
FROM ' . FORUMS_TABLE;
|
||||||
|
$result = $this->db->sql_query($sql, 3600);
|
||||||
|
|
||||||
|
while ($row = $this->db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$forums[$row['forum_id']] = (bool) $row['enable_indexing'];
|
||||||
|
}
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$starttime = microtime(true);
|
||||||
|
$row_count = 0;
|
||||||
|
$post_counter = $acp_module->state[2];
|
||||||
|
while (still_on_time() && $post_counter <= $acp_module->max_post_id)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id
|
||||||
|
FROM ' . POSTS_TABLE . '
|
||||||
|
WHERE post_id >= ' . (int) ($post_counter + 1) . '
|
||||||
|
AND post_id <= ' . (int) ($post_counter + $acp_module->batch_size);
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
|
||||||
|
$buffer = $this->db->sql_buffer_nested_transactions();
|
||||||
|
|
||||||
|
if ($buffer)
|
||||||
|
{
|
||||||
|
$rows = $this->db->sql_fetchrowset($result);
|
||||||
|
$rows[] = false; // indicate end of array for while loop below
|
||||||
|
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
while ($row = ($buffer ? $rows[$i++] : $this->db->sql_fetchrow($result)))
|
||||||
|
{
|
||||||
|
// Indexing enabled for this forum
|
||||||
|
if (isset($forums[$row['forum_id']]) && $forums[$row['forum_id']])
|
||||||
|
{
|
||||||
|
$this->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']);
|
||||||
|
}
|
||||||
|
$row_count++;
|
||||||
|
}
|
||||||
|
if (!$buffer)
|
||||||
|
{
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
$post_counter += $acp_module->batch_size;
|
||||||
|
}
|
||||||
|
// save the current state
|
||||||
|
$acp_module->save_state();
|
||||||
|
|
||||||
|
// pretend the number of posts was as big as the number of ids we indexed so far
|
||||||
|
// just an estimation as it includes deleted posts
|
||||||
|
$num_posts = $this->config['num_posts'];
|
||||||
|
$this->config['num_posts'] = min($this->config['num_posts'], $post_counter);
|
||||||
|
$this->tidy();
|
||||||
|
$this->config['num_posts'] = $num_posts;
|
||||||
|
|
||||||
|
if ($post_counter <= $acp_module->max_post_id)
|
||||||
|
{
|
||||||
|
$totaltime = microtime(true) - $starttime;
|
||||||
|
$rows_per_second = $row_count / $totaltime;
|
||||||
|
meta_refresh(1, $u_action);
|
||||||
|
trigger_error($user->lang('SEARCH_INDEX_CREATE_REDIRECT', (int) $row_count, $post_counter) . $user->lang('SEARCH_INDEX_CREATE_REDIRECT_RATE', $rows_per_second));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -1738,7 +1810,7 @@ class fulltext_native extends base implements search_backend_interface
|
||||||
$this->user->lang['TOTAL_WORDS'] => $this->stats['total_words'],
|
$this->user->lang['TOTAL_WORDS'] => $this->stats['total_words'],
|
||||||
$this->user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']);
|
$this->user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the stats and store them in the $this->stats associative array
|
* Computes the stats and store them in the $this->stats associative array
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -125,8 +125,7 @@ interface search_backend_interface
|
||||||
*
|
*
|
||||||
* @return string|bool error string is returned incase of errors otherwise false
|
* @return string|bool error string is returned incase of errors otherwise false
|
||||||
*/
|
*/
|
||||||
// This method isn't present in fulltext_native, because it's implementation is hardcoded in acp_search
|
public function create_index($acp_module, $u_action);
|
||||||
//public function create_index($acp_module, $u_action);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drop fulltext index
|
* Drop fulltext index
|
||||||
|
|
Loading…
Add table
Reference in a new issue