Merge PR #916 branch 'dhruvgoel92/ticket/11011' into develop

* dhruvgoel92/ticket/11011:
  [ticket/11011] rename property phpEx to php_ext
  [ticket/11011] pass $auth to search backend constructor
  [ticket/11011] remove global keyword from sphinx
  [ticket/11011] pass global variables in construct
  [ticket/11011] passing global variables
  [ticket/11011] remove global keyword in native search
  [ticket/11011] remove global keyword in pgsql search
  [ticket/11011] global variables as constructor parameters
  [ticket/11011] add access specifiers and docblocks
This commit is contained in:
Oleg Pudeyev 2012-08-08 03:19:00 -04:00
commit 7c6e1ba109
6 changed files with 314 additions and 318 deletions

View file

@ -596,7 +596,7 @@ class acp_search
*/
function init_search($type, &$search, &$error)
{
global $phpbb_root_path, $phpEx, $user;
global $phpbb_root_path, $phpEx, $user, $auth, $config, $db;
if (!class_exists($type) || !method_exists($type, 'keyword_search'))
{
@ -605,7 +605,7 @@ class acp_search
}
$error = false;
$search = new $type($error);
$search = new $type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
return $error;
}

View file

@ -22,17 +22,28 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_search_fulltext_mysql extends phpbb_search_base
{
var $stats = array();
var $word_length = array();
var $split_words = array();
var $search_query;
var $common_words = array();
private $stats = array();
private $split_words = array();
private $config;
private $db;
private $user;
public $word_length = array();
public $search_query;
public $common_words = array();
public function __construct(&$error)
/**
* Constructor
* Creates a new phpbb_search_fulltext_mysql, which is used as a search backend.
*
* @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false
*/
public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
{
global $config;
$this->config = $config;
$this->db = $db;
$this->user = $user;
$this->word_length = array('min' => $config['fulltext_mysql_min_word_len'], 'max' => $config['fulltext_mysql_max_word_len']);
$this->word_length = array('min' => $this->config['fulltext_mysql_min_word_len'], 'max' => $this->config['fulltext_mysql_max_word_len']);
$error = false;
}
@ -41,6 +52,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
* Returns the name of this search backend to be displayed to administrators
*
* @return string Name
*
* @access public
*/
public function get_name()
{
@ -49,19 +62,21 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Checks for correct MySQL version and stores min/max word length in the config
*
* @return string|bool Language key of the error/incompatiblity occured
*
* @access public
*/
function init()
{
global $db, $user;
if ($db->sql_layer != 'mysql4' && $db->sql_layer != 'mysqli')
if ($this->db->sql_layer != 'mysql4' && $this->db->sql_layer != 'mysqli')
{
return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE'];
return $this->user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_DATABASE'];
}
$result = $db->sql_query('SHOW TABLE STATUS LIKE \'' . POSTS_TABLE . '\'');
$info = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$result = $this->db->sql_query('SHOW TABLE STATUS LIKE \'' . POSTS_TABLE . '\'');
$info = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);
$engine = '';
if (isset($info['Engine']))
@ -75,19 +90,19 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if ($engine != 'MyISAM')
{
return $user->lang['FULLTEXT_MYSQL_NOT_MYISAM'];
return $this->user->lang['FULLTEXT_MYSQL_NOT_MYISAM'];
}
$sql = 'SHOW VARIABLES
LIKE \'ft\_%\'';
$result = $db->sql_query($sql);
$result = $this->db->sql_query($sql);
$mysql_info = array();
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$mysql_info[$row['Variable_name']] = $row['Value'];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
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']);
@ -102,11 +117,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
* @param string &$keywords Contains the keyword as entered by the user
* @param string $terms is either 'all' or 'any'
* @return bool false if no valid keywords were found and otherwise true
*
* @access public
*/
function split_keywords(&$keywords, $terms)
{
global $config, $user;
if ($terms == 'all')
{
$match = array('#\sand\s#iu', '#\sor\s#iu', '#\snot\s#iu', '#(^|\s)\+#', '#(^|\s)-#', '#(^|\s)\|#');
@ -125,9 +140,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
$this->split_words = $matches[1];
// We limit the number of allowed keywords to minimize load on the database
if ($config['max_num_search_keywords'] && sizeof($this->split_words) > $config['max_num_search_keywords'])
if ($this->config['max_num_search_keywords'] && sizeof($this->split_words) > $this->config['max_num_search_keywords'])
{
trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], sizeof($this->split_words)));
trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $this->config['max_num_search_keywords'], sizeof($this->split_words)));
}
// to allow phrase search, we need to concatenate quoted words
@ -169,7 +184,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
// check word length
$clean_len = utf8_strlen(str_replace('*', '', $clean_word));
if (($clean_len < $config['fulltext_mysql_min_word_len']) || ($clean_len > $config['fulltext_mysql_max_word_len']))
if (($clean_len < $this->config['fulltext_mysql_min_word_len']) || ($clean_len > $this->config['fulltext_mysql_max_word_len']))
{
$this->common_words[] = $word;
unset($this->split_words[$i]);
@ -221,11 +236,12 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Turns text into an array of words
* @param string $text contains post text/subject
*
* @access public
*/
function split_message($text)
{
global $config;
// Split words
$text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text)));
$matches = array();
@ -237,7 +253,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
for ($i = 0, $n = sizeof($text); $i < $n; $i++)
{
$text[$i] = trim($text[$i]);
if (utf8_strlen($text[$i]) < $config['fulltext_mysql_min_word_len'] || utf8_strlen($text[$i]) > $config['fulltext_mysql_max_word_len'])
if (utf8_strlen($text[$i]) < $this->config['fulltext_mysql_min_word_len'] || utf8_strlen($text[$i]) > $this->config['fulltext_mysql_max_word_len'])
{
unset($text[$i]);
}
@ -270,8 +286,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
*/
function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
global $config, $db;
// No keywords? No posts.
if (!$this->search_query)
{
@ -360,7 +374,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
}
else
{
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
$sql_select = (!$result_count) ? 'SQL_CALC_FOUND_ROWS ' : '';
@ -370,11 +384,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (sizeof($author_ary) && $author_name)
{
// first one matches post of registered users, second one guests and deleted users
$sql_author = ' AND (' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
$sql_author = ' AND (' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else if (sizeof($author_ary))
{
$sql_author = ' AND ' . $db->sql_in_set('p.poster_id', $author_ary);
$sql_author = ' AND ' . $this->db->sql_in_set('p.poster_id', $author_ary);
}
else
{
@ -384,7 +398,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
$sql_where_options = $sql_sort_join;
$sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : '';
$sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : '';
$sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_where_options .= $m_approve_fid_sql;
$sql_where_options .= $sql_author;
$sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
@ -392,16 +406,16 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
$sql = "SELECT $sql_select
FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p
WHERE MATCH ($sql_match) AGAINST ('" . $db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE)
WHERE MATCH ($sql_match) AGAINST ('" . $this->db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE)
$sql_where_options
ORDER BY $sql_sort";
$result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
$result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = (int) $row[$field];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
$id_ary = array_unique($id_ary);
@ -414,9 +428,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (!$result_count)
{
$sql = 'SELECT FOUND_ROWS() as result_count';
$result = $db->sql_query($sql);
$result_count = (int) $db->sql_fetchfield('result_count');
$db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
$result_count = (int) $this->db->sql_fetchfield('result_count');
$this->db->sql_freeresult($result);
if (!$result_count)
{
@ -454,8 +468,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
*/
function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
global $config, $db;
// No author? No posts.
if (!sizeof($author_ary))
{
@ -491,13 +503,13 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if ($author_name)
{
// first one matches post of registered users, second one guests and deleted users
$sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
$sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else
{
$sql_author = $db->sql_in_set('p.poster_id', $author_ary);
$sql_author = $this->db->sql_in_set('p.poster_id', $author_ary);
}
$sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : '';
$sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
$sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : '';
@ -533,7 +545,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
}
else
{
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
// If the cache was completely empty count the results
@ -572,21 +584,21 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
}
// Only read one block of posts from the db and then cache it
$result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
$result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = (int) $row[$field];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
// retrieve the total result count if needed
if (!$result_count)
{
$sql = 'SELECT FOUND_ROWS() as result_count';
$result = $db->sql_query($sql);
$result_count = (int) $db->sql_fetchfield('result_count');
$db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
$result_count = (int) $this->db->sql_fetchfield('result_count');
$this->db->sql_freeresult($result);
if (!$result_count)
{
@ -608,11 +620,16 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
* Destroys cached search results, that contained one of the new words in a post so the results won't be outdated.
*
* @param string $mode contains the post mode: edit, post, reply, quote ...
* @param int $post_id contains the post id of the post to index
* @param string $message contains the post text of the post
* @param string $subject contains the subject of the post to index
* @param int $poster_id contains the user id of the poster
* @param int $forum_id contains the forum id of parent forum of the post
*
* @access public
*/
function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
{
global $db;
// Split old and new post/subject to obtain array of words
$split_text = $this->split_message($message);
$split_title = ($subject) ? $this->split_message($subject) : array();
@ -630,6 +647,8 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Destroy cached results, that might be outdated after deleting a post
*
* @access public
*/
function index_remove($post_ids, $author_ids, $forum_ids)
{
@ -638,11 +657,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Destroy old cache entries
*
* @access public
*/
function tidy()
{
global $db, $config;
// destroy too old cached search results
$this->destroy_cache(array());
@ -651,11 +670,13 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Create fulltext index
*
* @return string|bool error string is returned incase of errors otherwise false
*
* @access public
*/
function create_index($acp_module, $u_action)
{
global $db;
// Make sure we can actually use MySQL with fulltext indexes
if ($error = $this->init())
{
@ -671,7 +692,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (!isset($this->stats['post_subject']))
{
if ($db->sql_layer == 'mysqli' || version_compare($db->sql_server_info(true), '4.1.3', '>='))
if ($this->db->sql_layer == 'mysqli' || version_compare($this->db->sql_server_info(true), '4.1.3', '>='))
{
$alter[] = 'MODIFY post_subject varchar(255) COLLATE utf8_unicode_ci DEFAULT \'\' NOT NULL';
}
@ -684,7 +705,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (!isset($this->stats['post_text']))
{
if ($db->sql_layer == 'mysqli' || version_compare($db->sql_server_info(true), '4.1.3', '>='))
if ($this->db->sql_layer == 'mysqli' || version_compare($this->db->sql_server_info(true), '4.1.3', '>='))
{
$alter[] = 'MODIFY post_text mediumtext COLLATE utf8_unicode_ci NOT NULL';
}
@ -702,21 +723,23 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (sizeof($alter))
{
$db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
$this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
}
$db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
return false;
}
/**
* Drop fulltext index
*
* @return string|bool error string is returned incase of errors otherwise false
*
* @access public
*/
function delete_index($acp_module, $u_action)
{
global $db;
// Make sure we can actually use MySQL with fulltext indexes
if ($error = $this->init())
{
@ -747,16 +770,18 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
if (sizeof($alter))
{
$db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
$this->db->sql_query('ALTER TABLE ' . POSTS_TABLE . ' ' . implode(', ', $alter));
}
$db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
return false;
}
/**
* Returns true if both FULLTEXT indexes exist
*
* @access public
*/
function index_created()
{
@ -770,26 +795,29 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
/**
* Returns an associative array containing information about the indexes
*
* @access public
*/
function index_stats()
{
global $user;
if (empty($this->stats))
{
$this->get_stats();
}
return array(
$user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
$this->user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
);
}
/**
* Computes the stats and store them in the $this->stats associative array
*
* @access private
*/
function get_stats()
{
global $db;
if (strpos($db->sql_layer, 'mysql') === false)
if (strpos($this->db->sql_layer, 'mysql') === false)
{
$this->stats = array();
return;
@ -797,9 +825,9 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
$sql = 'SHOW INDEX
FROM ' . POSTS_TABLE;
$result = $db->sql_query($sql);
$result = $this->db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
// deal with older MySQL versions which didn't use Index_type
$index_type = (isset($row['Index_type'])) ? $row['Index_type'] : $row['Comment'];
@ -820,26 +848,28 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base
}
}
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
$this->stats['total_posts'] = empty($this->stats) ? 0 : $db->get_estimated_row_count(POSTS_TABLE);
$this->stats['total_posts'] = empty($this->stats) ? 0 : $this->db->get_estimated_row_count(POSTS_TABLE);
}
/**
* Display a note, that UTF-8 support is not available with certain versions of PHP
*
* @return associative array containing template and config variables
*
* @access public
*/
function acp()
{
global $user, $config;
$tpl = '
<dl>
<dt><label>' . $user->lang['MIN_SEARCH_CHARS'] . ':</label><br /><span>' . $user->lang['FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dd>' . $config['fulltext_mysql_min_word_len'] . '</dd>
<dt><label>' . $this->user->lang['MIN_SEARCH_CHARS'] . ':</label><br /><span>' . $this->user->lang['FULLTEXT_MYSQL_MIN_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dd>' . $this->config['fulltext_mysql_min_word_len'] . '</dd>
</dl>
<dl>
<dt><label>' . $user->lang['MAX_SEARCH_CHARS'] . ':</label><br /><span>' . $user->lang['FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dd>' . $config['fulltext_mysql_max_word_len'] . '</dd>
<dt><label>' . $this->user->lang['MAX_SEARCH_CHARS'] . ':</label><br /><span>' . $this->user->lang['FULLTEXT_MYSQL_MAX_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dd>' . $this->config['fulltext_mysql_max_word_len'] . '</dd>
</dl>
';

View file

@ -31,23 +31,33 @@ class phpbb_search_fulltext_native extends phpbb_search_base
var $must_not_contain_ids = array();
var $must_exclude_one_ids = array();
private $phpbb_root_path;
private $php_ext;
private $config;
private $db;
private $user;
/**
* Initialises the fulltext_native search backend with min/max word length and makes sure the UTF-8 normalizer is loaded.
*
* @param boolean|string &$error is passed by reference and should either be set to false on success or an error message on failure.
*/
public function __construct(&$error)
public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
{
global $phpbb_root_path, $phpEx, $config;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$this->config = $config;
$this->db = $db;
$this->user = $user;
$this->word_length = array('min' => $config['fulltext_native_min_chars'], 'max' => $config['fulltext_native_max_chars']);
$this->word_length = array('min' => $this->config['fulltext_native_min_chars'], 'max' => $this->config['fulltext_native_max_chars']);
/**
* Load the UTF tools
*/
if (!class_exists('utf_normalizer'))
{
include($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx);
include($this->phpbb_root_path . 'includes/utf/utf_normalizer.' . $this->php_ext);
}
$error = false;
@ -82,8 +92,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*/
function split_keywords($keywords, $terms)
{
global $db, $user, $config;
$tokens = '+-|()*';
$keywords = trim($this->cleanup($keywords, $tokens));
@ -182,9 +190,9 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$num_keywords = sizeof(explode(' ', $keywords));
// We limit the number of allowed keywords to minimize load on the database
if ($config['max_num_search_keywords'] && $num_keywords > $config['max_num_search_keywords'])
if ($this->config['max_num_search_keywords'] && $num_keywords > $this->config['max_num_search_keywords'])
{
trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], $num_keywords));
trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $this->config['max_num_search_keywords'], $num_keywords));
}
// $keywords input format: each word separated by a space, words in a bracket are not separated
@ -214,12 +222,12 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{
$sql = 'SELECT word_id, word_text, word_common
FROM ' . SEARCH_WORDLIST_TABLE . '
WHERE ' . $db->sql_in_set('word_text', $exact_words) . '
WHERE ' . $this->db->sql_in_set('word_text', $exact_words) . '
ORDER BY word_count ASC';
$result = $db->sql_query($sql);
$result = $this->db->sql_query($sql);
// store an array of words and ids, remove common words
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
if ($row['word_common'])
{
@ -230,7 +238,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$words[$row['word_text']] = (int) $row['word_id'];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
}
unset($exact_words);
@ -301,7 +309,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{
if (strpos($word_part, '*') !== false)
{
$id_words[] = '\'' . $db->sql_escape(str_replace('*', '%', $word_part)) . '\'';
$id_words[] = '\'' . $this->db->sql_escape(str_replace('*', '%', $word_part)) . '\'';
$non_common_words[] = $word_part;
}
else if (isset($words[$word_part]))
@ -346,7 +354,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$len = utf8_strlen(str_replace('*', '', $word));
if ($len >= $this->word_length['min'] && $len <= $this->word_length['max'])
{
$this->{$mode . '_ids'}[] = '\'' . $db->sql_escape(str_replace('*', '%', $word)) . '\'';
$this->{$mode . '_ids'}[] = '\'' . $this->db->sql_escape(str_replace('*', '%', $word)) . '\'';
}
else
{
@ -366,7 +374,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$len = utf8_strlen($word);
if ($len >= $this->word_length['min'] && $len <= $this->word_length['max'])
{
trigger_error(sprintf($user->lang['WORD_IN_NO_POST'], $word));
trigger_error(sprintf($this->user->lang['WORD_IN_NO_POST'], $word));
}
else
{
@ -421,8 +429,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*/
function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
global $config, $db;
// No keywords? No posts.
if (empty($this->search_query))
{
@ -537,7 +543,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
}
$sql_where[] = $db->sql_in_set("m$m_num.word_id", $word_ids);
$sql_where[] = $this->db->sql_in_set("m$m_num.word_id", $word_ids);
unset($word_id_sql);
unset($word_ids);
@ -591,7 +597,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{
$sql_array['LEFT_JOIN'][] = array(
'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num),
'ON' => $db->sql_in_set("m$m_num.word_id", $this->must_not_contain_ids) . (($title_match) ? " AND m$m_num.$title_match" : '') . " AND m$m_num.post_id = m0.post_id"
'ON' => $this->db->sql_in_set("m$m_num.word_id", $this->must_not_contain_ids) . (($title_match) ? " AND m$m_num.$title_match" : '') . " AND m$m_num.post_id = m0.post_id"
);
$sql_where[] = "m$m_num.word_id IS NULL";
@ -632,7 +638,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
else if ($m_approve_fid_ary !== array(-1))
{
$sql_where[] = '(p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
$sql_where[] = '(p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
if ($topic_id)
@ -645,18 +651,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base
if ($author_name)
{
// first one matches post of registered users, second one guests and deleted users
$sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
$sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else
{
$sql_author = $db->sql_in_set('p.poster_id', $author_ary);
$sql_author = $this->db->sql_in_set('p.poster_id', $author_ary);
}
$sql_where[] = $sql_author;
}
if (sizeof($ex_fid_ary))
{
$sql_where[] = $db->sql_in_set('p.forum_id', $ex_fid_ary, true);
$sql_where[] = $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true);
}
if ($sort_days)
@ -681,7 +687,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
);
}
switch ($db->sql_layer)
switch ($this->db->sql_layer)
{
case 'mysql4':
case 'mysqli':
@ -695,17 +701,17 @@ class phpbb_search_fulltext_native extends phpbb_search_base
case 'sqlite':
$sql_array_count['SELECT'] = ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id';
$sql = 'SELECT COUNT(' . (($type == 'posts') ? 'post_id' : 'topic_id') . ') as total_results
FROM (' . $db->sql_build_query('SELECT', $sql_array_count) . ')';
FROM (' . $this->db->sql_build_query('SELECT', $sql_array_count) . ')';
// no break
default:
$sql_array_count['SELECT'] = ($type == 'posts') ? 'COUNT(DISTINCT p.post_id) AS total_results' : 'COUNT(DISTINCT p.topic_id) AS total_results';
$sql = (!$sql) ? $db->sql_build_query('SELECT', $sql_array_count) : $sql;
$sql = (!$sql) ? $this->db->sql_build_query('SELECT', $sql_array_count) : $sql;
$result = $db->sql_query($sql);
$total_results = (int) $db->sql_fetchfield('total_results');
$db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
$total_results = (int) $this->db->sql_fetchfield('total_results');
$this->db->sql_freeresult($result);
if (!$total_results)
{
@ -751,14 +757,14 @@ class phpbb_search_fulltext_native extends phpbb_search_base
unset($sql_where, $sql_sort, $group_by);
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
$sql = $this->db->sql_build_query('SELECT', $sql_array);
$result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = (int) $row[(($type == 'posts') ? 'post_id' : 'topic_id')];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
if (!sizeof($id_ary))
{
@ -772,16 +778,16 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$sql_array_copy = $sql_array;
$sql_array_copy['SELECT'] = 'SQL_CALC_FOUND_ROWS p.post_id ';
$sql = $db->sql_build_query('SELECT', $sql_array_copy);
$sql = $this->db->sql_build_query('SELECT', $sql_array_copy);
unset($sql_array_copy);
$db->sql_query($sql);
$db->sql_freeresult($result);
$this->db->sql_query($sql);
$this->db->sql_freeresult($result);
$sql = 'SELECT FOUND_ROWS() as total_results';
$result = $db->sql_query($sql);
$total_results = (int) $db->sql_fetchfield('total_results');
$db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
$total_results = (int) $this->db->sql_fetchfield('total_results');
$this->db->sql_freeresult($result);
if (!$total_results)
{
@ -819,8 +825,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*/
function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
global $config, $db;
// No author? No posts.
if (!sizeof($author_ary))
{
@ -856,13 +860,13 @@ class phpbb_search_fulltext_native extends phpbb_search_base
if ($author_name)
{
// first one matches post of registered users, second one guests and deleted users
$sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
$sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else
{
$sql_author = $db->sql_in_set('p.poster_id', $author_ary);
$sql_author = $this->db->sql_in_set('p.poster_id', $author_ary);
}
$sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
$sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : '';
$sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : '';
@ -898,7 +902,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
else
{
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
$select = ($type == 'posts') ? 'p.post_id' : 't.topic_id';
@ -907,7 +911,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
// If the cache was completely empty count the results
if (!$total_results)
{
switch ($db->sql_layer)
switch ($this->db->sql_layer)
{
case 'mysql4':
case 'mysqli':
@ -929,7 +933,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
else
{
if ($db->sql_layer == 'sqlite')
if ($this->db->sql_layer == 'sqlite')
{
$sql = 'SELECT COUNT(topic_id) as total_results
FROM (SELECT DISTINCT t.topic_id';
@ -946,12 +950,12 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$m_approve_fid_sql
$sql_fora
AND t.topic_id = p.topic_id
$sql_time" . (($db->sql_layer == 'sqlite') ? ')' : '');
$sql_time" . (($this->db->sql_layer == 'sqlite') ? ')' : '');
}
$result = $db->sql_query($sql);
$result = $this->db->sql_query($sql);
$total_results = (int) $db->sql_fetchfield('total_results');
$db->sql_freeresult($result);
$total_results = (int) $this->db->sql_fetchfield('total_results');
$this->db->sql_freeresult($result);
if (!$total_results)
{
@ -994,26 +998,26 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
// Only read one block of posts from the db and then cache it
$result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
$result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = (int) $row[$field];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
if (!$total_results && $is_mysql)
{
// Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it.
$sql = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql);
$db->sql_query($sql);
$db->sql_freeresult($result);
$this->db->sql_query($sql);
$this->db->sql_freeresult($result);
$sql = 'SELECT FOUND_ROWS() as total_results';
$result = $db->sql_query($sql);
$total_results = (int) $db->sql_fetchfield('total_results');
$db->sql_freeresult($result);
$result = $this->db->sql_query($sql);
$total_results = (int) $this->db->sql_fetchfield('total_results');
$this->db->sql_freeresult($result);
if (!$total_results)
{
@ -1046,8 +1050,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*/
function split_message($text)
{
global $phpbb_root_path, $phpEx, $user;
$match = $words = array();
/**
@ -1125,9 +1127,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*/
function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
{
global $config, $db, $user;
if (!$config['fulltext_native_load_upd'])
if (!$this->config['fulltext_native_load_upd'])
{
/**
* The search indexer is disabled, return
@ -1153,14 +1153,14 @@ class phpbb_search_fulltext_native extends phpbb_search_base
FROM ' . SEARCH_WORDLIST_TABLE . ' w, ' . SEARCH_WORDMATCH_TABLE . " m
WHERE m.post_id = $post_id
AND w.word_id = m.word_id";
$result = $db->sql_query($sql);
$result = $this->db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$which = ($row['title_match']) ? 'title' : 'post';
$cur_words[$which][$row['word_text']] = $row['word_id'];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
$words['add']['post'] = array_diff($split_text, array_keys($cur_words['post']));
$words['add']['title'] = array_diff($split_title, array_keys($cur_words['title']));
@ -1188,18 +1188,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{
$sql = 'SELECT word_id, word_text
FROM ' . SEARCH_WORDLIST_TABLE . '
WHERE ' . $db->sql_in_set('word_text', $unique_add_words);
$result = $db->sql_query($sql);
WHERE ' . $this->db->sql_in_set('word_text', $unique_add_words);
$result = $this->db->sql_query($sql);
$word_ids = array();
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$word_ids[$row['word_text']] = $row['word_id'];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
$new_words = array_diff($unique_add_words, array_keys($word_ids));
$db->sql_transaction('begin');
$this->db->sql_transaction('begin');
if (sizeof($new_words))
{
$sql_ary = array();
@ -1208,15 +1208,15 @@ class phpbb_search_fulltext_native extends phpbb_search_base
{
$sql_ary[] = array('word_text' => (string) $word, 'word_count' => 0);
}
$db->sql_return_on_error(true);
$db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary);
$db->sql_return_on_error(false);
$this->db->sql_return_on_error(true);
$this->db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary);
$this->db->sql_return_on_error(false);
}
unset($new_words, $sql_ary);
}
else
{
$db->sql_transaction('begin');
$this->db->sql_transaction('begin');
}
// now update the search match table, remove links to removed words and add links to new words
@ -1233,22 +1233,22 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . '
WHERE ' . $db->sql_in_set('word_id', $sql_in) . '
WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . '
AND post_id = ' . intval($post_id) . "
AND title_match = $title_match";
$db->sql_query($sql);
$this->db->sql_query($sql);
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count - 1
WHERE ' . $db->sql_in_set('word_id', $sql_in) . '
WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . '
AND word_count > 0';
$db->sql_query($sql);
$this->db->sql_query($sql);
unset($sql_in);
}
}
$db->sql_return_on_error(true);
$this->db->sql_return_on_error(true);
foreach ($words['add'] as $word_in => $word_ary)
{
$title_match = ($word_in == 'title') ? 1 : 0;
@ -1258,18 +1258,18 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$sql = 'INSERT INTO ' . SEARCH_WORDMATCH_TABLE . ' (post_id, word_id, title_match)
SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . '
FROM ' . SEARCH_WORDLIST_TABLE . '
WHERE ' . $db->sql_in_set('word_text', $word_ary);
$db->sql_query($sql);
WHERE ' . $this->db->sql_in_set('word_text', $word_ary);
$this->db->sql_query($sql);
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count + 1
WHERE ' . $db->sql_in_set('word_text', $word_ary);
$db->sql_query($sql);
WHERE ' . $this->db->sql_in_set('word_text', $word_ary);
$this->db->sql_query($sql);
}
}
$db->sql_return_on_error(false);
$this->db->sql_return_on_error(false);
$db->sql_transaction('commit');
$this->db->sql_transaction('commit');
// destroy cached search results containing any of the words removed or added
$this->destroy_cache(array_unique(array_merge($words['add']['post'], $words['add']['title'], $words['del']['post'], $words['del']['title'])), array($poster_id));
@ -1284,18 +1284,16 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*/
function index_remove($post_ids, $author_ids, $forum_ids)
{
global $db;
if (sizeof($post_ids))
{
$sql = 'SELECT w.word_id, w.word_text, m.title_match
FROM ' . SEARCH_WORDMATCH_TABLE . ' m, ' . SEARCH_WORDLIST_TABLE . ' w
WHERE ' . $db->sql_in_set('m.post_id', $post_ids) . '
WHERE ' . $this->db->sql_in_set('m.post_id', $post_ids) . '
AND w.word_id = m.word_id';
$result = $db->sql_query($sql);
$result = $this->db->sql_query($sql);
$message_word_ids = $title_word_ids = $word_texts = array();
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
if ($row['title_match'])
{
@ -1307,32 +1305,32 @@ class phpbb_search_fulltext_native extends phpbb_search_base
}
$word_texts[] = $row['word_text'];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
if (sizeof($title_word_ids))
{
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count - 1
WHERE ' . $db->sql_in_set('word_id', $title_word_ids) . '
WHERE ' . $this->db->sql_in_set('word_id', $title_word_ids) . '
AND word_count > 0';
$db->sql_query($sql);
$this->db->sql_query($sql);
}
if (sizeof($message_word_ids))
{
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_count = word_count - 1
WHERE ' . $db->sql_in_set('word_id', $message_word_ids) . '
WHERE ' . $this->db->sql_in_set('word_id', $message_word_ids) . '
AND word_count > 0';
$db->sql_query($sql);
$this->db->sql_query($sql);
}
unset($title_word_ids);
unset($message_word_ids);
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . '
WHERE ' . $db->sql_in_set('post_id', $post_ids);
$db->sql_query($sql);
WHERE ' . $this->db->sql_in_set('post_id', $post_ids);
$this->db->sql_query($sql);
}
$this->destroy_cache(array_unique($word_texts), array_unique($author_ids));
@ -1344,11 +1342,9 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*/
function tidy()
{
global $db, $config;
// Is the fulltext indexer disabled? If yes then we need not
// carry on ... it's okay ... I know when I'm not wanted boo hoo
if (!$config['fulltext_native_load_upd'])
if (!$this->config['fulltext_native_load_upd'])
{
set_config('search_last_gc', time(), true);
return;
@ -1357,31 +1353,31 @@ class phpbb_search_fulltext_native extends phpbb_search_base
$destroy_cache_words = array();
// Remove common words
if ($config['num_posts'] >= 100 && $config['fulltext_native_common_thres'])
if ($this->config['num_posts'] >= 100 && $this->config['fulltext_native_common_thres'])
{
$common_threshold = ((double) $config['fulltext_native_common_thres']) / 100.0;
$common_threshold = ((double) $this->config['fulltext_native_common_thres']) / 100.0;
// First, get the IDs of common words
$sql = 'SELECT word_id, word_text
FROM ' . SEARCH_WORDLIST_TABLE . '
WHERE word_count > ' . floor($config['num_posts'] * $common_threshold) . '
WHERE word_count > ' . floor($this->config['num_posts'] * $common_threshold) . '
OR word_common = 1';
$result = $db->sql_query($sql);
$result = $this->db->sql_query($sql);
$sql_in = array();
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$sql_in[] = $row['word_id'];
$destroy_cache_words[] = $row['word_text'];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
if (sizeof($sql_in))
{
// Flag the words
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
SET word_common = 1
WHERE ' . $db->sql_in_set('word_id', $sql_in);
$db->sql_query($sql);
WHERE ' . $this->db->sql_in_set('word_id', $sql_in);
$this->db->sql_query($sql);
// by setting search_last_gc to the new time here we make sure that if a user reloads because the
// following query takes too long, he won't run into it again
@ -1389,8 +1385,8 @@ class phpbb_search_fulltext_native extends phpbb_search_base
// Delete the matches
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . '
WHERE ' . $db->sql_in_set('word_id', $sql_in);
$db->sql_query($sql);
WHERE ' . $this->db->sql_in_set('word_id', $sql_in);
$this->db->sql_query($sql);
}
unset($sql_in);
}
@ -1409,21 +1405,19 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*/
function delete_index($acp_module, $u_action)
{
global $db;
switch ($db->sql_layer)
switch ($this->db->sql_layer)
{
case 'sqlite':
case 'firebird':
$db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE);
$db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE);
$db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE);
$this->db->sql_query('DELETE FROM ' . SEARCH_WORDLIST_TABLE);
$this->db->sql_query('DELETE FROM ' . SEARCH_WORDMATCH_TABLE);
$this->db->sql_query('DELETE FROM ' . SEARCH_RESULTS_TABLE);
break;
default:
$db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE);
$db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE);
$db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE);
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE);
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
break;
}
}
@ -1446,24 +1440,20 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*/
function index_stats()
{
global $user;
if (!sizeof($this->stats))
{
$this->get_stats();
}
return array(
$user->lang['TOTAL_WORDS'] => $this->stats['total_words'],
$user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']);
$this->user->lang['TOTAL_WORDS'] => $this->stats['total_words'],
$this->user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']);
}
function get_stats()
{
global $db;
$this->stats['total_words'] = $db->get_estimated_row_count(SEARCH_WORDLIST_TABLE);
$this->stats['total_matches'] = $db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE);
$this->stats['total_words'] = $this->db->get_estimated_row_count(SEARCH_WORDLIST_TABLE);
$this->stats['total_matches'] = $this->db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE);
}
/**
@ -1483,7 +1473,6 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*/
function cleanup($text, $allowed_chars = null, $encoding = 'utf-8')
{
global $phpbb_root_path, $phpEx;
static $conv = array(), $conv_loaded = array();
$words = $allow = array();
@ -1680,7 +1669,7 @@ class phpbb_search_fulltext_native extends phpbb_search_base
if (!isset($conv_loaded[$idx]))
{
$conv_loaded[$idx] = 1;
$file = $phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $phpEx;
$file = $this->phpbb_root_path . 'includes/utf/data/search_indexer_' . $idx . '.' . $this->php_ext;
if (file_exists($file))
{
@ -1713,29 +1702,26 @@ class phpbb_search_fulltext_native extends phpbb_search_base
*/
function acp()
{
global $user, $config;
/**
* if we need any options, copied from fulltext_native for now, will have to be adjusted or removed
*/
$tpl = '
<dl>
<dt><label for="fulltext_native_load_upd">' . $user->lang['YES_SEARCH_UPDATE'] . ':</label><br /><span>' . $user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '</span></dt>
<dd><label><input type="radio" id="fulltext_native_load_upd" name="config[fulltext_native_load_upd]" value="1"' . (($config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $user->lang['YES'] . '</label><label><input type="radio" name="config[fulltext_native_load_upd]" value="0"' . ((!$config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $user->lang['NO'] . '</label></dd>
<dt><label for="fulltext_native_load_upd">' . $this->user->lang['YES_SEARCH_UPDATE'] . ':</label><br /><span>' . $this->user->lang['YES_SEARCH_UPDATE_EXPLAIN'] . '</span></dt>
<dd><label><input type="radio" id="fulltext_native_load_upd" name="config[fulltext_native_load_upd]" value="1"' . (($this->config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $this->user->lang['YES'] . '</label><label><input type="radio" name="config[fulltext_native_load_upd]" value="0"' . ((!$this->config['fulltext_native_load_upd']) ? ' checked="checked"' : '') . ' class="radio" /> ' . $this->user->lang['NO'] . '</label></dd>
</dl>
<dl>
<dt><label for="fulltext_native_min_chars">' . $user->lang['MIN_SEARCH_CHARS'] . ':</label><br /><span>' . $user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dd><input id="fulltext_native_min_chars" type="text" size="3" maxlength="3" name="config[fulltext_native_min_chars]" value="' . (int) $config['fulltext_native_min_chars'] . '" /></dd>
<dt><label for="fulltext_native_min_chars">' . $this->user->lang['MIN_SEARCH_CHARS'] . ':</label><br /><span>' . $this->user->lang['MIN_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dd><input id="fulltext_native_min_chars" type="text" size="3" maxlength="3" name="config[fulltext_native_min_chars]" value="' . (int) $this->config['fulltext_native_min_chars'] . '" /></dd>
</dl>
<dl>
<dt><label for="fulltext_native_max_chars">' . $user->lang['MAX_SEARCH_CHARS'] . ':</label><br /><span>' . $user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dd><input id="fulltext_native_max_chars" type="text" size="3" maxlength="3" name="config[fulltext_native_max_chars]" value="' . (int) $config['fulltext_native_max_chars'] . '" /></dd>
<dt><label for="fulltext_native_max_chars">' . $this->user->lang['MAX_SEARCH_CHARS'] . ':</label><br /><span>' . $this->user->lang['MAX_SEARCH_CHARS_EXPLAIN'] . '</span></dt>
<dd><input id="fulltext_native_max_chars" type="text" size="3" maxlength="3" name="config[fulltext_native_max_chars]" value="' . (int) $this->config['fulltext_native_max_chars'] . '" /></dd>
</dl>
<dl>
<dt><label for="fulltext_native_common_thres">' . $user->lang['COMMON_WORD_THRESHOLD'] . ':</label><br /><span>' . $user->lang['COMMON_WORD_THRESHOLD_EXPLAIN'] . '</span></dt>
<dd><input id="fulltext_native_common_thres" type="text" size="3" maxlength="3" name="config[fulltext_native_common_thres]" value="' . (double) $config['fulltext_native_common_thres'] . '" /> %</dd>
<dt><label for="fulltext_native_common_thres">' . $this->user->lang['COMMON_WORD_THRESHOLD'] . ':</label><br /><span>' . $this->user->lang['COMMON_WORD_THRESHOLD_EXPLAIN'] . '</span></dt>
<dd><input id="fulltext_native_common_thres" type="text" size="3" maxlength="3" name="config[fulltext_native_common_thres]" value="' . (double) $this->config['fulltext_native_common_thres'] . '" /> %</dd>
</dl>
';

View file

@ -28,6 +28,9 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
private $version;
private $tsearch_query;
private $phrase_search = false;
private $config;
private $db;
private $user;
public $search_query;
public $common_words = array();
public $word_length = array();
@ -38,16 +41,17 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*
* @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false
*/
public function __construct(&$error)
public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
{
global $db, $config;
$this->config = $config;
$this->db = $db;
$this->user = $user;
$this->word_length = array('min' => $config['fulltext_postgres_min_word_len'], 'max' => $config['fulltext_postgres_max_word_len']);
$this->word_length = array('min' => $this->config['fulltext_postgres_min_word_len'], 'max' => $this->config['fulltext_postgres_max_word_len']);
if ($db->sql_layer == 'postgres')
if ($this->db->sql_layer == 'postgres')
{
$pgsql_version = explode(',', substr($db->sql_server_info(), 10));
$pgsql_version = explode(',', substr($this->db->sql_server_info(), 10));
$this->version = trim($pgsql_version[0]);
if (version_compare($this->version, '8.3', '>='))
{
@ -91,16 +95,14 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function init()
{
global $db, $user;
if ($db->sql_layer != 'postgres')
if ($this->db->sql_layer != 'postgres')
{
return $user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE'];
return $this->user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE'];
}
if (!$this->tsearch_usable)
{
return $user->lang['FULLTEXT_POSTGRES_TS_NOT_USABLE'];
return $this->user->lang['FULLTEXT_POSTGRES_TS_NOT_USABLE'];
}
return false;
@ -118,8 +120,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function split_keywords(&$keywords, $terms)
{
global $config;
if ($terms == 'all')
{
$match = array('#\sand\s#iu', '#\sor\s#iu', '#\snot\s#iu', '#\+#', '#-#', '#\|#');
@ -143,7 +143,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
// check word length
$clean_len = utf8_strlen(str_replace('*', '', $clean_word));
if (($clean_len < $config['fulltext_postgres_min_word_len']) || ($clean_len > $config['fulltext_postgres_max_word_len']))
if (($clean_len < $this->config['fulltext_postgres_min_word_len']) || ($clean_len > $this->config['fulltext_postgres_max_word_len']))
{
$this->common_words[] = $word;
unset($this->split_words[$i]);
@ -213,8 +213,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function split_message($text)
{
global $config;
// Split words
$text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text)));
$matches = array();
@ -226,7 +224,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
for ($i = 0, $n = sizeof($text); $i < $n; $i++)
{
$text[$i] = trim($text[$i]);
if (utf8_strlen($text[$i]) < $config['fulltext_postgres_min_word_len'] || utf8_strlen($text[$i]) > $config['fulltext_postgres_max_word_len'])
if (utf8_strlen($text[$i]) < $this->config['fulltext_postgres_min_word_len'] || utf8_strlen($text[$i]) > $this->config['fulltext_postgres_max_word_len'])
{
unset($text[$i]);
}
@ -259,8 +257,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
global $config, $db;
// No keywords? No posts.
if (!$this->search_query)
{
@ -349,7 +345,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
}
else
{
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
$sql_select = ($type == 'posts') ? 'p.post_id' : 'DISTINCT t.topic_id';
@ -360,11 +356,11 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
if (sizeof($author_ary) && $author_name)
{
// first one matches post of registered users, second one guests and deleted users
$sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
$sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else if (sizeof($author_ary))
{
$sql_author = ' AND ' . $db->sql_in_set('p.poster_id', $author_ary);
$sql_author = ' AND ' . $this->db->sql_in_set('p.poster_id', $author_ary);
}
else
{
@ -374,7 +370,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
$sql_where_options = $sql_sort_join;
$sql_where_options .= ($topic_id) ? ' AND p.topic_id = ' . $topic_id : '';
$sql_where_options .= ($join_topic) ? ' AND t.topic_id = p.topic_id' : '';
$sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_where_options .= $m_approve_fid_sql;
$sql_where_options .= $sql_author;
$sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
@ -383,7 +379,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
$tmp_sql_match = array();
foreach (explode(',', $sql_match) as $sql_match_column)
{
$tmp_sql_match[] = "to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', " . $sql_match_column . ") @@ to_tsquery ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', '" . $db->sql_escape($this->tsearch_query) . "')";
$tmp_sql_match[] = "to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', " . $sql_match_column . ") @@ to_tsquery ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', '" . $this->db->sql_escape($this->tsearch_query) . "')";
}
$sql = "SELECT $sql_select
@ -391,13 +387,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
WHERE (" . implode(' OR ', $tmp_sql_match) . ")
$sql_where_options
ORDER BY $sql_sort";
$result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
$result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = $row[$field];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
$id_ary = array_unique($id_ary);
@ -447,8 +443,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
{
global $config, $db;
// No author? No posts.
if (!sizeof($author_ary))
{
@ -484,13 +478,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
if ($author_name)
{
// first one matches post of registered users, second one guests and deleted users
$sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
$sql_author = '(' . $this->db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')';
}
else
{
$sql_author = $db->sql_in_set('p.poster_id', $author_ary);
$sql_author = $this->db->sql_in_set('p.poster_id', $author_ary);
}
$sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $this->db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
$sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : '';
$sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
$sql_firstpost = ($firstpost_only) ? ' AND p.post_id = t.topic_first_post_id' : '';
@ -526,7 +520,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
}
else
{
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
$m_approve_fid_sql = ' AND (p.post_approved = 1 OR ' . $this->db->sql_in_set('p.forum_id', $m_approve_fid_ary, true) . ')';
}
// Build the query for really selecting the post_ids
@ -562,13 +556,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
}
// Only read one block of posts from the db and then cache it
$result = $db->sql_query_limit($sql, $config['search_block_size'], $start);
$result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start);
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$id_ary[] = $row[$field];
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
// retrieve the total result count if needed
if (!$result_count)
@ -605,8 +599,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
{
global $db;
// Split old and new post/subject to obtain array of words
$split_text = $this->split_message($message);
$split_title = ($subject) ? $this->split_message($subject) : array();
@ -639,8 +631,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function tidy()
{
global $db, $config;
// destroy too old cached search results
$this->destroy_cache(array());
@ -656,8 +646,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function create_index($acp_module, $u_action)
{
global $db, $config;
// Make sure we can actually use PostgreSQL with fulltext indexes
if ($error = $this->init())
{
@ -671,15 +659,15 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
if (!isset($this->stats['post_subject']))
{
$db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $config['fulltext_postgres_ts_name'] . "_post_subject ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', post_subject))");
$this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_subject ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_subject))");
}
if (!isset($this->stats['post_text']))
{
$db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $config['fulltext_postgres_ts_name'] . "_post_text ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $db->sql_escape($config['fulltext_postgres_ts_name']) . "', post_text))");
$this->db->sql_query("CREATE INDEX " . POSTS_TABLE . "_" . $this->config['fulltext_postgres_ts_name'] . "_post_text ON " . POSTS_TABLE . " USING gin (to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', post_text))");
}
$db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
return false;
}
@ -693,8 +681,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function delete_index($acp_module, $u_action)
{
global $db;
// Make sure we can actually use PostgreSQL with fulltext indexes
if ($error = $this->init())
{
@ -708,15 +694,15 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
if (isset($this->stats['post_subject']))
{
$db->sql_query('DROP INDEX ' . $this->stats['post_subject']['relname']);
$this->db->sql_query('DROP INDEX ' . $this->stats['post_subject']['relname']);
}
if (isset($this->stats['post_text']))
{
$db->sql_query('DROP INDEX ' . $this->stats['post_text']['relname']);
$this->db->sql_query('DROP INDEX ' . $this->stats['post_text']['relname']);
}
$db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
return false;
}
@ -743,15 +729,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function index_stats()
{
global $user;
if (empty($this->stats))
{
$this->get_stats();
}
return array(
$user->lang['FULLTEXT_POSTGRES_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
$this->user->lang['FULLTEXT_POSTGRES_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
);
}
@ -762,9 +746,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function get_stats()
{
global $db, $config;
if ($db->sql_layer != 'postgres')
if ($this->db->sql_layer != 'postgres')
{
$this->stats = array();
return;
@ -776,26 +758,26 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
AND pg_catalog.pg_table_is_visible(c1.oid)
AND c1.oid = i.indrelid
AND i.indexrelid = c2.oid";
$result = $db->sql_query($sql);
$result = $this->db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
// deal with older PostgreSQL versions which didn't use Index_type
if (strpos($row['indexdef'], 'to_tsvector') !== false)
{
if ($row['relname'] == POSTS_TABLE . '_' . $config['fulltext_postgres_ts_name'] . '_post_text' || $row['relname'] == POSTS_TABLE . '_post_text')
if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_text' || $row['relname'] == POSTS_TABLE . '_post_text')
{
$this->stats['post_text'] = $row;
}
else if ($row['relname'] == POSTS_TABLE . '_' . $config['fulltext_postgres_ts_name'] . '_post_subject' || $row['relname'] == POSTS_TABLE . '_post_subject')
else if ($row['relname'] == POSTS_TABLE . '_' . $this->config['fulltext_postgres_ts_name'] . '_post_subject' || $row['relname'] == POSTS_TABLE . '_post_subject')
{
$this->stats['post_subject'] = $row;
}
}
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
$this->stats['total_posts'] = $config['num_posts'];
$this->stats['total_posts'] = $this->config['num_posts'];
}
/**
@ -807,43 +789,41 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base
*/
function acp()
{
global $user, $config, $db;
$tpl = '
<dl>
<dt><label>' . $user->lang['FULLTEXT_POSTGRES_VERSION_CHECK'] . '</label><br /><span>' . $user->lang['FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN'] . '</span></dt>
<dd>' . (($this->tsearch_usable) ? $user->lang['YES'] : $user->lang['NO']) . ' (PostgreSQL ' . $this->version . ')</dd>
<dt><label>' . $this->user->lang['FULLTEXT_POSTGRES_VERSION_CHECK'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_VERSION_CHECK_EXPLAIN'] . '</span></dt>
<dd>' . (($this->tsearch_usable) ? $this->user->lang['YES'] : $this->user->lang['NO']) . ' (PostgreSQL ' . $this->version . ')</dd>
</dl>
<dl>
<dt><label>' . $user->lang['FULLTEXT_POSTGRES_TS_NAME'] . '</label><br /><span>' . $user->lang['FULLTEXT_POSTGRES_TS_NAME_EXPLAIN'] . '</span></dt>
<dt><label>' . $this->user->lang['FULLTEXT_POSTGRES_TS_NAME'] . '</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_TS_NAME_EXPLAIN'] . '</span></dt>
<dd><select name="config[fulltext_postgres_ts_name]">';
if ($db->sql_layer == 'postgres' && $this->tsearch_usable)
if ($this->db->sql_layer == 'postgres' && $this->tsearch_usable)
{
$sql = 'SELECT cfgname AS ts_name
FROM pg_ts_config';
$result = $db->sql_query($sql);
$result = $this->db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
while ($row = $this->db->sql_fetchrow($result))
{
$tpl .= '<option value="' . $row['ts_name'] . '"' . ($row['ts_name'] === $config['fulltext_postgres_ts_name'] ? ' selected="selected"' : '') . '>' . $row['ts_name'] . '</option>';
$tpl .= '<option value="' . $row['ts_name'] . '"' . ($row['ts_name'] === $this->config['fulltext_postgres_ts_name'] ? ' selected="selected"' : '') . '>' . $row['ts_name'] . '</option>';
}
$db->sql_freeresult($result);
$this->db->sql_freeresult($result);
}
else
{
$tpl .= '<option value="' . $config['fulltext_postgres_ts_name'] . '" selected="selected">' . $config['fulltext_postgres_ts_name'] . '</option>';
$tpl .= '<option value="' . $this->config['fulltext_postgres_ts_name'] . '" selected="selected">' . $this->config['fulltext_postgres_ts_name'] . '</option>';
}
$tpl .= '</select></dd>
</dl>
<dl>
<dt><label for="fulltext_postgres_min_word_len">' . $user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN'] . ':</label><br /><span>' . $user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN'] . '</span></dt>
<dd><input id="fulltext_postgres_min_word_len" type="text" size="3" maxlength="3" name="config[fulltext_postgres_min_word_len]" value="' . (int) $config['fulltext_postgres_min_word_len'] . '" /></dd>
<dt><label for="fulltext_postgres_min_word_len">' . $this->user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN'] . ':</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_MIN_WORD_LEN_EXPLAIN'] . '</span></dt>
<dd><input id="fulltext_postgres_min_word_len" type="text" size="3" maxlength="3" name="config[fulltext_postgres_min_word_len]" value="' . (int) $this->config['fulltext_postgres_min_word_len'] . '" /></dd>
</dl>
<dl>
<dt><label for="fulltext_postgres_max_word_len">' . $user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN'] . ':</label><br /><span>' . $user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN'] . '</span></dt>
<dd><input id="fulltext_postgres_max_word_len" type="text" size="3" maxlength="3" name="config[fulltext_postgres_max_word_len]" value="' . (int) $config['fulltext_postgres_max_word_len'] . '" /></dd>
<dt><label for="fulltext_postgres_max_word_len">' . $this->user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN'] . ':</label><br /><span>' . $this->user->lang['FULLTEXT_POSTGRES_MAX_WORD_LEN_EXPLAIN'] . '</span></dt>
<dd><input id="fulltext_postgres_max_word_len" type="text" size="3" maxlength="3" name="config[fulltext_postgres_max_word_len]" value="' . (int) $this->config['fulltext_postgres_max_word_len'] . '" /></dd>
</dl>
';

View file

@ -17,13 +17,6 @@ if (!defined('IN_PHPBB'))
/**
* @ignore
*/
/**
* This statement is necessary as this file is sometimes included from within a
* function and the variables used are in global space.
*/
global $phpbb_root_path, $phpEx, $table_prefix;
require($phpbb_root_path . 'includes/sphinxapi.' . $phpEx);
define('SPHINX_MAX_MATCHES', 20000);
define('SPHINX_CONNECT_RETRIES', 3);
define('SPHINX_CONNECT_WAIT_TIME', 300);
@ -40,6 +33,8 @@ class phpbb_search_fulltext_sphinx
private $id;
private $indexes;
private $sphinx;
private $phpbb_root_path;
private $php_ext;
private $auth;
private $config;
private $db;
@ -56,9 +51,10 @@ class phpbb_search_fulltext_sphinx
*
* @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false
*/
public function __construct(&$error)
public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
{
global $config, $db, $user, $auth, $phpbb_root_path, $phpEx;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$this->config = $config;
$this->user = $user;
$this->db = $db;
@ -66,7 +62,7 @@ class phpbb_search_fulltext_sphinx
if (!class_exists('phpbb_db_tools'))
{
require($phpbb_root_path . 'includes/db/db_tools.' . $phpEx);
require($this->phpbb_root_path . 'includes/db/db_tools.' . $this->php_ext);
}
// Initialize phpbb_db_tools object
@ -79,6 +75,12 @@ class phpbb_search_fulltext_sphinx
$this->id = $this->config['fulltext_sphinx_id'];
$this->indexes = 'index_phpbb_' . $this->id . '_delta;index_phpbb_' . $this->id . '_main';
if (!class_exists('SphinxClient'))
{
require($this->phpbb_root_path . 'includes/sphinxapi.' . $this->php_ext);
}
// Initialize sphinx client
$this->sphinx = new SphinxClient();
$this->sphinx->SetServer(($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost'), ($this->config['fulltext_sphinx_port'] ? (int) $this->config['fulltext_sphinx_port'] : 9312));
@ -127,8 +129,6 @@ class phpbb_search_fulltext_sphinx
*/
function config_generate()
{
global $phpbb_root_path, $phpEx;
// Check if Database is supported by Sphinx
if ($this->db->sql_layer =='mysql' || $this->db->sql_layer == 'mysql4' || $this->db->sql_layer == 'mysqli')
{
@ -151,7 +151,7 @@ class phpbb_search_fulltext_sphinx
return false;
}
include($phpbb_root_path . 'config.' . $phpEx);
include($this->phpbb_root_path . 'config.' . $this->php_ext);
/* Now that we're sure everything was entered correctly,
generate a config for the index. We use a config value

View file

@ -280,7 +280,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
}
// We do some additional checks in the module to ensure it can actually be utilised
$error = false;
$search = new $search_type($error);
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user);
if ($error)
{