[ticket/12683] Pass tables via parameter and small fix

PHPBB3-12683
This commit is contained in:
rubencm 2021-04-09 19:36:54 +02:00 committed by Ruben Calvo
parent 565c806eda
commit f4977853be
No known key found for this signature in database
16 changed files with 132 additions and 103 deletions

View file

@ -4,7 +4,7 @@ services:
class: phpbb\search\state_helper class: phpbb\search\state_helper
arguments: arguments:
- '@config' - '@config'
- '@search.backend_collection' - '@search.backend_factory'
# Search backends # Search backends
search.fulltext.mysql: search.fulltext.mysql:
@ -15,6 +15,7 @@ services:
- '@dispatcher' - '@dispatcher'
- '@language' - '@language'
- '@user' - '@user'
- '%tables.search_results%'
- '%core.root_path%' - '%core.root_path%'
- '%core.php_ext%' - '%core.php_ext%'
tags: tags:
@ -28,6 +29,9 @@ services:
- '@dispatcher' - '@dispatcher'
- '@language' - '@language'
- '@user' - '@user'
- '%tables.search_results%'
- '%tables.search_wordlist%'
- '%tables.search_wordmatch%'
- '%core.root_path%' - '%core.root_path%'
- '%core.php_ext%' - '%core.php_ext%'
tags: tags:
@ -41,6 +45,7 @@ services:
- '@dispatcher' - '@dispatcher'
- '@language' - '@language'
- '@user' - '@user'
- '%tables.search_results%'
- '%core.root_path%' - '%core.root_path%'
- '%core.php_ext%' - '%core.php_ext%'
tags: tags:

View file

