mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/12683] Pass tables via parameter and small fix
PHPBB3-12683
This commit is contained in:
parent
565c806eda
commit
f4977853be
16 changed files with 132 additions and 103 deletions
|
@ -4,7 +4,7 @@ services:
|
|||
class: phpbb\search\state_helper
|
||||
arguments:
|
||||
- '@config'
|
||||
- '@search.backend_collection'
|
||||
- '@search.backend_factory'
|
||||
|
||||
# Search backends
|
||||
search.fulltext.mysql:
|
||||
|
@ -15,6 +15,7 @@ services:
|
|||
- '@dispatcher'
|
||||
- '@language'
|
||||
- '@user'
|
||||
- '%tables.search_results%'
|
||||
- '%core.root_path%'
|
||||
- '%core.php_ext%'
|
||||
tags:
|
||||
|
@ -28,6 +29,9 @@ services:
|
|||
- '@dispatcher'
|
||||
- '@language'
|
||||
- '@user'
|
||||
- '%tables.search_results%'
|
||||
- '%tables.search_wordlist%'
|
||||
- '%tables.search_wordmatch%'
|
||||
- '%core.root_path%'
|
||||
- '%core.php_ext%'
|
||||
tags:
|
||||
|
@ -41,6 +45,7 @@ services:
|
|||
- '@dispatcher'
|
||||
- '@language'
|
||||
- '@user'
|
||||
- '%tables.search_results%'
|
||||
- '%core.root_path%'
|
||||
- '%core.php_ext%'
|
||||
tags:
|
||||
|
|
|
@ -322,6 +322,8 @@ class acp_search
|
|||
$this->page_title = 'ACP_SEARCH_INDEX';
|
||||
|
||||
foreach ($this->search_backend_collection as $search)
|
||||
{
|
||||
if ($search->is_available())
|
||||
{
|
||||
$this->template->assign_block_vars('backends', [
|
||||
'NAME' => $search->get_name(),
|
||||
|
@ -332,13 +334,14 @@ class acp_search
|
|||
'S_INDEXED' => $search->index_created(),
|
||||
'S_STATS' => $search->index_stats(),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->template->assign_vars([
|
||||
'U_ACTION' => $this->u_action . '&hash=' . generate_link_hash('acp_search'),
|
||||
'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form to continue or cancel indexing process
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
namespace phpbb\post;
|
||||
|
||||
|
||||
use phpbb\db\driver\driver_interface;
|
||||
|
||||
class post_helper
|
||||
|
|
|
@ -53,6 +53,11 @@ abstract class base implements search_backend_interface
|
|||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $search_results_table;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -60,13 +65,15 @@ abstract class base implements search_backend_interface
|
|||
* @param config $config
|
||||
* @param driver_interface $db
|
||||
* @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->config = $config;
|
||||
$this->db = $db;
|
||||
$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))
|
||||
{
|
||||
$sql = 'SELECT search_time
|
||||
FROM ' . SEARCH_RESULTS_TABLE . '
|
||||
FROM ' . $this->search_results_table . '
|
||||
WHERE search_key = \'' . $this->db->sql_escape($search_key) . '\'';
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
|
@ -195,7 +202,7 @@ abstract class base implements search_backend_interface
|
|||
'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_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']);
|
||||
|
||||
$sql = 'UPDATE ' . SEARCH_RESULTS_TABLE . '
|
||||
$sql = 'UPDATE ' . $this->search_results_table . '
|
||||
SET search_time = ' . time() . '
|
||||
WHERE search_key = \'' . $this->db->sql_escape($search_key) . '\'';
|
||||
$this->db->sql_query($sql);
|
||||
|
@ -282,7 +289,7 @@ abstract class base implements search_backend_interface
|
|||
}
|
||||
|
||||
$sql = 'SELECT search_key
|
||||
FROM ' . SEARCH_RESULTS_TABLE . "
|
||||
FROM ' . $this->search_results_table . "
|
||||
WHERE search_keywords LIKE '%*%' $sql_where";
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
|
@ -303,7 +310,7 @@ abstract class base implements search_backend_interface
|
|||
}
|
||||
|
||||
$sql = 'SELECT search_key
|
||||
FROM ' . SEARCH_RESULTS_TABLE . "
|
||||
FROM ' . $this->search_results_table . "
|
||||
WHERE $sql_where";
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
|
@ -315,7 +322,7 @@ abstract class base implements search_backend_interface
|
|||
}
|
||||
|
||||
$sql = 'DELETE
|
||||
FROM ' . SEARCH_RESULTS_TABLE . '
|
||||
FROM ' . $this->search_results_table . '
|
||||
WHERE search_time < ' . (time() - (int) $this->config['search_store_results']);
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ use phpbb\event\dispatcher_interface;
|
|||
use phpbb\language\language;
|
||||
use phpbb\search\exception\index_created_exception;
|
||||
use phpbb\search\exception\index_empty_exception;
|
||||
use phpbb\search\exception\search_exception;
|
||||
use phpbb\user;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* 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 language $language
|
||||
* @param user $user User object
|
||||
* @param string $search_results_table
|
||||
* @param string $phpbb_root_path Relative path to phpBB root
|
||||
* @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;
|
||||
|
||||
parent::__construct($cache, $config, $db, $user);
|
||||
parent::__construct($cache, $config, $db, $user, $search_results_table);
|
||||
$this->phpbb_dispatcher = $phpbb_dispatcher;
|
||||
$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
|
||||
if ($error = $this->init())
|
||||
{
|
||||
throw new RuntimeException($error);
|
||||
throw new search_exception($error);
|
||||
}
|
||||
|
||||
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('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
|
||||
$this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table);
|
||||
|
||||
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
|
||||
if ($error = $this->init())
|
||||
{
|
||||
throw new RuntimeException($error);
|
||||
throw new search_exception($error);
|
||||
}
|
||||
|
||||
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('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
|
||||
$this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -99,6 +99,16 @@ class fulltext_native extends base implements search_backend_interface
|
|||
*/
|
||||
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
|
||||
*
|
||||
|
@ -107,17 +117,23 @@ class fulltext_native extends base implements search_backend_interface
|
|||
* @param dispatcher_interface $phpbb_dispatcher Event dispatcher object
|
||||
* @param language $language
|
||||
* @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 $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;
|
||||
|
||||
parent::__construct($cache, $config, $db, $user);
|
||||
parent::__construct($cache, $config, $db, $user, $search_results_table);
|
||||
$this->phpbb_dispatcher = $phpbb_dispatcher;
|
||||
$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->php_ext = $phpEx;
|
||||
|
||||
|
@ -336,7 +352,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
if (count($exact_words))
|
||||
{
|
||||
$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) . '
|
||||
ORDER BY word_count ASC';
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
@ -608,8 +624,8 @@ class fulltext_native extends base implements search_backend_interface
|
|||
$sql_array = array(
|
||||
'SELECT' => ($type == 'posts') ? 'DISTINCT p.post_id' : 'DISTINCT p.topic_id',
|
||||
'FROM' => array(
|
||||
SEARCH_WORDMATCH_TABLE => array(),
|
||||
SEARCH_WORDLIST_TABLE => array(),
|
||||
$this->search_wordmatch_table => array(),
|
||||
$this->search_wordlist_table => array(),
|
||||
),
|
||||
'LEFT_JOIN' => array(array(
|
||||
'FROM' => array(POSTS_TABLE => 'p'),
|
||||
|
@ -661,7 +677,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
if (is_string($id))
|
||||
{
|
||||
$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"
|
||||
);
|
||||
$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))
|
||||
{
|
||||
$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[] = "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_array['FROM'][SEARCH_WORDMATCH_TABLE][] = 'm' . $m_num;
|
||||
$sql_array['FROM'][$this->search_wordmatch_table][] = 'm' . $m_num;
|
||||
|
||||
if ($title_match)
|
||||
{
|
||||
|
@ -713,7 +729,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
if (is_string($subquery))
|
||||
{
|
||||
$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"
|
||||
);
|
||||
|
||||
|
@ -727,7 +743,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
if (count($this->must_not_contain_ids))
|
||||
{
|
||||
$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"
|
||||
);
|
||||
|
||||
|
@ -743,7 +759,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
if (is_string($id))
|
||||
{
|
||||
$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"
|
||||
);
|
||||
$id = "w$w_num.word_id";
|
||||
|
@ -753,7 +769,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
}
|
||||
|
||||
$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" : '')
|
||||
);
|
||||
$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();
|
||||
|
||||
$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
|
||||
AND w.word_id = m.word_id";
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
@ -1380,7 +1396,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
if (count($unique_add_words))
|
||||
{
|
||||
$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);
|
||||
$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);
|
||||
}
|
||||
$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);
|
||||
}
|
||||
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 = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE . '
|
||||
$sql = 'DELETE FROM ' . $this->search_wordmatch_table . '
|
||||
WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . '
|
||||
AND post_id = ' . intval($post_id) . "
|
||||
AND title_match = $title_match";
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
|
||||
$sql = 'UPDATE ' . $this->search_wordlist_table . '
|
||||
SET word_count = word_count - 1
|
||||
WHERE ' . $this->db->sql_in_set('word_id', $sql_in) . '
|
||||
AND word_count > 0';
|
||||
|
@ -1448,13 +1464,13 @@ class fulltext_native extends base implements search_backend_interface
|
|||
|
||||
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 . '
|
||||
FROM ' . SEARCH_WORDLIST_TABLE . '
|
||||
FROM ' . $this->search_wordlist_table . '
|
||||
WHERE ' . $this->db->sql_in_set('word_text', $word_ary);
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
|
||||
$sql = 'UPDATE ' . $this->search_wordlist_table . '
|
||||
SET word_count = word_count + 1
|
||||
WHERE ' . $this->db->sql_in_set('word_text', $word_ary);
|
||||
$this->db->sql_query($sql);
|
||||
|
@ -1480,7 +1496,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
if (count($post_ids))
|
||||
{
|
||||
$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) . '
|
||||
AND w.word_id = m.word_id';
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
@ -1502,7 +1518,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
|
||||
if (count($title_word_ids))
|
||||
{
|
||||
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
|
||||
$sql = 'UPDATE ' . $this->search_wordlist_table . '
|
||||
SET word_count = word_count - 1
|
||||
WHERE ' . $this->db->sql_in_set('word_id', $title_word_ids) . '
|
||||
AND word_count > 0';
|
||||
|
@ -1511,7 +1527,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
|
||||
if (count($message_word_ids))
|
||||
{
|
||||
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
|
||||
$sql = 'UPDATE ' . $this->search_wordlist_table . '
|
||||
SET word_count = word_count - 1
|
||||
WHERE ' . $this->db->sql_in_set('word_id', $message_word_ids) . '
|
||||
AND word_count > 0';
|
||||
|
@ -1521,7 +1537,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
unset($title_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);
|
||||
$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;
|
||||
// First, get the IDs of common words
|
||||
$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) . '
|
||||
OR word_common = 1';
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
@ -1566,7 +1582,7 @@ class fulltext_native extends base implements search_backend_interface
|
|||
if (count($sql_in))
|
||||
{
|
||||
// Flag the words
|
||||
$sql = 'UPDATE ' . SEARCH_WORDLIST_TABLE . '
|
||||
$sql = 'UPDATE ' . $this->search_wordlist_table . '
|
||||
SET word_common = 1
|
||||
WHERE ' . $this->db->sql_in_set('word_id', $sql_in);
|
||||
$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);
|
||||
|
||||
// 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);
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
@ -1609,15 +1625,15 @@ class fulltext_native extends base implements search_backend_interface
|
|||
switch ($this->db->get_sql_layer())
|
||||
{
|
||||
case 'sqlite3':
|
||||
$sql_queries[] = 'DELETE FROM ' . SEARCH_WORDLIST_TABLE;
|
||||
$sql_queries[] = 'DELETE FROM ' . SEARCH_WORDMATCH_TABLE;
|
||||
$sql_queries[] = 'DELETE FROM ' . SEARCH_RESULTS_TABLE;
|
||||
$sql_queries[] = 'DELETE FROM ' . $this->search_wordlist_table;
|
||||
$sql_queries[] = 'DELETE FROM ' . $this->search_wordmatch_table;
|
||||
$sql_queries[] = 'DELETE FROM ' . $this->search_results_table;
|
||||
break;
|
||||
|
||||
default:
|
||||
$sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_WORDLIST_TABLE;
|
||||
$sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_WORDMATCH_TABLE;
|
||||
$sql_queries[] = 'TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE;
|
||||
$sql_queries[] = 'TRUNCATE TABLE ' . $this->search_wordlist_table;
|
||||
$sql_queries[] = 'TRUNCATE TABLE ' . $this->search_wordmatch_table;
|
||||
$sql_queries[] = 'TRUNCATE TABLE ' . $this->search_results_table;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1678,8 +1694,8 @@ class fulltext_native extends base implements search_backend_interface
|
|||
*/
|
||||
protected function get_stats()
|
||||
{
|
||||
$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);
|
||||
$this->stats['total_words'] = $this->db->get_estimated_row_count($this->search_wordlist_table);
|
||||
$this->stats['total_matches'] = $this->db->get_estimated_row_count($this->search_wordmatch_table);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,8 +19,8 @@ use phpbb\event\dispatcher_interface;
|
|||
use phpbb\language\language;
|
||||
use phpbb\search\exception\index_created_exception;
|
||||
use phpbb\search\exception\index_empty_exception;
|
||||
use phpbb\search\exception\search_exception;
|
||||
use phpbb\user;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* 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 language $language
|
||||
* @param user $user User object
|
||||
* @param string $search_results_table
|
||||
* @param string $phpbb_root_path Relative path to phpBB root
|
||||
* @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;
|
||||
|
||||
parent::__construct($cache, $config, $db, $user);
|
||||
parent::__construct($cache, $config, $db, $user, $search_results_table);
|
||||
$this->phpbb_dispatcher = $phpbb_dispatcher;
|
||||
$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
|
||||
if ($error = $this->init())
|
||||
{
|
||||
throw new RuntimeException($error);
|
||||
throw new search_exception($error);
|
||||
}
|
||||
|
||||
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('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
|
||||
$this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table);
|
||||
|
||||
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
|
||||
if ($error = $this->init())
|
||||
{
|
||||
throw new RuntimeException($error);
|
||||
throw new search_exception($error);
|
||||
}
|
||||
|
||||
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('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
|
||||
$this->db->sql_query('TRUNCATE TABLE ' . $this->search_results_table);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -632,7 +632,7 @@ class fulltext_sphinx implements search_backend_interface
|
|||
*/
|
||||
public function create_index(int &$post_counter = 0): ?array
|
||||
{
|
||||
if (!$this->index_created())
|
||||
if ($this->index_created())
|
||||
{
|
||||
throw new index_empty_exception();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
namespace phpbb\search\exception;
|
||||
|
||||
|
||||
class action_in_progress_exception extends search_exception
|
||||
{
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
namespace phpbb\search\exception;
|
||||
|
||||
|
||||
class index_created_exception extends search_exception
|
||||
{
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
namespace phpbb\search\exception;
|
||||
|
||||
|
||||
class index_empty_exception extends search_exception
|
||||
{
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
namespace phpbb\search\exception;
|
||||
|
||||
|
||||
class no_action_in_progress_exception extends search_exception
|
||||
{
|
||||
|
||||
|
|
|
@ -17,5 +17,5 @@ use phpbb\exception\runtime_exception;
|
|||
|
||||
class search_exception extends runtime_exception
|
||||
{
|
||||
// TODO: Launch this exception from search instead of RuntimeException
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace phpbb\search;
|
|||
use phpbb\config\config;
|
||||
use phpbb\search\exception\action_in_progress_exception;
|
||||
use phpbb\search\exception\no_action_in_progress_exception;
|
||||
use phpbb\search\exception\search_exception;
|
||||
|
||||
class state_helper
|
||||
{
|
||||
|
@ -32,8 +33,8 @@ class state_helper
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \phpbb\config\config $config
|
||||
* @param \phpbb\search\search_backend_factory $search_backend_factory
|
||||
* @param config $config
|
||||
* @param 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)
|
||||
if (!in_array($action, ['create', 'delete']))
|
||||
{
|
||||
throw new \RuntimeException('Invalid action');
|
||||
throw new search_exception('Invalid action');
|
||||
}
|
||||
|
||||
$state = [
|
||||
|
|
Loading…
Add table
Reference in a new issue