diff options
author | Igor Wiedler <igor@wiedler.ch> | 2012-02-17 13:48:48 +0100 |
---|---|---|
committer | Igor Wiedler <igor@wiedler.ch> | 2012-02-17 13:48:48 +0100 |
commit | d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182 (patch) | |
tree | c0081f9deac588982d2e00cf935daabb03af6605 /phpBB/develop/create_search_index.php | |
parent | 7295e5824aed6f5ec32cfab0ad17cfa2c24855ac (diff) | |
parent | 9611b5ff83582d7bda22ab991e8d69786dab5b93 (diff) | |
download | forums-d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182.tar forums-d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182.tar.gz forums-d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182.tar.bz2 forums-d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182.tar.xz forums-d70c3f1eb8c0ddc68d8eda1bd8708c4957c21182.zip |
Merge branch 'develop' into ticket/10380
* develop: (325 commits)
[ticket/10641] Update MCP template with new plurality forms
[ticket/10637] Leftovers from implementation of extensions in convertor
[ticket/10637] Leftovers from implementation of extensions in develop tools
[ticket/10637] Leftovers from implementation of extensions in mcp_post
[ticket/10637] Leftovers from implementation of extensions in mcp_main
[ticket/10637] Leftovers from implementation of extensions
[ticket/10606] Also correctly use $s_search_hidden_fields in view(forum|topic).
[ticket/10606] Fix incorrect hidden fields array name in page_header().
[ticket/10633] Stop leaking filename of attachments when thumbnail is requested
[ticket/10636] Resolve variable name ($sql_ary) conflict in cache_moderators().
[ticket/10634] Specify module type when viewing profile
[ticket/10634] Changing p_master::is_full_class
[ticket/10569] Invalid string comparison in prosilver
[ticket/10495] Update request/type_cast_helper for PHP 5.4 magic_quotes_gpc drop
[ticket/10512] Call startup.php from tests/bootstrap.php
[ticket/10535] Delete no longer needed email confirm language entries.
[ticket/9914] Add backup warning to updater.
[ticket/10616] Add template inheritance to exported template
[ticket/10616] Ignore template inheritance that points to self
[ticket/10616] Add template inheritance to default styles
...
Diffstat (limited to 'phpBB/develop/create_search_index.php')
-rw-r--r-- | phpBB/develop/create_search_index.php | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/phpBB/develop/create_search_index.php b/phpBB/develop/create_search_index.php new file mode 100644 index 0000000000..1de20f3099 --- /dev/null +++ b/phpBB/develop/create_search_index.php @@ -0,0 +1,136 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +if (php_sapi_name() != 'cli') +{ + die("This program must be run from the command line.\n"); +} + +if ($argc < 2) +{ + echo 'Usage: php ' . basename(__FILE__) . " index_type [batch_size]\n"; + exit(1); +} + +$class_name = basename($argv[1]); + +define('IN_PHPBB', true); +$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../'; +$phpEx = substr(strrchr(__FILE__, '.'), 1); +require($phpbb_root_path . 'common.' . $phpEx); +require($phpbb_root_path . 'includes/acp/acp_search.' . $phpEx); + +$user->session_begin(); +$auth->acl($user->data); +$user->setup('acp/search'); + +$search_name = ucfirst(strtolower(str_replace('_', ' ', $class_name))); +$search_errors = array(); +$search = new $class_name($search_errors); + +$batch_size = isset($argv[2]) ? $argv[2] : 2000; +$time = time(); + +if (method_exists($search, 'create_index')) +{ + if ($error = $search->create_index(null, '')) + { + var_dump($error); + exit(1); + } +} +else +{ + $sql = 'SELECT forum_id, enable_indexing + FROM ' . FORUMS_TABLE; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $forums[$row['forum_id']] = (bool) $row['enable_indexing']; + } + $db->sql_freeresult($result); + + $sql = 'SELECT post_id + FROM ' . POSTS_TABLE . ' + ORDER BY post_id DESC'; + $result = $db->sql_query_limit($sql, 1); + $max_post_id = (int) $db->sql_fetchfield('post_id'); + + $post_counter = 0; + while ($post_counter <= $max_post_id) + { + $row_count = 0; + + printf("Processing posts with %d <= post_id <= %d\n", + $post_counter + 1, + $post_counter + $batch_size + ); + + $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 + $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 or global announcement? + // Global announcements get indexed by default. + if (!$row['forum_id'] || !empty($forums[$row['forum_id']])) + { + ++$row_count; + + $search->index('post', + $row['post_id'], + $row['post_text'], + $row['post_subject'], + $row['poster_id'], + $row['forum_id'] + ); + + if ($row_count % 10 == 0) + { + echo '.'; + } + } + } + + $delta = (time() - $time); + $delta = $delta <= 0 ? 1 : $delta; + printf(" %d posts/sec\n", $row_count / $delta); + + if (!$buffer) + { + $db->sql_freeresult($result); + } + + $post_counter += $batch_size; + } +} + +$search->tidy(); + +add_log('admin', 'LOG_SEARCH_INDEX_CREATED', $search_name); + +echo $user->lang['SEARCH_INDEX_CREATED'] . "\n"; +echo 'Peak Memory Usage: ' . get_formatted_filesize(memory_get_peak_usage()) . "\n"; + +exit(0); |