@ -322,6 +322,8 @@ class acp_search
$this->page_title = 'ACP_SEARCH_INDEX'; $this->page_title = 'ACP_SEARCH_INDEX';
foreach ($this->search_backend_collection as $search) foreach ($this->search_backend_collection as $search)
{
if ($search->is_available())
{ {
$this->template->assign_block_vars('backends', [ $this->template->assign_block_vars('backends', [
'NAME' => $search->get_name(), 'NAME' => $search->get_name(),
@ -332,13 +334,14 @@ class acp_search
'S_INDEXED' => $search->index_created(), 'S_INDEXED' => $search->index_created(),
'S_STATS' => $search->index_stats(), 'S_STATS' => $search->index_stats(),
]); ]);
}
$this->template->assign_vars([ $this->template->assign_vars([
'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'), 'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'),
'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'), 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
]); ]);
} }
}
}
/** /**
* Form to continue or cancel indexing process * Form to continue or cancel indexing process

View file

@ -146,7 +146,7 @@ class create extends command
$io->newLine(2); $io->newLine(2);
} }
catch(index_created_exception $e) catch (index_created_exception $e)
{ {
$this->state_helper->clear_state(); $this->state_helper->clear_state();
$io->error($this->language->lang('CLI_SEARCHINDEX_ALREADY_CREATED', $name)); $io->error($this->language->lang('CLI_SEARCHINDEX_ALREADY_CREATED', $name));

View file

@ -146,7 +146,7 @@ class delete extends command
$io->newLine(2); $io->newLine(2);
} }
catch(index_empty_exception $e) catch (index_empty_exception $e)
{ {
$this->state_helper->clear_state(); $this->state_helper->clear_state();
$io->error($this->language->lang('CLI_SEARCHINDEX_NO_CREATED', $name)); $io->error($this->language->lang('CLI_SEARCHINDEX_NO_CREATED', $name));

View file

@ -13,7 +13,6 @@
namespace phpbb\post; namespace phpbb\post;
use phpbb\db\driver\driver_interface; use phpbb\db\driver\driver_interface;
class post_helper class post_helper

View file

@ -53,6 +53,11 @@ abstract class base implements search_backend_interface
*/ */
protected $user; protected $user;
/**
* @var string
*/
protected $search_results_table;
/** /**
* Constructor. * Constructor.
* *
@ -60,13 +65,15 @@ abstract class base implements search_backend_interface
* @param config $config * @param config $config
* @param driver_interface $db * @param driver_interface $db
* @param user $user * @param user $user
* @param string $search_results_table
*/ */
public function __construct(service $cache, config $config, driver_interface $db, user $user) public function __construct(service $cache, config $config, driver_interface $db, user $user, string $search_results_table)
{ {
$this->cache = $cache; $this->cache = $cache;
$this->config = $config; $this->config = $config;
$this->db = $db; $this->db = $db;
$this->user = $user; $this->user = $user;
$this->search_results_table = $search_results_table;
} }
/** /**
@ -182,7 +189,7 @@ abstract class base implements search_backend_interface
if (!empty($keywords) || count($author_ary)) if (!empty($keywords) || count($author_ary))
{ {
$sql = 'SELECT search_time $sql = 'SELECT search_time
FROM ' . SEARCH_RESULTS_TABLE . ' FROM ' . $this->search_results_table . '
WHERE search_key = \'' . $this->db->sql_escape($search_key) . '\''; WHERE search_key = \'' . $this->db->sql_escape($search_key) . '\'';
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
@ -195,7 +202,7 @@ abstract class base implements search_backend_interface
'search_authors' => ' ' . implode(' ', $author_ary) . ' ' 'search_authors' => ' ' . implode(' ', $author_ary) . ' '
); );
$sql = 'INSERT INTO ' . SEARCH_RESULTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $sql = 'INSERT INTO ' . $this->search_results_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
$this->db->sql_query($sql); $this->db->sql_query($sql);
} }
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
@ -255,7 +262,7 @@ abstract class base implements search_backend_interface
} }
$this->cache->put('_search_results_' . $search_key, $store, $this->config['search_store_results']); $this->cache->put('_search_results_' . $search_key, $store, $this->config['search_store_results']);
$sql = 'UPDATE ' . SEARCH_RESULTS_TABLE . ' $sql = 'UPDATE ' . $this->search_results_table . '
SET search_time = ' . time() . ' SET search_time = ' . time() . '
WHERE search_key = \'' . $this->db->sql_escape($search_key) . '\''; WHERE search_key = \'' . $this->db->sql_escape($search_key) . '\'';
$this->db->sql_query($sql); $this->db->sql_query($sql);
@ -282,7 +289,7 @@ abstract class base implements search_backend_interface
} }
$sql = 'SELECT search_key $sql = 'SELECT search_key
FROM ' . SEARCH_RESULTS_TABLE . " FROM ' . $this->search_results_table . "
WHERE search_keywords LIKE '%*%' $sql_where"; WHERE search_keywords LIKE '%*%' $sql_where";
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
@ -303,7 +310,7 @@ abstract class base implements search_backend_interface
} }
$sql = 'SELECT search_key $sql = 'SELECT search_key
FROM ' . SEARCH_RESULTS_TABLE . " FROM ' . $this->search_results_table . "
WHERE $sql_where"; WHERE $sql_where";
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
@ -315,7 +322,7 @@ abstract class base implements search_backend_interface
} }
$sql = 'DELETE $sql = 'DELETE
FROM ' . SEARCH_RESULTS_TABLE . ' FROM ' . $this->search_results_table . '
WHERE search_time < ' . (time() - (int) $this->config['search_store_results']); WHERE search_time < ' . (time() - (int) $this->config['search_store_results']);
$this->db->sql_query($sql); $this->db->sql_query($sql);
} }

View file

@ -19,8 +19,8 @@ use phpbb\event\dispatcher_interface;
use phpbb\language\language; use phpbb\language\language;
use phpbb\search\exception\index_created_exception; use phpbb\search\exception\index_created_exception;
use phpbb\search\exception\index_empty_exception; use phpbb\search\exception\index_empty_exception;
use phpbb\search\exception\search_exception;
use phpbb\user; use phpbb\user;
use RuntimeException;
/** /**
* Fulltext search for MySQL * Fulltext search for MySQL
@ -79,14 +79,15 @@ class fulltext_mysql extends base implements search_backend_interface
* @param dispatcher_interface $phpbb_dispatcher Event dispatcher object * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object
* @param language $language * @param language $language
* @param user $user User object * @param user $user User object
* @param string $search_results_table
* @param string $phpbb_root_path Relative path to phpBB root * @param string $phpbb_root_path Relative path to phpBB root
* @param string $phpEx PHP file extension * @param string $phpEx PHP file extension
*/ */
public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx) public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $search_results_table, string $phpbb_root_path, string $phpEx)
{ {
global $cache; global $cache;
parent::__construct($cache, $config, $db, $user); parent::__construct($cache, $config, $db, $user, $search_results_table);
$this->phpbb_dispatcher = $phpbb_dispatcher; $this->phpbb_dispatcher = $phpbb_dispatcher;
$this->language = $language; $this->language = $language;
@ -923,7 +924,7 @@ class fulltext_mysql extends base implements search_backend_interface
// Make sure we can actually use MySQL with fulltext indexes // Make sure we can actually use MySQL with fulltext indexes
if ($error = $this->init()) if ($error = $this->init())
{ {
throw new RuntimeException($error); throw new search_exception($error);
} }
if (empty($this->stats)) if (empty($this->stats))
@ -982,7 +983,7 @@ class fulltext_mysql extends base implements search_backend_interface
$this->db->sql_query($sql_query); $this->db->sql_query($sql_query);
} }
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); $this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table);
return null; return null;
} }
@ -1000,7 +1001,7 @@ class fulltext_mysql extends base implements search_backend_interface
// Make sure we can actually use MySQL with fulltext indexes // Make sure we can actually use MySQL with fulltext indexes
if ($error = $this->init()) if ($error = $this->init())
{ {
throw new RuntimeException($error); throw new search_exception($error);
} }
if (empty($this->stats)) if (empty($this->stats))
@ -1053,7 +1054,7 @@ class fulltext_mysql extends base implements search_backend_interface
$this->db->sql_query($sql_query); $this->db->sql_query($sql_query);
} }
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); $this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table);
return null; return null;
} }

