aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/develop/search_fill.php
blob: af2dd6a288ec71d3fbd7a3093a7389999e1edaea (plain)
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
<?php

//
// Security message:
//
// This script is potentially dangerous.
// Remove or comment the next line (die(".... ) to enable this script.
// Do NOT FORGET to either remove this script or disable it after you have used it.
//

//
// Security message:
//
// This script is potentially dangerous.
// Remove or comment the next line (die(".... ) to enable this script.
// Do NOT FORGET to either remove this script or disable it after you have used it.
//
die("Please read the first lines of this script for instructions on how to enable it");

//
// Do not change anything below this line.
//
set_time_limit(0);

define('IN_PHPBB', true);
define('PHPBB_ROOT_PATH', './../');
define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$search_type = phpbb::$config['search_type'];

if (!file_exists(PHPBB_ROOT_PATH . 'includes/search/' . $search_type . '.' . PHP_EXT))
{
	trigger_error('NO_SUCH_SEARCH_MODULE');
}

require(PHPBB_ROOT_PATH . 'includes/search/' . $search_type . '.' . PHP_EXT);

$error = false;
$search = new $search_type($error);

if ($error)
{
	trigger_error($error);
}

print "<html>\n<body>\n";

//
// Fetch a batch of posts_text entries
//
$sql = "SELECT COUNT(*) as total, MAX(post_id) as max_post_id
	FROM ". POSTS_TABLE;
if ( !($result = $db->sql_query($sql)) )
{
	$error = $db->sql_error();
	die("Couldn't get maximum post ID :: " . $sql . " :: " . $error['message']);
}

$max_post_id = $db->sql_fetchrow($result);

$totalposts = $max_post_id['total'];
$max_post_id = $max_post_id['max_post_id'];

$postcounter = (!isset($HTTP_GET_VARS['batchstart'])) ? 0 : $HTTP_GET_VARS['batchstart'];

$batchsize = 200; // Process this many posts per loop
$batchcount = 0;
for(;$postcounter <= $max_post_id; $postcounter += $batchsize)
{
	$batchstart = $postcounter + 1;
	$batchend = $postcounter + $batchsize;
	$batchcount++;

	$sql = "SELECT *
		FROM " . POSTS_TABLE . "
		WHERE post_id
			BETWEEN $batchstart
				AND $batchend";
	if( !($result = $db->sql_query($sql)) )
	{
		$error = $db->sql_error();
		die("Couldn't get post_text :: " . $sql . " :: " . $error['message']);
	}

	$rowset = $db->sql_fetchrowset($result);
	$db->sql_freeresult($result);

	$post_rows = sizeof($rowset);

	if( $post_rows )
	{

	// $sql = "LOCK TABLES ".POST_TEXT_TABLE." WRITE";
	// $result = $db->sql_query($sql);
		print "\n<p>\n<a href='{$_SERVER['PHP_SELF']}?batchstart=$batchstart'>Restart from posting $batchstart</a><br>\n";

		// For every post in the batch:
		for($post_nr = 0; $post_nr < $post_rows; $post_nr++ )
		{
			print ".";
			flush();

			$post_id = $rowset[$post_nr]['post_id'];

			$search->index('post', $rowset[$post_nr]['post_id'], $rowset[$post_nr]['post_text'], $rowset[$post_nr]['post_subject'], $rowset[$post_nr]['poster_id']);
		}
	// $sql = "UNLOCK TABLES";
	// $result = $db->sql_query($sql);

	}
}

print "<br>Removing common words (words that appear in more than 50% of the posts)<br>\n";
flush();
$search->tidy();
print "Removed words that where too common.<br>";

echo "<br>Done";

?>

</body>
</html>