1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
<?php
/***************************************************************************
* admin_search.php
* -------------------
* begin : Saturday, Feb 13, 2001
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id$
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
if (!empty($setmodules))
{
if (!$auth->acl_get('a_search'))
{
return;
}
$module['DB']['SEARCH_INDEX'] = basename(__FILE__) . $SID;
return;
}
define('IN_PHPBB', 1);
// Include files
$phpbb_root_path = '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require('pagestart.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.'.$phpEx);
// Check permissions
if (!$auth->acl_get('a_search'))
{
trigger_error($user->lang['NO_ADMIN']);
}
// Start indexing
if (isset($_POST['start']) || isset($_GET['batchstart']))
{
$batchsize = 5000; // Process this many posts per batch
$batchcount = request_var('batchcount', 1);
$batchstart = request_var('batchstart', 0);
$loopcount = 0;
$fulltext = new fulltext_search();
// Search re-indexing is tough on the server ... so we'll check the load
// each loop and if we're on a 1min load of 3 or more we'll re-load the page
// and try again. No idea how well this will work in practice so we'll see ...
if (file_exists('/proc/loadavg'))
{
if ($load = @file('/proc/loadavg'))
{
list($load) = explode(' ', $load[0]);
if ($load > 3)
{
redirect("adm/admin_search.$phpEx$SID&batchstart=$batchstart&batchcount=$batchcount", 3);
}
}
}
if (!$batchstart)
{
// Take board offline
set_config('board_disable', 1);
// Empty existing tables
$db->sql_query("TRUNCATE " . SEARCH_TABLE);
$db->sql_query("TRUNCATE " . SEARCH_WORD_TABLE);
$db->sql_query("TRUNCATE " . SEARCH_MATCH_TABLE);
}
// Fetch a batch of posts_text entries
$sql = "SELECT COUNT(*) AS total, MAX(post_id) AS max_post_id, MIN(post_id) AS min_post_id
FROM " . POSTS_TABLE;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$totalposts = $row['total'];
$max_post_id = $row['max_post_id'];
$batchstart = (!$batchstart) ? $row['min_post_id'] : $batchstart;
$batchend = $batchstart + $batchsize;
$db->sql_freeresult($result);
$sql = "SELECT *
FROM " . POSTS_TABLE . "
WHERE post_id
BETWEEN $batchstart
AND $batchend";
$result = $db->sql_query($sql);
if ($row = $db->sql_fetchrow($result))
{
do
{
$fulltext->add('admin', $row['post_id'], $row['post_text'], $row['post_subject']);
}
while ($row = $db->sql_fetchrow($result));
}
$db->sql_freeresult($result);
$batchcount++;
if (($batchstart + $batchsize) < $max_post_id)
{
redirect("adm/admin_search.$phpEx$SID&batchstart=" . ($batchstart + $batchsize) . "&batchcount=$batchcount", 3);
}
else
{
set_config('board_disable', 0);
// search tidy
$fulltext->search_tidy();
adm_page_header($user->lang['SEARCH_INDEX']);
?>
<h1><?php echo $user->lang['SEARCH_INDEX']; ?></h1>
<p><?php echo $user->lang['SEARCH_INDEX_COMPLETE']; ?></p>
<?php
adm_page_footer();
}
exit;
}
else if (isset($_POST['cancel']))
{
set_config('board_disable', 0);
adm_page_header($user->lang['SEARCH_INDEX']);
?>
<h1><?php echo $user->lang['SEARCH_INDEX']; ?></h1>
<p><?php echo $user->lang['SEARCH_INDEX_CANCEL']; ?></p>
<?php
adm_page_footer();
}
else
{
adm_page_header($user->lang['SEARCH_INDEX']);
?>
<h1><?php echo $user->lang['SEARCH_INDEX']; ?></h1>
<p><?php echo $user->lang['SEARCH_INDEX_EXPLAIN']; ?></p>
<form method="post" action="<?php echo "admin_search.$phpEx$SID"; ?>"><table cellspacing="1" cellpadding="4" border="0" align="center" bgcolor="#98AAB1">
<tr>
<td class="cat" height="28" align="center"> <input type="submit" name="start" value="<?php echo $user->lang['START']; ?>" class="btnmain" /> <input type="submit" name="cancel" value="<?php echo $user->lang['CANCEL']; ?>" class="btnmain" /> </td>
</tr>
</table></form>
<?php
adm_page_footer();
}
?>
|