View file

@ -99,6 +99,16 @@ class fulltext_native extends base implements search_backend_interface
*/ */
protected $language; protected $language;
/**
* @var string
*/
protected $search_wordlist_table;
/**
* @var string
*/
protected $search_wordmatch_table;
/** /**
* Initialises the fulltext_native search backend with min/max word length * Initialises the fulltext_native search backend with min/max word length
* *
@ -107,17 +117,23 @@ class fulltext_native extends base implements search_backend_interface
* @param dispatcher_interface $phpbb_dispatcher Event dispatcher object * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object
* @param language $language * @param language $language
* @param user $user User object * @param user $user User object
* @param string $search_results_table
* @param string $search_wordlist_table
* @param string $search_wordmatch_table
* @param string $phpbb_root_path phpBB root path * @param string $phpbb_root_path phpBB root path
* @param string $phpEx PHP file extension * @param string $phpEx PHP file extension
*/ */
public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx) public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $search_results_table, string $search_wordlist_table, string $search_wordmatch_table, string $phpbb_root_path, string $phpEx)
{ {
global $cache; global $cache;
parent::__construct($cache, $config, $db, $user); parent::__construct($cache, $config, $db, $user, $search_results_table);
$this->phpbb_dispatcher = $phpbb_dispatcher; $this->phpbb_dispatcher = $phpbb_dispatcher;
$this->language = $language; $this->language = $language;
$this->search_wordlist_table = $search_wordlist_table;
$this->search_wordmatch_table = $search_wordmatch_table;
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx; $this->php_ext = $phpEx;
@ -336,7 +352,7 @@ class fulltext_native extends base implements search_backend_interface
if (count($exact_words)) if (count($exact_words))
{ {
$sql = 'SELECT word_id, word_text, word_common $sql = 'SELECT word_id, word_text, word_common
FROM ' . SEARCH_WORDLIST_TABLE . ' FROM ' . $this->search_wordlist_table . '
WHERE ' . $this->db->sql_in_set('word_text', $exact_words) . ' WHERE ' . $this->db->sql_in_set('word_text', $exact_words) . '
ORDER BY word_count ASC'; ORDER BY word_count ASC';
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
@ -608,8 +624,8 @@ class fulltext_native extends base implements search_backend_interface
$sql_array = array( $sql_array = array(
'SELECT' => ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id', 'SELECT' => ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id',
'FROM' => array( 'FROM' => array(
SEARCH_WORDMATCH_TABLE => array(), $this->search_wordmatch_table => array(),
SEARCH_WORDLIST_TABLE => array(), $this->search_wordlist_table => array(),
), ),
'LEFT_JOIN' => array(array( 'LEFT_JOIN' => array(array(
'FROM' => array(POSTS_TABLE => 'p'), 'FROM' => array(POSTS_TABLE => 'p'),
@ -661,7 +677,7 @@ class fulltext_native extends base implements search_backend_interface
if (is_string($id)) if (is_string($id))
{ {
$sql_array['LEFT_JOIN'][] = array( $sql_array['LEFT_JOIN'][] = array(
'FROM' => array(SEARCH_WORDLIST_TABLE => 'w' . $w_num), 'FROM' => array($this->search_wordlist_table => 'w' . $w_num),
'ON' => "w$w_num.word_text LIKE $id" 'ON' => "w$w_num.word_text LIKE $id"
); );
$word_ids[] = "w$w_num.word_id"; $word_ids[] = "w$w_num.word_id";
@ -681,7 +697,7 @@ class fulltext_native extends base implements search_backend_interface
} }
else if (is_string($subquery)) else if (is_string($subquery))
{ {
$sql_array['FROM'][SEARCH_WORDLIST_TABLE][] = 'w' . $w_num; $sql_array['FROM'][$this->search_wordlist_table][] = 'w' . $w_num;
$sql_where[] = "w$w_num.word_text LIKE $subquery"; $sql_where[] = "w$w_num.word_text LIKE $subquery";
$sql_where[] = "m$m_num.word_id = w$w_num.word_id"; $sql_where[] = "m$m_num.word_id = w$w_num.word_id";
@ -694,7 +710,7 @@ class fulltext_native extends base implements search_backend_interface
$sql_where[] = "m$m_num.word_id = $subquery"; $sql_where[] = "m$m_num.word_id = $subquery";
} }
$sql_array['FROM'][SEARCH_WORDMATCH_TABLE][] = 'm' . $m_num; $sql_array['FROM'][$this->search_wordmatch_table][] = 'm' . $m_num;
if ($title_match) if ($title_match)
{ {
@ -713,7 +729,7 @@ class fulltext_native extends base implements search_backend_interface
if (is_string($subquery)) if (is_string($subquery))
{ {
$sql_array['LEFT_JOIN'][] = array( $sql_array['LEFT_JOIN'][] = array(
'FROM' => array(SEARCH_WORDLIST_TABLE => 'w' . $w_num), 'FROM' => array($this->search_wordlist_table => 'w' . $w_num),
'ON' => "w$w_num.word_text LIKE $subquery" 'ON' => "w$w_num.word_text LIKE $subquery"
); );
@ -727,7 +743,7 @@ class fulltext_native extends base implements search_backend_interface
if (count($this->must_not_contain_ids)) if (count($this->must_not_contain_ids))
{ {
$sql_array['LEFT_JOIN'][] = array( $sql_array['LEFT_JOIN'][] = array(
'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num), 'FROM' => array($this->search_wordmatch_table => 'm' . $m_num),
'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" '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"
); );
@ -743,7 +759,7 @@ class fulltext_native extends base implements search_backend_interface
if (is_string($id)) if (is_string($id))
{ {
$sql_array['LEFT_JOIN'][] = array( $sql_array['LEFT_JOIN'][] = array(
'FROM' => array(SEARCH_WORDLIST_TABLE => 'w' . $w_num), 'FROM' => array($this->search_wordlist_table => 'w' . $w_num),
'ON' => "w$w_num.word_text LIKE $id" 'ON' => "w$w_num.word_text LIKE $id"
); );
$id = "w$w_num.word_id"; $id = "w$w_num.word_id";
@ -753,7 +769,7 @@ class fulltext_native extends base implements search_backend_interface
} }
$sql_array['LEFT_JOIN'][] = array( $sql_array['LEFT_JOIN'][] = array(
'FROM' => array(SEARCH_WORDMATCH_TABLE => 'm' . $m_num), 'FROM' => array($this->search_wordmatch_table => 'm' . $m_num),
'ON' => "m$m_num.word_id = $id AND m$m_num.post_id = m0.post_id" . (($title_match) ? " AND m$m_num.$title_match" : '') 'ON' => "m$m_num.word_id = $id AND m$m_num.post_id = m0.post_id" . (($title_match) ? " AND m$m_num.$title_match" : '')
); );
$is_null_joins[] = "m$m_num.word_id IS NULL"; $is_null_joins[] = "m$m_num.word_id IS NULL";
@ -1311,7 +1327,7 @@ class fulltext_native extends base implements search_backend_interface
$words['del']['title'] = array(); $words['del']['title'] = array();
$sql = 'SELECT w.word_id, w.word_text, m.title_match $sql = 'SELECT w.word_id, w.word_text, m.title_match
FROM ' . SEARCH_WORDLIST_TABLE . ' w, ' . SEARCH_WORDMATCH_TABLE . " m FROM ' . $this->search_wordlist_table . ' w, ' . $this->search_wordmatch_table . " m
WHERE m.post_id = $post_id WHERE m.post_id = $post_id
AND w.word_id = m.word_id"; AND w.word_id = m.word_id";
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
@ -1380,7 +1396,7 @@ class fulltext_native extends base implements search_backend_interface
if (count($unique_add_words)) if (count($unique_add_words))
{ {
$sql = 'SELECT word_id, word_text $sql = 'SELECT word_id, word_text
FROM ' . SEARCH_WORDLIST_TABLE . ' FROM ' . $this->search_wordlist_table . '
WHERE ' . $this->db->sql_in_set('word_text', $unique_add_words); WHERE ' . $this->db->sql_in_set('word_text', $unique_add_words);
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
@ -1402,7 +1418,7 @@ class fulltext_native extends base implements search_backend_interface
$sql_ary[] = array('word_text' => (string) $word, 'word_count' => 0); $sql_ary[] = array('word_text' => (string) $word, 'word_count' => 0);
} }
$this->db->sql_return_on_error(true); $this->db->sql_return_on_error(true);
$this->db->sql_multi_insert(SEARCH_WORDLIST_TABLE, $sql_ary); $this->db->sql_multi_insert($this->search_wordlist_table, $sql_ary);
$this->db->sql_return_on_error(false); $this->db->sql_return_on_error(false);
} }
unset($new_words, $sql_ary); unset($new_words, $sql_ary);
@ -1425,13 +1441,13 @@ class fulltext_native extends base implements search_backend_interface
$sql_in[] = $cur_words[$word_in][$word]; $sql_in[] = $cur_words[$word_in][$word];
} }
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' $sql = 'DELETE FROM ' . $this->search_wordmatch_table . '
WHERE ' . $this->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 post_id = ' . intval($post_id) . "
AND title_match = $title_match"; AND title_match = $title_match";
$this->db->sql_query($sql); $this->db->sql_query($sql);
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' $sql = 'UPDATE ' . $this->search_wordlist_table . '
SET word_count = word_count - 1 SET word_count = word_count - 1
WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . ' WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . '
AND word_count > 0'; AND word_count > 0';
@ -1448,13 +1464,13 @@ class fulltext_native extends base implements search_backend_interface
if (count($word_ary)) if (count($word_ary))
{ {
$sql = 'INSERT INTO ' . SEARCH_WORDMATCH_TABLE . ' (post_id, word_id, title_match) $sql = 'INSERT INTO ' . $this->search_wordmatch_table . ' (post_id, word_id, title_match)
SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . ' SELECT ' . (int) $post_id . ', word_id, ' . (int) $title_match . '
FROM ' . SEARCH_WORDLIST_TABLE . ' FROM ' . $this->search_wordlist_table . '
WHERE ' . $this->db->sql_in_set('word_text', $word_ary); WHERE ' . $this->db->sql_in_set('word_text', $word_ary);
$this->db->sql_query($sql); $this->db->sql_query($sql);
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' $sql = 'UPDATE ' . $this->search_wordlist_table . '
SET word_count = word_count + 1 SET word_count = word_count + 1
WHERE ' . $this->db->sql_in_set('word_text', $word_ary); WHERE ' . $this->db->sql_in_set('word_text', $word_ary);
$this->db->sql_query($sql); $this->db->sql_query($sql);
@ -1480,7 +1496,7 @@ class fulltext_native extends base implements search_backend_interface
if (count($post_ids)) if (count($post_ids))
{ {
$sql = 'SELECT w.word_id, w.word_text, m.title_match $sql = 'SELECT w.word_id, w.word_text, m.title_match
FROM ' . SEARCH_WORDMATCH_TABLE . ' m, ' . SEARCH_WORDLIST_TABLE . ' w FROM ' . $this->search_wordmatch_table . ' m, ' . $this->search_wordlist_table . ' w
WHERE ' . $this->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'; AND w.word_id = m.word_id';
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
@ -1502,7 +1518,7 @@ class fulltext_native extends base implements search_backend_interface
if (count($title_word_ids)) if (count($title_word_ids))
{ {
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' $sql = 'UPDATE ' . $this->search_wordlist_table . '
SET word_count = word_count - 1 SET word_count = word_count - 1
WHERE ' . $this->db->sql_in_set('word_id', $title_word_ids) . ' WHERE ' . $this->db->sql_in_set('word_id', $title_word_ids) . '
AND word_count > 0'; AND word_count > 0';
@ -1511,7 +1527,7 @@ class fulltext_native extends base implements search_backend_interface
if (count($message_word_ids)) if (count($message_word_ids))
{ {
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' $sql = 'UPDATE ' . $this->search_wordlist_table . '
SET word_count = word_count - 1 SET word_count = word_count - 1
WHERE ' . $this->db->sql_in_set('word_id', $message_word_ids) . ' WHERE ' . $this->db->sql_in_set('word_id', $message_word_ids) . '
AND word_count > 0'; AND word_count > 0';
@ -1521,7 +1537,7 @@ class fulltext_native extends base implements search_backend_interface
unset($title_word_ids); unset($title_word_ids);
unset($message_word_ids); unset($message_word_ids);
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' $sql = 'DELETE FROM ' . $this->search_wordmatch_table . '
WHERE ' . $this->db->sql_in_set('post_id', $post_ids); WHERE ' . $this->db->sql_in_set('post_id', $post_ids);
$this->db->sql_query($sql); $this->db->sql_query($sql);
} }
@ -1550,7 +1566,7 @@ class fulltext_native extends base implements search_backend_interface
$common_threshold = ((double) $this->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 // First, get the IDs of common words
$sql = 'SELECT word_id, word_text $sql = 'SELECT word_id, word_text
FROM ' . SEARCH_WORDLIST_TABLE . ' FROM ' . $this->search_wordlist_table . '
WHERE word_count > ' . floor($this->config['num_posts'] * $common_threshold) . ' WHERE word_count > ' . floor($this->config['num_posts'] * $common_threshold) . '
OR word_common = 1'; OR word_common = 1';
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
@ -1566,7 +1582,7 @@ class fulltext_native extends base implements search_backend_interface
if (count($sql_in)) if (count($sql_in))
{ {
// Flag the words // Flag the words
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . ' $sql = 'UPDATE ' . $this->search_wordlist_table . '
SET word_common = 1 SET word_common = 1
WHERE ' . $this->db->sql_in_set('word_id', $sql_in); WHERE ' . $this->db->sql_in_set('word_id', $sql_in);
$this->db->sql_query($sql); $this->db->sql_query($sql);
@ -1576,7 +1592,7 @@ 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);
// Delete the matches // Delete the matches
$sql = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . ' $sql = 'DELETE FROM ' . $this->search_wordmatch_table . '
WHERE ' . $this->db->sql_in_set('word_id', $sql_in); WHERE ' . $this->db->sql_in_set('word_id', $sql_in);
$this->db->sql_query($sql); $this->db->sql_query($sql);
} }
@ -1609,15 +1625,15 @@ class fulltext_native extends base implements search_backend_interface
switch ($this->db->get_sql_layer()) switch ($this->db->get_sql_layer())
{ {
case 'sqlite3': case 'sqlite3':
$sql_queries[] = 'DELETE FROM ' . SEARCH_WORDLIST_TABLE; $sql_queries[] = 'DELETE FROM ' . $this->search_wordlist_table;
$sql_queries[] = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE; $sql_queries[] = 'DELETE FROM ' . $this->search_wordmatch_table;
$sql_queries[] = 'DELETE FROM ' . SEARCH_RESULTS_TABLE; $sql_queries[] = 'DELETE FROM ' . $this->search_results_table;
break; break;
default: default:
$sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE; $sql_queries[] = 'TRUNCATE TABLE ' . $this->search_wordlist_table;
$sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE; $sql_queries[] = 'TRUNCATE TABLE ' . $this->search_wordmatch_table;
$sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE; $sql_queries[] = 'TRUNCATE TABLE ' . $this->search_results_table;
break; break;
} }
@ -1678,8 +1694,8 @@ class fulltext_native extends base implements search_backend_interface
*/ */
protected function get_stats() protected function get_stats()
{ {
$this->stats['total_words'] = $this->db->get_estimated_row_count(SEARCH_WORDLIST_TABLE); $this->stats['total_words'] = $this->db->get_estimated_row_count($this->search_wordlist_table);
$this->stats['total_matches'] = $this->db->get_estimated_row_count(SEARCH_WORDMATCH_TABLE); $this->stats['total_matches'] = $this->db->get_estimated_row_count($this->search_wordmatch_table);
} }
/** /**

View file

@ -19,8 +19,8 @@ use phpbb\event\dispatcher_interface;
use phpbb\language\language; use phpbb\language\language;
use phpbb\search\exception\index_created_exception; use phpbb\search\exception\index_created_exception;
use phpbb\search\exception\index_empty_exception; use phpbb\search\exception\index_empty_exception;
use phpbb\search\exception\search_exception;
use phpbb\user; use phpbb\user;
use RuntimeException;
/** /**
* Fulltext search for PostgreSQL * Fulltext search for PostgreSQL
@ -91,14 +91,15 @@ class fulltext_postgres extends base implements search_backend_interface
* @param dispatcher_interface $phpbb_dispatcher Event dispatcher object * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object
* @param language $language * @param language $language
* @param user $user User object * @param user $user User object
* @param string $search_results_table
* @param string $phpbb_root_path Relative path to phpBB root * @param string $phpbb_root_path Relative path to phpBB root
* @param string $phpEx PHP file extension * @param string $phpEx PHP file extension
*/ */
public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx) public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $search_results_table, string $phpbb_root_path, string $phpEx)
{ {
global $cache; global $cache;
parent::__construct($cache, $config, $db, $user); parent::__construct($cache, $config, $db, $user, $search_results_table);
$this->phpbb_dispatcher = $phpbb_dispatcher; $this->phpbb_dispatcher = $phpbb_dispatcher;
$this->language = $language; $this->language = $language;
@ -878,7 +879,7 @@ class fulltext_postgres extends base implements search_backend_interface
// Make sure we can actually use PostgreSQL with fulltext indexes // Make sure we can actually use PostgreSQL with fulltext indexes
if ($error = $this->init()) if ($error = $this->init())
{ {
throw new RuntimeException($error); throw new search_exception($error);
} }
if (empty($this->stats)) if (empty($this->stats))
@ -924,7 +925,7 @@ class fulltext_postgres extends base implements search_backend_interface
$this->db->sql_query($sql_query); $this->db->sql_query($sql_query);
} }
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); $this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table);
return null; return null;
} }
@ -942,7 +943,7 @@ class fulltext_postgres extends base implements search_backend_interface
// Make sure we can actually use PostgreSQL with fulltext indexes // Make sure we can actually use PostgreSQL with fulltext indexes
if ($error = $this->init()) if ($error = $this->init())
{ {
throw new RuntimeException($error); throw new search_exception($error);
} }
if (empty($this->stats)) if (empty($this->stats))
@ -988,7 +989,7 @@ class fulltext_postgres extends base implements search_backend_interface
$this->db->sql_query($sql_query); $this->db->sql_query($sql_query);
} }
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE); $this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table);
return null; return null;
} }

View file

@ -632,7 +632,7 @@ class fulltext_sphinx implements search_backend_interface
*/ */
public function create_index(int &$post_counter = 0): ?array public function create_index(int &$post_counter = 0): ?array
{ {
if (!$this->index_created()) if ($this->index_created())
{ {
throw new index_empty_exception(); throw new index_empty_exception();
} }

View file

@ -13,7 +13,6 @@
namespace phpbb\search\exception; namespace phpbb\search\exception;
class action_in_progress_exception extends search_exception class action_in_progress_exception extends search_exception
{ {

View file

@ -13,7 +13,6 @@
namespace phpbb\search\exception; namespace phpbb\search\exception;
class index_created_exception extends search_exception class index_created_exception extends search_exception
{ {

View file

@ -13,7 +13,6 @@
namespace phpbb\search\exception; namespace phpbb\search\exception;
class index_empty_exception extends search_exception class index_empty_exception extends search_exception
{ {

View file

@ -13,7 +13,6 @@
namespace phpbb\search\exception; namespace phpbb\search\exception;
class no_action_in_progress_exception extends search_exception class no_action_in_progress_exception extends search_exception
{ {

View file

@ -17,5 +17,5 @@ use phpbb\exception\runtime_exception;
class search_exception extends runtime_exception class search_exception extends runtime_exception
{ {
// TODO: Launch this exception from search instead of RuntimeException
} }

View file

@ -16,6 +16,7 @@ namespace phpbb\search;
use phpbb\config\config; use phpbb\config\config;
use phpbb\search\exception\action_in_progress_exception; use phpbb\search\exception\action_in_progress_exception;
use phpbb\search\exception\no_action_in_progress_exception; use phpbb\search\exception\no_action_in_progress_exception;
use phpbb\search\exception\search_exception;
class state_helper class state_helper
{ {
@ -32,8 +33,8 @@ class state_helper
/** /**
* Constructor. * Constructor.
* *
* @param \phpbb\config\config $config * @param config $config
* @param \phpbb\search\search_backend_factory $search_backend_factory * @param search_backend_factory $search_backend_factory
*/ */
public function __construct(config $config, search_backend_factory $search_backend_factory) public function __construct(config $config, search_backend_factory $search_backend_factory)
{ {
@ -108,7 +109,7 @@ class state_helper
// Make sure the action is correct (just in case) // Make sure the action is correct (just in case)
if (!in_array($action, ['create', 'delete'])) if (!in_array($action, ['create', 'delete']))
{ {
throw new \RuntimeException('Invalid action'); throw new search_exception('Invalid action');
} }
$state = [ $state = [