';
diff --git a/phpBB/phpbb/search/fulltext_native.php b/phpBB/phpbb/search/backend/fulltext_native.php
similarity index 83%
rename from phpBB/phpbb/search/fulltext_native.php
rename to phpBB/phpbb/search/backend/fulltext_native.php
index 2246dc0aef..24a7d7d9bc 100644
--- a/phpBB/phpbb/search/fulltext_native.php
+++ b/phpBB/phpbb/search/backend/fulltext_native.php
@@ -11,19 +11,25 @@
*
*/
-namespace phpbb\search;
+namespace phpbb\search\backend;
+
+use phpbb\config\config;
+use phpbb\db\driver\driver_interface;
+use phpbb\event\dispatcher_interface;
+use phpbb\language\language;
+use phpbb\user;
/**
* phpBB's own db driven fulltext search, version 2
*/
-class fulltext_native extends \phpbb\search\base
+class fulltext_native extends base implements search_backend_interface
{
- const UTF8_HANGUL_FIRST = "\xEA\xB0\x80";
- const UTF8_HANGUL_LAST = "\xED\x9E\xA3";
- const UTF8_CJK_FIRST = "\xE4\xB8\x80";
- const UTF8_CJK_LAST = "\xE9\xBE\xBB";
- const UTF8_CJK_B_FIRST = "\xF0\xA0\x80\x80";
- const UTF8_CJK_B_LAST = "\xF0\xAA\x9B\x96";
+ protected const UTF8_HANGUL_FIRST = "\xEA\xB0\x80";
+ protected const UTF8_HANGUL_LAST = "\xED\x9E\xA3";
+ protected const UTF8_CJK_FIRST = "\xE4\xB8\x80";
+ protected const UTF8_CJK_LAST = "\xE9\xBE\xBB";
+ protected const UTF8_CJK_B_FIRST = "\xF0\xA0\x80\x80";
+ protected const UTF8_CJK_B_LAST = "\xF0\xAA\x9B\x96";
/**
* Associative array holding index stats
@@ -81,50 +87,38 @@ class fulltext_native extends \phpbb\search\base
*/
protected $php_ext;
- /**
- * Config object
- * @var \phpbb\config\config
- */
- protected $config;
-
- /**
- * Database connection
- * @var \phpbb\db\driver\driver_interface
- */
- protected $db;
-
/**
* phpBB event dispatcher object
- * @var \phpbb\event\dispatcher_interface
+ * @var dispatcher_interface
*/
protected $phpbb_dispatcher;
/**
- * User object
- * @var \phpbb\user
+ * @var language
*/
- protected $user;
+ protected $language;
/**
- * Initialises the fulltext_native search backend with min/max word length
- *
- * @param boolean|string &$error is passed by reference and should either be set to false on success or an error message on failure
- * @param string $phpbb_root_path phpBB root path
- * @param string $phpEx PHP file extension
- * @param \phpbb\auth\auth $auth Auth object
- * @param \phpbb\config\config $config Config object
- * @param \phpbb\db\driver\driver_interface $db Database object
- * @param \phpbb\user $user User object
- * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object
- */
- public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher)
+ * Initialises the fulltext_native search backend with min/max word length
+ *
+ * @param config $config Config object
+ * @param driver_interface $db Database object
+ * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object
+ * @param language $language
+ * @param user $user User object
+ * @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)
{
+ global $cache;
+
+ parent::__construct($cache, $config, $db, $user);
+ $this->phpbb_dispatcher = $phpbb_dispatcher;
+ $this->language = $language;
+
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
- $this->config = $config;
- $this->db = $db;
- $this->phpbb_dispatcher = $phpbb_dispatcher;
- $this->user = $user;
$this->word_length = array('min' => (int) $this->config['fulltext_native_min_chars'], 'max' => (int) $this->config['fulltext_native_max_chars']);
@@ -135,44 +129,50 @@ class fulltext_native extends \phpbb\search\base
{
include($this->phpbb_root_path . 'includes/utf/utf_tools.' . $this->php_ext);
}
-
- $error = false;
}
/**
- * Returns the name of this search backend to be displayed to administrators
- *
- * @return string Name
+ * {@inheritdoc}
*/
- public function get_name()
+ public function get_name(): string
{
return 'phpBB Native Fulltext';
}
/**
- * Returns the search_query
- *
- * @return string search query
+ * {@inheritdoc}
*/
- public function get_search_query()
+ public function is_available(): bool
+ {
+ return true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function init()
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_search_query(): string
{
return $this->search_query;
}
/**
- * Returns the common_words array
- *
- * @return array common words that are ignored by search backend
+ * {@inheritdoc}
*/
- public function get_common_words()
+ public function get_common_words(): array
{
return $this->common_words;
}
/**
- * Returns the word_length array
- *
- * @return array min and max word length for searching
+ * {@inheritdoc}
*/
public function get_word_length()
{
@@ -180,21 +180,9 @@ class fulltext_native extends \phpbb\search\base
}
/**
- * This function fills $this->search_query with the cleaned user search query
- *
- * If $terms is 'any' then the words will be extracted from the search query
- * and combined with | inside brackets. They will afterwards be treated like
- * an standard search query.
- *
- * Then it analyses the query and fills the internal arrays $must_not_contain_ids,
- * $must_contain_ids and $must_exclude_one_ids which are later used by keyword_search()
- *
- * @param string $keywords contains the search query string as entered by the user
- * @param string $terms is either 'all' (use search query as entered, default words to 'must be contained in post')
- * or 'any' (find all posts containing at least one of the given words)
- * @return boolean false if no valid keywords were found and otherwise true
- */
- public function split_keywords($keywords, $terms)
+ * {@inheritdoc}
+ */
+ public function split_keywords(string &$keywords, string $terms): bool
{
$tokens = '+-|()* ';
@@ -294,7 +282,7 @@ class fulltext_native extends \phpbb\search\base
// We limit the number of allowed keywords to minimize load on the database
if ($this->config['max_num_search_keywords'] && $num_keywords > $this->config['max_num_search_keywords'])
{
- trigger_error($this->user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', (int) $this->config['max_num_search_keywords'], $num_keywords));
+ trigger_error($this->language->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', (int) $this->config['max_num_search_keywords'], $num_keywords));
}
// $keywords input format: each word separated by a space, words in a bracket are not separated
@@ -468,7 +456,7 @@ class fulltext_native extends \phpbb\search\base
// throw an error if we shall not ignore unexistant words
else if (!$ignore_no_id && count($non_common_words))
{
- trigger_error(sprintf($this->user->lang['WORDS_IN_NO_POST'], implode($this->user->lang['COMMA_SEPARATOR'], $non_common_words)));
+ trigger_error(sprintf($this->language->lang('WORDS_IN_NO_POST'), implode($this->language->lang('COMMA_SEPARATOR'), $non_common_words)));
}
unset($non_common_words);
}
@@ -514,26 +502,9 @@ class fulltext_native extends \phpbb\search\base
}
/**
- * Performs a search on keywords depending on display specific params. You have to run split_keywords() first
- *
- * @param string $type contains either posts or topics depending on what should be searched for
- * @param string $fields contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched)
- * @param string $terms is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
- * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query
- * @param string $sort_key is the key of $sort_by_sql for the selected sorting
- * @param string $sort_dir is either a or d representing ASC and DESC
- * @param string $sort_days specifies the maximum amount of days a post may be old
- * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
- * @param string $post_visibility specifies which types of posts the user can view in which forums
- * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
- * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty
- * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
- * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
- * @param int $start indicates the first index of the page
- * @param int $per_page number of ids each page is supposed to contain
- * @return boolean|int total number of results
- */
- public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page)
+ * {@inheritdoc}
+ */
+ public function keyword_search(string $type, string $fields, string $terms, array $sort_by_sql, string $sort_key, string $sort_dir, string $sort_days, array $ex_fid_ary, string $post_visibility, int $topic_id, array $author_ary, string $author_name, array &$id_ary, int &$start, int $per_page)
{
// No keywords? No posts.
if (empty($this->search_query))
@@ -612,7 +583,7 @@ class fulltext_native extends \phpbb\search\base
// try reading the results from cache
$total_results = 0;
- if ($this->obtain_ids($search_key, $total_results, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE)
+ if ($this->obtain_ids($search_key, $total_results, $id_ary, $start, $per_page, $sort_dir) == self::SEARCH_RESULT_IN_CACHE)
{
return $total_results;
}
@@ -1016,25 +987,9 @@ class fulltext_native extends \phpbb\search\base
}
/**
- * Performs a search on an author's posts without caring about message contents. Depends on display specific params
- *
- * @param string $type contains either posts or topics depending on what should be searched for
- * @param boolean $firstpost_only if true, only topic starting posts will be considered
- * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query
- * @param string $sort_key is the key of $sort_by_sql for the selected sorting
- * @param string $sort_dir is either a or d representing ASC and DESC
- * @param string $sort_days specifies the maximum amount of days a post may be old
- * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
- * @param string $post_visibility specifies which types of posts the user can view in which forums
- * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
- * @param array $author_ary an array of author ids
- * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
- * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
- * @param int $start indicates the first index of the page
- * @param int $per_page number of ids each page is supposed to contain
- * @return boolean|int total number of results
- */
- public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page)
+ * {@inheritdoc}
+ */
+ public function author_search(string $type, bool $firstpost_only, array $sort_by_sql, string $sort_key, string $sort_dir, string $sort_days, array $ex_fid_ary, string $post_visibility, int $topic_id, array $author_ary, string $author_name, array &$id_ary, int &$start, int $per_page)
{
// No author? No posts
if (!count($author_ary))
@@ -1092,7 +1047,7 @@ class fulltext_native extends \phpbb\search\base
// try reading the results from cache
$total_results = 0;
- if ($this->obtain_ids($search_key, $total_results, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE)
+ if ($this->obtain_ids($search_key, $total_results, $id_ary, $start, $per_page, $sort_dir) == self::SEARCH_RESULT_IN_CACHE)
{
return $total_results;
}
@@ -1326,91 +1281,17 @@ class fulltext_native extends \phpbb\search\base
}
/**
- * Split a text into words of a given length
- *
- * The text is converted to UTF-8, cleaned up, and split. Then, words that
- * conform to the defined length range are returned in an array.
- *
- * NOTE: duplicates are NOT removed from the return array
- *
- * @param string $text Text to split, encoded in UTF-8
- * @return array Array of UTF-8 words
- */
- public function split_message($text)
+ * {@inheritdoc}
+ */
+ public function supports_phrase_search(): bool
{
- $match = $words = array();
-
- /**
- * Taken from the original code
- */
- // Do not index code
- $match[] = '#\[code(?:=.*?)?(\:?[0-9a-z]{5,})\].*?\[\/code(\:?[0-9a-z]{5,})\]#is';
- // BBcode
- $match[] = '#\[\/?[a-z0-9\*\+\-]+(?:=.*?)?(?::[a-z])?(\:?[0-9a-z]{5,})\]#';
-
- $min = $this->word_length['min'];
-
- $isset_min = $min - 1;
-
- /**
- * Clean up the string, remove HTML tags, remove BBCodes
- */
- $word = strtok($this->cleanup(preg_replace($match, ' ', strip_tags($text)), -1), ' ');
-
- while (strlen($word))
- {
- if (strlen($word) > 255 || strlen($word) <= $isset_min)
- {
- /**
- * Words longer than 255 bytes are ignored. This will have to be
- * changed whenever we change the length of search_wordlist.word_text
- *
- * Words shorter than $isset_min bytes are ignored, too
- */
- $word = strtok(' ');
- continue;
- }
-
- $len = utf8_strlen($word);
-
- /**
- * Test whether the word is too short to be indexed.
- *
- * Note that this limit does NOT apply to CJK and Hangul
- */
- if ($len < $min)
- {
- /**
- * Note: this could be optimized. If the codepoint is lower than Hangul's range
- * we know that it will also be lower than CJK ranges
- */
- if ((strncmp($word, self::UTF8_HANGUL_FIRST, 3) < 0 || strncmp($word, self::UTF8_HANGUL_LAST, 3) > 0)
- && (strncmp($word, self::UTF8_CJK_FIRST, 3) < 0 || strncmp($word, self::UTF8_CJK_LAST, 3) > 0)
- && (strncmp($word, self::UTF8_CJK_B_FIRST, 4) < 0 || strncmp($word, self::UTF8_CJK_B_LAST, 4) > 0))
- {
- $word = strtok(' ');
- continue;
- }
- }
-
- $words[] = $word;
- $word = strtok(' ');
- }
-
- return $words;
+ return false;
}
/**
- * Updates wordlist and wordmatch tables when a message is posted or changed
- *
- * @param string $mode Contains the post mode: edit, post, reply, quote
- * @param int $post_id The id of the post which is modified/created
- * @param string &$message New or updated post content
- * @param string &$subject New or updated post subject
- * @param int $poster_id Post author's user id
- * @param int $forum_id The id of the forum in which the post is located
+ * {@inheritdoc}
*/
- public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
+ public function index(string $mode, int $post_id, string &$message, string &$subject, int $poster_id, int $forum_id)
{
if (!$this->config['fulltext_native_load_upd'])
{
@@ -1597,9 +1478,9 @@ class fulltext_native extends \phpbb\search\base
}
/**
- * Removes entries from the wordmatch table for the specified post_ids
- */
- public function index_remove($post_ids, $author_ids, $forum_ids)
+ * {@inheritdoc}
+ */
+ public function index_remove(array $post_ids, array $author_ids, array $forum_ids): void
{
if (count($post_ids))
{
@@ -1654,10 +1535,9 @@ class fulltext_native extends \phpbb\search\base
}
/**
- * Tidy up indexes: Tag 'common words' and remove
- * words no longer referenced in the match table
- */
- public function tidy()
+ * {@inheritdoc}
+ */
+ public function tidy(): void
{
// 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
@@ -1717,10 +1597,12 @@ class fulltext_native extends \phpbb\search\base
$this->config->set('search_last_gc', time(), false);
}
+ // create_index is inherited from base.php
+
/**
- * Deletes all words from the index
- */
- public function delete_index($acp_module, $u_action)
+ * {@inheritdoc}
+ */
+ public function delete_index(int &$post_counter = null): ?array
{
$sql_queries = [];
@@ -1759,24 +1641,26 @@ class fulltext_native extends \phpbb\search\base
{
$this->db->sql_query($sql_query);
}
+
+ return null;
}
/**
- * Returns true if both FULLTEXT indexes exist
+ * {@inheritdoc}
*/
- public function index_created()
+ public function index_created(): bool
{
if (!count($this->stats))
{
$this->get_stats();
}
- return ($this->stats['total_words'] && $this->stats['total_matches']) ? true : false;
+ return $this->stats['total_words'] && $this->stats['total_matches'];
}
/**
- * Returns an associative array containing information about the indexes
- */
+ * {@inheritdoc}
+ */
public function index_stats()
{
if (!count($this->stats))
@@ -1785,16 +1669,94 @@ class fulltext_native extends \phpbb\search\base
}
return array(
- $this->user->lang['TOTAL_WORDS'] => $this->stats['total_words'],
- $this->user->lang['TOTAL_MATCHES'] => $this->stats['total_matches']);
+ $this->language->lang('TOTAL_WORDS') => $this->stats['total_words'],
+ $this->language->lang('TOTAL_MATCHES') => $this->stats['total_matches']);
}
+ /**
+ * Computes the stats and store them in the $this->stats associative array
+ */
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);
}
+ /**
+ * Split a text into words of a given length
+ *
+ * The text is converted to UTF-8, cleaned up, and split. Then, words that
+ * conform to the defined length range are returned in an array.
+ *
+ * NOTE: duplicates are NOT removed from the return array
+ *
+ * @param string $text Text to split, encoded in UTF-8
+ * @return array Array of UTF-8 words
+ */
+ protected function split_message($text)
+ {
+ $match = $words = array();
+
+ /**
+ * Taken from the original code
+ */
+ // Do not index code
+ $match[] = '#\[code(?:=.*?)?(\:?[0-9a-z]{5,})\].*?\[\/code(\:?[0-9a-z]{5,})\]#is';
+ // BBcode
+ $match[] = '#\[\/?[a-z0-9\*\+\-]+(?:=.*?)?(?::[a-z])?(\:?[0-9a-z]{5,})\]#';
+
+ $min = $this->word_length['min'];
+
+ $isset_min = $min - 1;
+
+ /**
+ * Clean up the string, remove HTML tags, remove BBCodes
+ */
+ $word = strtok($this->cleanup(preg_replace($match, ' ', strip_tags($text)), -1), ' ');
+
+ while (strlen($word))
+ {
+ if (strlen($word) > 255 || strlen($word) <= $isset_min)
+ {
+ /**
+ * Words longer than 255 bytes are ignored. This will have to be
+ * changed whenever we change the length of search_wordlist.word_text
+ *
+ * Words shorter than $isset_min bytes are ignored, too
+ */
+ $word = strtok(' ');
+ continue;
+ }
+
+ $len = utf8_strlen($word);
+
+ /**
+ * Test whether the word is too short to be indexed.
+ *
+ * Note that this limit does NOT apply to CJK and Hangul
+ */
+ if ($len < $min)
+ {
+ /**
+ * Note: this could be optimized. If the codepoint is lower than Hangul's range
+ * we know that it will also be lower than CJK ranges
+ */
+ if ((strncmp($word, self::UTF8_HANGUL_FIRST, 3) < 0 || strncmp($word, self::UTF8_HANGUL_LAST, 3) > 0)
+ && (strncmp($word, self::UTF8_CJK_FIRST, 3) < 0 || strncmp($word, self::UTF8_CJK_LAST, 3) > 0)
+ && (strncmp($word, self::UTF8_CJK_B_FIRST, 4) < 0 || strncmp($word, self::UTF8_CJK_B_LAST, 4) > 0))
+ {
+ $word = strtok(' ');
+ continue;
+ }
+ }
+
+ $words[] = $word;
+ $word = strtok(' ');
+ }
+
+ return $words;
+ }
+
/**
* Clean up a text to remove non-alphanumeric characters
*
@@ -2032,9 +1994,9 @@ class fulltext_native extends \phpbb\search\base
}
/**
- * Returns a list of options for the ACP to display
- */
- public function acp()
+ * {@inheritdoc}
+ */
+ public function get_acp_options(): array
{
/**
* if we need any options, copied from fulltext_native for now, will have to be adjusted or removed
@@ -2042,19 +2004,19 @@ class fulltext_native extends \phpbb\search\base
$tpl = '
';
diff --git a/phpBB/phpbb/search/fulltext_postgres.php b/phpBB/phpbb/search/backend/fulltext_postgres.php
similarity index 70%
rename from phpBB/phpbb/search/fulltext_postgres.php
rename to phpBB/phpbb/search/backend/fulltext_postgres.php
index 0b7b32a6c6..b1855f3119 100644
--- a/phpBB/phpbb/search/fulltext_postgres.php
+++ b/phpBB/phpbb/search/backend/fulltext_postgres.php
@@ -11,12 +11,19 @@
*
*/
-namespace phpbb\search;
+namespace phpbb\search\backend;
+
+use phpbb\config\config;
+use phpbb\db\driver\driver_interface;
+use phpbb\event\dispatcher_interface;
+use phpbb\language\language;
+use phpbb\user;
+use RuntimeException;
/**
* Fulltext search for PostgreSQL
*/
-class fulltext_postgres extends \phpbb\search\base
+class fulltext_postgres extends base implements search_backend_interface
{
/**
* Associative array holding index stats
@@ -43,30 +50,16 @@ class fulltext_postgres extends \phpbb\search\base
*/
protected $phrase_search = false;
- /**
- * Config object
- * @var \phpbb\config\config
- */
- protected $config;
-
- /**
- * Database connection
- * @var \phpbb\db\driver\driver_interface
- */
- protected $db;
-
/**
* phpBB event dispatcher object
- * @var \phpbb\event\dispatcher_interface
+ * @var dispatcher_interface
*/
protected $phpbb_dispatcher;
/**
- * User object
- * @var \phpbb\user
+ * @var language
*/
- protected $user;
-
+ protected $language;
/**
* Contains tidied search query.
* Operators are prefixed in search query and common words excluded
@@ -89,23 +82,23 @@ class fulltext_postgres extends \phpbb\search\base
/**
* Constructor
- * Creates a new \phpbb\search\fulltext_postgres, which is used as a search backend
+ * Creates a new \phpbb\search\backend\fulltext_postgres, which is used as a search backend
*
- * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false
+ * @param config $config Config object
+ * @param driver_interface $db Database object
+ * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object
+ * @param language $language
+ * @param user $user User object
* @param string $phpbb_root_path Relative path to phpBB root
* @param string $phpEx PHP file extension
- * @param \phpbb\auth\auth $auth Auth object
- * @param \phpbb\config\config $config Config object
- * @param \phpbb\db\driver\driver_interface Database object
- * @param \phpbb\user $user User object
- * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object
*/
- public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher)
+ public function __construct(config $config, driver_interface $db, dispatcher_interface $phpbb_dispatcher, language $language, user $user, string $phpbb_root_path, string $phpEx)
{
- $this->config = $config;
- $this->db = $db;
+ global $cache;
+
+ parent::__construct($cache, $config, $db, $user);
$this->phpbb_dispatcher = $phpbb_dispatcher;
- $this->user = $user;
+ $this->language = $language;
$this->word_length = array('min' => $this->config['fulltext_postgres_min_word_len'], 'max' => $this->config['fulltext_postgres_max_word_len']);
@@ -116,44 +109,55 @@ class fulltext_postgres extends \phpbb\search\base
{
include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx);
}
-
- $error = false;
}
/**
- * Returns the name of this search backend to be displayed to administrators
- *
- * @return string Name
- */
- public function get_name()
+ * {@inheritdoc}
+ */
+ public function get_name(): string
{
return 'PostgreSQL Fulltext';
}
/**
- * Returns the search_query
- *
- * @return string search query
+ * {@inheritdoc}
*/
- public function get_search_query()
+ public function is_available(): bool
+ {
+ return $this->db->get_sql_layer() == 'postgres';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function init()
+ {
+ if (!$this->is_available())
+ {
+ return $this->language->lang('FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE');
+ }
+
+ return false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_search_query(): string
{
return $this->search_query;
}
/**
- * Returns the common_words array
- *
- * @return array common words that are ignored by search backend
+ * {@inheritdoc}
*/
- public function get_common_words()
+ public function get_common_words(): array
{
return $this->common_words;
}
/**
- * Returns the word_length array
- *
- * @return array min and max word length for searching
+ * {@inheritdoc}
*/
public function get_word_length()
{
@@ -161,39 +165,9 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
- * Returns if phrase search is supported or not
- *
- * @return bool
+ * {@inheritdoc}
*/
- public function supports_phrase_search()
- {
- return $this->phrase_search;
- }
-
- /**
- * Checks for correct PostgreSQL version and stores min/max word length in the config
- *
- * @return string|bool Language key of the error/incompatibility occurred
- */
- public function init()
- {
- if ($this->db->get_sql_layer() != 'postgres')
- {
- return $this->user->lang['FULLTEXT_POSTGRES_INCOMPATIBLE_DATABASE'];
- }
-
- return false;
- }
-
- /**
- * Splits keywords entered by a user into an array of words stored in $this->split_words
- * Stores the tidied search query in $this->search_query
- *
- * @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
- */
- public function split_keywords(&$keywords, $terms)
+ public function split_keywords(string &$keywords, string $terms): bool
{
if ($terms == 'all')
{
@@ -280,53 +254,11 @@ class fulltext_postgres extends \phpbb\search\base
return false;
}
- /**
- * Turns text into an array of words
- * @param string $text contains post text/subject
- */
- public function split_message($text)
- {
- // Split words
- $text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text)));
- $matches = array();
- preg_match_all('#(?:[^\p{L}\p{N}*]|^)([+\-|]?(?:[\p{L}\p{N}*]+\'?)*[\p{L}\p{N}*])(?:[^\p{L}\p{N}*]|$)#u', $text, $matches);
- $text = $matches[1];
-
- // remove too short or too long words
- $text = array_values($text);
- for ($i = 0, $n = count($text); $i < $n; $i++)
- {
- $text[$i] = trim($text[$i]);
- 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]);
- }
- }
-
- return array_values($text);
- }
/**
- * Performs a search on keywords depending on display specific params. You have to run split_keywords() first
- *
- * @param string $type contains either posts or topics depending on what should be searched for
- * @param string $fields contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched)
- * @param string $terms is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
- * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query
- * @param string $sort_key is the key of $sort_by_sql for the selected sorting
- * @param string $sort_dir is either a or d representing ASC and DESC
- * @param string $sort_days specifies the maximum amount of days a post may be old
- * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
- * @param string $post_visibility specifies which types of posts the user can view in which forums
- * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
- * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty
- * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
- * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
- * @param int $start indicates the first index of the page
- * @param int $per_page number of ids each page is supposed to contain
- * @return boolean|int total number of results
- */
- public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page)
+ * {@inheritdoc}
+ */
+ public function keyword_search(string $type, string $fields, string $terms, array $sort_by_sql, string $sort_key, string $sort_dir, string $sort_days, array $ex_fid_ary, string $post_visibility, int $topic_id, array $author_ary, string $author_name, array &$id_ary, int &$start, int $per_page)
{
// No keywords? No posts
if (!$this->search_query)
@@ -355,21 +287,21 @@ class fulltext_postgres extends \phpbb\search\base
);
/**
- * Allow changing the search_key for cached results
- *
- * @event core.search_postgres_by_keyword_modify_search_key
- * @var array search_key_array Array with search parameters to generate the search_key
- * @var string type Searching type ('posts', 'topics')
- * @var string fields Searching fields ('titleonly', 'msgonly', 'firstpost', 'all')
- * @var string terms Searching terms ('all', 'any')
- * @var int sort_days Time, in days, of the oldest possible post to list
- * @var string sort_key The sort type used from the possible sort types
- * @var int topic_id Limit the search to this topic_id only
- * @var array ex_fid_ary Which forums not to search on
- * @var string post_visibility Post visibility data
- * @var array author_ary Array of user_id containing the users to filter the results to
- * @since 3.1.7-RC1
- */
+ * Allow changing the search_key for cached results
+ *
+ * @event core.search_postgres_by_keyword_modify_search_key
+ * @var array search_key_array Array with search parameters to generate the search_key
+ * @var string type Searching type ('posts', 'topics')
+ * @var string fields Searching fields ('titleonly', 'msgonly', 'firstpost', 'all')
+ * @var string terms Searching terms ('all', 'any')
+ * @var int sort_days Time, in days, of the oldest possible post to list
+ * @var string sort_key The sort type used from the possible sort types
+ * @var int topic_id Limit the search to this topic_id only
+ * @var array ex_fid_ary Which forums not to search on
+ * @var string post_visibility Post visibility data
+ * @var array author_ary Array of user_id containing the users to filter the results to
+ * @since 3.1.7-RC1
+ */
$vars = array(
'search_key_array',
'type',
@@ -393,7 +325,7 @@ class fulltext_postgres extends \phpbb\search\base
// try reading the results from cache
$result_count = 0;
- if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE)
+ if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == self::SEARCH_RESULT_IN_CACHE)
{
return $result_count;
}
@@ -430,53 +362,53 @@ class fulltext_postgres extends \phpbb\search\base
$sql_match = 'p.post_subject';
$sql_match_where = ' AND p.post_id = t.topic_first_post_id';
$join_topic = true;
- break;
+ break;
case 'msgonly':
$sql_match = 'p.post_text';
$sql_match_where = '';
- break;
+ break;
case 'firstpost':
$sql_match = 'p.post_subject, p.post_text';
$sql_match_where = ' AND p.post_id = t.topic_first_post_id';
$join_topic = true;
- break;
+ break;
default:
$sql_match = 'p.post_subject, p.post_text';
$sql_match_where = '';
- break;
+ break;
}
$tsearch_query = $this->tsearch_query;
/**
- * Allow changing the query used to search for posts using fulltext_postgres
- *
- * @event core.search_postgres_keywords_main_query_before
- * @var string tsearch_query The parsed keywords used for this search
- * @var int result_count The previous result count for the format of the query.
- * Set to 0 to force a re-count
- * @var bool join_topic Weather or not TOPICS_TABLE should be CROSS JOIN'ED
- * @var array author_ary Array of user_id containing the users to filter the results to
- * @var string author_name An extra username to search on (!empty(author_ary) must be true, to be relevant)
- * @var array ex_fid_ary Which forums not to search on
- * @var int topic_id Limit the search to this topic_id only
- * @var string sql_sort_table Extra tables to include in the SQL query.
- * Used in conjunction with sql_sort_join
- * @var string sql_sort_join SQL conditions to join all the tables used together.
- * Used in conjunction with sql_sort_table
- * @var int sort_days Time, in days, of the oldest possible post to list
- * @var string sql_match Which columns to do the search on.
- * @var string sql_match_where Extra conditions to use to properly filter the matching process
- * @var string sort_by_sql The possible predefined sort types
- * @var string sort_key The sort type used from the possible sort types
- * @var string sort_dir "a" for ASC or "d" dor DESC for the sort order used
- * @var string sql_sort The result SQL when processing sort_by_sql + sort_key + sort_dir
- * @var int start How many posts to skip in the search results (used for pagination)
- * @since 3.1.5-RC1
- */
+ * Allow changing the query used to search for posts using fulltext_postgres
+ *
+ * @event core.search_postgres_keywords_main_query_before
+ * @var string tsearch_query The parsed keywords used for this search
+ * @var int result_count The previous result count for the format of the query.
+ * Set to 0 to force a re-count
+ * @var bool join_topic Weather or not TOPICS_TABLE should be CROSS JOIN'ED
+ * @var array author_ary Array of user_id containing the users to filter the results to
+ * @var string author_name An extra username to search on (!empty(author_ary) must be true, to be relevant)
+ * @var array ex_fid_ary Which forums not to search on
+ * @var int topic_id Limit the search to this topic_id only
+ * @var string sql_sort_table Extra tables to include in the SQL query.
+ * Used in conjunction with sql_sort_join
+ * @var string sql_sort_join SQL conditions to join all the tables used together.
+ * Used in conjunction with sql_sort_table
+ * @var int sort_days Time, in days, of the oldest possible post to list
+ * @var string sql_match Which columns to do the search on.
+ * @var string sql_match_where Extra conditions to use to properly filter the matching process
+ * @var string sort_by_sql The possible predefined sort types
+ * @var string sort_key The sort type used from the possible sort types
+ * @var string sort_dir "a" for ASC or "d" dor DESC for the sort order used
+ * @var string sql_sort The result SQL when processing sort_by_sql + sort_key + sort_dir
+ * @var int start How many posts to skip in the search results (used for pagination)
+ * @since 3.1.5-RC1
+ */
$vars = array(
'tsearch_query',
'result_count',
@@ -588,25 +520,9 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
- * Performs a search on an author's posts without caring about message contents. Depends on display specific params
- *
- * @param string $type contains either posts or topics depending on what should be searched for
- * @param boolean $firstpost_only if true, only topic starting posts will be considered
- * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query
- * @param string $sort_key is the key of $sort_by_sql for the selected sorting
- * @param string $sort_dir is either a or d representing ASC and DESC
- * @param string $sort_days specifies the maximum amount of days a post may be old
- * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
- * @param string $post_visibility specifies which types of posts the user can view in which forums
- * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
- * @param array $author_ary an array of author ids
- * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
- * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
- * @param int $start indicates the first index of the page
- * @param int $per_page number of ids each page is supposed to contain
- * @return boolean|int total number of results
- */
- public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page)
+ * {@inheritdoc}
+ */
+ public function author_search(string $type, bool $firstpost_only, array $sort_by_sql, string $sort_key, string $sort_dir, string $sort_days, array $ex_fid_ary, string $post_visibility, int $topic_id, array $author_ary, string $author_name, array &$id_ary, int &$start, int $per_page)
{
// No author? No posts
if (!count($author_ary))
@@ -669,7 +585,7 @@ class fulltext_postgres extends \phpbb\search\base
// try reading the results from cache
$result_count = 0;
- if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE)
+ if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == self::SEARCH_RESULT_IN_CACHE)
{
return $result_count;
}
@@ -872,16 +788,17 @@ class fulltext_postgres 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
- */
- public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
+ * {@inheritdoc}
+ */
+ public function supports_phrase_search(): bool
+ {
+ return $this->phrase_search;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function index(string $mode, int $post_id, string &$message, string &$subject, int $poster_id, int $forum_id)
{
// Split old and new post/subject to obtain array of words
$split_text = $this->split_message($message);
@@ -927,17 +844,17 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
- * Destroy cached results, that might be outdated after deleting a post
- */
- public function index_remove($post_ids, $author_ids, $forum_ids)
+ * {@inheritdoc}
+ */
+ public function index_remove(array $post_ids, array $author_ids, array $forum_ids): void
{
- $this->destroy_cache(array(), $author_ids);
+ $this->destroy_cache([], $author_ids);
}
/**
- * Destroy old cache entries
- */
- public function tidy()
+ * {@inheritdoc}
+ */
+ public function tidy(): void
{
// destroy too old cached search results
$this->destroy_cache(array());
@@ -946,16 +863,14 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
- * Create fulltext index
- *
- * @return string|bool error string is returned incase of errors otherwise false
- */
- public function create_index($acp_module, $u_action)
+ * {@inheritdoc}
+ */
+ public function create_index(int &$post_counter = 0): ?array
{
// Make sure we can actually use PostgreSQL with fulltext indexes
if ($error = $this->init())
{
- return $error;
+ throw new RuntimeException($error);
}
if (empty($this->stats))
@@ -1003,20 +918,18 @@ class fulltext_postgres extends \phpbb\search\base
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
- return false;
+ return null;
}
/**
- * Drop fulltext index
- *
- * @return string|bool error string is returned incase of errors otherwise false
- */
- public function delete_index($acp_module, $u_action)
+ * {@inheritdoc}
+ */
+ public function delete_index(int &$post_counter = null): ?array
{
// Make sure we can actually use PostgreSQL with fulltext indexes
if ($error = $this->init())
{
- return $error;
+ throw new RuntimeException($error);
}
if (empty($this->stats))
@@ -1064,13 +977,13 @@ class fulltext_postgres extends \phpbb\search\base
$this->db->sql_query('TRUNCATE TABLE ' . SEARCH_RESULTS_TABLE);
- return false;
+ return null;
}
/**
- * Returns true if both FULLTEXT indexes exist
+ * {@inheritdoc}
*/
- public function index_created()
+ public function index_created(): bool
{
if (empty($this->stats))
{
@@ -1081,7 +994,7 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
- * Returns an associative array containing information about the indexes
+ * {@inheritdoc}
*/
public function index_stats()
{
@@ -1091,12 +1004,12 @@ class fulltext_postgres extends \phpbb\search\base
}
return array(
- $this->user->lang['FULLTEXT_POSTGRES_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
+ $this->language->lang('FULLTEXT_POSTGRES_TOTAL_POSTS') => ($this->index_created()) ? $this->stats['total_posts'] : 0,
);
}
/**
- * Computes the stats and store them in the $this->stats associative array
+ * {@inheritdoc}
*/
protected function get_stats()
{
@@ -1139,19 +1052,44 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
- * Display various options that can be configured for the backend from the acp
- *
- * @return associative array containing template and config variables
- */
- public function acp()
+ * Turns text into an array of words
+ * @param string $text contains post text/subject
+ * @return array
+ */
+ protected function split_message($text)
+ {
+ // Split words
+ $text = preg_replace('#([^\p{L}\p{N}\'*])#u', '$1$1', str_replace('\'\'', '\' \'', trim($text)));
+ $matches = array();
+ preg_match_all('#(?:[^\p{L}\p{N}*]|^)([+\-|]?(?:[\p{L}\p{N}*]+\'?)*[\p{L}\p{N}*])(?:[^\p{L}\p{N}*]|$)#u', $text, $matches);
+ $text = $matches[1];
+
+ // remove too short or too long words
+ $text = array_values($text);
+ for ($i = 0, $n = count($text); $i < $n; $i++)
+ {
+ $text[$i] = trim($text[$i]);
+ 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]);
+ }
+ }
+
+ return array_values($text);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_acp_options(): array
{
$tpl = '
';
diff --git a/phpBB/phpbb/search/fulltext_sphinx.php b/phpBB/phpbb/search/backend/fulltext_sphinx.php
similarity index 66%
rename from phpBB/phpbb/search/fulltext_sphinx.php
rename to phpBB/phpbb/search/backend/fulltext_sphinx.php
index 8f24f970da..cc6c0b8afe 100644
--- a/phpBB/phpbb/search/fulltext_sphinx.php
+++ b/phpBB/phpbb/search/backend/fulltext_sphinx.php
@@ -11,17 +11,26 @@
*
*/
-namespace phpbb\search;
+namespace phpbb\search\backend;
-define('SPHINX_MAX_MATCHES', 20000);
-define('SPHINX_CONNECT_RETRIES', 3);
-define('SPHINX_CONNECT_WAIT_TIME', 300);
+use phpbb\auth\auth;
+use phpbb\config\config;
+use phpbb\db\driver\driver_interface;
+use phpbb\db\tools\tools_interface;
+use phpbb\event\dispatcher_interface;
+use phpbb\language\language;
+use phpbb\log\log;
+use phpbb\user;
/**
* Fulltext search based on the sphinx search daemon
*/
-class fulltext_sphinx
+class fulltext_sphinx implements search_backend_interface
{
+ protected const SPHINX_MAX_MATCHES = 20000;
+ protected const SPHINX_CONNECT_RETRIES = 3;
+ protected const SPHINX_CONNECT_WAIT_TIME = 300;
+
/**
* Associative array holding index stats
* @var array
@@ -67,25 +76,25 @@ class fulltext_sphinx
/**
* Auth object
- * @var \phpbb\auth\auth
+ * @var auth
*/
protected $auth;
/**
* Config object
- * @var \phpbb\config\config
+ * @var config
*/
protected $config;
/**
* Database connection
- * @var \phpbb\db\driver\driver_interface
+ * @var driver_interface
*/
protected $db;
/**
* Database Tools object
- * @var \phpbb\db\tools\tools_interface
+ * @var tools_interface
*/
protected $db_tools;
@@ -97,13 +106,23 @@ class fulltext_sphinx
/**
* phpBB event dispatcher object
- * @var \phpbb\event\dispatcher_interface
+ * @var dispatcher_interface
*/
protected $phpbb_dispatcher;
+ /**
+ * @var language
+ */
+ protected $language;
+
+ /**
+ * @var log
+ */
+ protected $log;
+
/**
* User object
- * @var \phpbb\user
+ * @var user
*/
protected $user;
@@ -122,30 +141,33 @@ class fulltext_sphinx
/**
* Constructor
- * Creates a new \phpbb\search\fulltext_postgres, which is used as a search backend
+ * Creates a new \phpbb\search\backend\fulltext_postgres, which is used as a search backend
*
- * @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false
+ * @param auth $auth Auth object
+ * @param config $config Config object
+ * @param driver_interface $db Database object
+ * @param tools_interface $db_tools
+ * @param dispatcher_interface $phpbb_dispatcher Event dispatcher object
+ * @param language $language
+ * @param log $log
+ * @param user $user User object
* @param string $phpbb_root_path Relative path to phpBB root
* @param string $phpEx PHP file extension
- * @param \phpbb\auth\auth $auth Auth object
- * @param \phpbb\config\config $config Config object
- * @param \phpbb\db\driver\driver_interface Database object
- * @param \phpbb\user $user User object
- * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object
*/
- public function __construct(&$error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher)
+ public function __construct(auth $auth, config $config, driver_interface $db, tools_interface $db_tools, dispatcher_interface $phpbb_dispatcher, language $language, log $log, user $user, string $phpbb_root_path, string $phpEx)
{
+ $this->auth = $auth;
+ $this->config = $config;
+ $this->db = $db;
+ $this->phpbb_dispatcher = $phpbb_dispatcher;
+ $this->language = $language;
+ $this->log = $log;
+ $this->user = $user;
+
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
- $this->config = $config;
- $this->phpbb_dispatcher = $phpbb_dispatcher;
- $this->user = $user;
- $this->db = $db;
- $this->auth = $auth;
- // Initialize \phpbb\db\tools\tools object
- global $phpbb_container; // TODO inject into object
- $this->db_tools = $phpbb_container->get('dbal.tools');
+ $this->db_tools = $db_tools;
if (!$this->config['fulltext_sphinx_id'])
{
@@ -163,60 +185,32 @@ class fulltext_sphinx
$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));
-
- $error = false;
}
/**
- * Returns the name of this search backend to be displayed to administrators
- *
- * @return string Name
- */
- public function get_name()
+ * {@inheritdoc}
+ */
+ public function get_name(): string
{
return 'Sphinx Fulltext';
}
/**
- * Returns the search_query
- *
- * @return string search query
+ * {@inheritdoc}
*/
- public function get_search_query()
+ public function is_available(): bool
{
- return $this->search_query;
+ return ($this->db->get_sql_layer() == 'mysqli' || $this->db->get_sql_layer() == 'postgres') && class_exists('SphinxClient');
}
/**
- * Returns false as there is no word_len array
- *
- * @return false
+ * {@inheritdoc}
*/
- public function get_word_length()
- {
- return false;
- }
-
- /**
- * Returns an empty array as there are no common_words
- *
- * @return array common words that are ignored by search backend
- */
- public function get_common_words()
- {
- return array();
- }
-
- /**
- * Checks permissions and paths, if everything is correct it generates the config file
- *
- * @return string|bool Language key of the error/incompatibility encountered, or false if successful
- */
public function init()
{
- if ($this->db->get_sql_layer() != 'mysqli' && $this->db->get_sql_layer() != 'postgres')
+ if (!$this->is_available())
{
- return $this->user->lang['FULLTEXT_SPHINX_WRONG_DATABASE'];
+ return $this->language->lang('FULLTEXT_SPHINX_WRONG_DATABASE');
}
// Move delta to main index each hour
@@ -226,214 +220,33 @@ class fulltext_sphinx
}
/**
- * Generates content of sphinx.conf
- *
- * @return bool True if sphinx.conf content is correctly generated, false otherwise
+ * {@inheritdoc}
*/
- protected function config_generate()
+ public function get_search_query(): string
{
- // Check if Database is supported by Sphinx
- if ($this->db->get_sql_layer() == 'mysqli')
- {
- $this->dbtype = 'mysql';
- }
- else if ($this->db->get_sql_layer() == 'postgres')
- {
- $this->dbtype = 'pgsql';
- }
- else
- {
- $this->config_file_data = $this->user->lang('FULLTEXT_SPHINX_WRONG_DATABASE');
- return false;
- }
-
- // Check if directory paths have been filled
- if (!$this->config['fulltext_sphinx_data_path'])
- {
- $this->config_file_data = $this->user->lang('FULLTEXT_SPHINX_NO_CONFIG_DATA');
- return false;
- }
-
- 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
- fulltext_sphinx_id for this, as it should be unique. */
- $config_object = new \phpbb\search\sphinx\config($this->config_file_data);
- $config_data = array(
- 'source source_phpbb_' . $this->id . '_main' => array(
- array('type', $this->dbtype . ' # mysql or pgsql'),
- // This config value sql_host needs to be changed incase sphinx and sql are on different servers
- array('sql_host', $dbhost . ' # SQL server host sphinx connects to'),
- array('sql_user', '[dbuser]'),
- array('sql_pass', '[dbpassword]'),
- array('sql_db', $dbname),
- array('sql_port', $dbport . ' # optional, default is 3306 for mysql and 5432 for pgsql'),
- array('sql_query_pre', 'SET NAMES \'utf8\''),
- array('sql_query_pre', 'UPDATE ' . SPHINX_TABLE . ' SET max_doc_id = (SELECT MAX(post_id) FROM ' . POSTS_TABLE . ') WHERE counter_id = 1'),
- array('sql_query_range', 'SELECT MIN(post_id), MAX(post_id) FROM ' . POSTS_TABLE . ''),
- array('sql_range_step', '5000'),
- array('sql_query', 'SELECT
- p.post_id AS id,
- p.forum_id,
- p.topic_id,
- p.poster_id,
- p.post_visibility,
- CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post,
- p.post_time,
- p.post_subject,
- p.post_subject as title,
- p.post_text as data,
- t.topic_last_post_time,
- 0 as deleted
- FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
- WHERE
- p.topic_id = t.topic_id
- AND p.post_id >= $start AND p.post_id <= $end'),
- array('sql_query_post', ''),
- array('sql_query_post_index', 'UPDATE ' . SPHINX_TABLE . ' SET max_doc_id = $maxid WHERE counter_id = 1'),
- array('sql_attr_uint', 'forum_id'),
- array('sql_attr_uint', 'topic_id'),
- array('sql_attr_uint', 'poster_id'),
- array('sql_attr_uint', 'post_visibility'),
- array('sql_attr_bool', 'topic_first_post'),
- array('sql_attr_bool', 'deleted'),
- array('sql_attr_timestamp', 'post_time'),
- array('sql_attr_timestamp', 'topic_last_post_time'),
- array('sql_attr_string', 'post_subject'),
- ),
- 'source source_phpbb_' . $this->id . '_delta : source_phpbb_' . $this->id . '_main' => array(
- array('sql_query_pre', 'SET NAMES \'utf8\''),
- array('sql_query_range', ''),
- array('sql_range_step', ''),
- array('sql_query', 'SELECT
- p.post_id AS id,
- p.forum_id,
- p.topic_id,
- p.poster_id,
- p.post_visibility,
- CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post,
- p.post_time,
- p.post_subject,
- p.post_subject as title,
- p.post_text as data,
- t.topic_last_post_time,
- 0 as deleted
- FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
- WHERE
- p.topic_id = t.topic_id
- AND p.post_id >= ( SELECT max_doc_id FROM ' . SPHINX_TABLE . ' WHERE counter_id=1 )'),
- array('sql_query_post_index', ''),
- ),
- 'index index_phpbb_' . $this->id . '_main' => array(
- array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main'),
- array('source', 'source_phpbb_' . $this->id . '_main'),
- array('docinfo', 'extern'),
- array('morphology', 'none'),
- array('stopwords', ''),
- array('wordforms', ' # optional, specify path to wordforms file. See ./docs/sphinx_wordforms.txt for example'),
- array('exceptions', ' # optional, specify path to exceptions file. See ./docs/sphinx_exceptions.txt for example'),
- array('min_word_len', '2'),
- array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'),
- array('ignore_chars', 'U+0027, U+002C'),
- array('min_prefix_len', '3 # Minimum number of characters for wildcard searches by prefix (min 1). Default is 3. If specified, set min_infix_len to 0'),
- array('min_infix_len', '0 # Minimum number of characters for wildcard searches by infix (min 2). If specified, set min_prefix_len to 0'),
- array('html_strip', '1'),
- array('index_exact_words', '0 # Set to 1 to enable exact search operator. Requires wordforms or morphology'),
- array('blend_chars', 'U+23, U+24, U+25, U+26, U+40'),
- ),
- 'index index_phpbb_' . $this->id . '_delta : index_phpbb_' . $this->id . '_main' => array(
- array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta'),
- array('source', 'source_phpbb_' . $this->id . '_delta'),
- ),
- 'indexer' => array(
- array('mem_limit', $this->config['fulltext_sphinx_indexer_mem_limit'] . 'M'),
- ),
- 'searchd' => array(
- array('listen' , ($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost') . ':' . ($this->config['fulltext_sphinx_port'] ? $this->config['fulltext_sphinx_port'] : '9312')),
- array('log', $this->config['fulltext_sphinx_data_path'] . 'log/searchd.log'),
- array('query_log', $this->config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log'),
- array('read_timeout', '5'),
- array('max_children', '30'),
- array('pid_file', $this->config['fulltext_sphinx_data_path'] . 'searchd.pid'),
- array('binlog_path', $this->config['fulltext_sphinx_data_path']),
- ),
- );
-
- $non_unique = array('sql_query_pre' => true, 'sql_attr_uint' => true, 'sql_attr_timestamp' => true, 'sql_attr_str2ordinal' => true, 'sql_attr_bool' => true);
- $delete = array('sql_group_column' => true, 'sql_date_column' => true, 'sql_str2ordinal_column' => true);
-
- /**
- * Allow adding/changing the Sphinx configuration data
- *
- * @event core.search_sphinx_modify_config_data
- * @var array config_data Array with the Sphinx configuration data
- * @var array non_unique Array with the Sphinx non-unique variables to delete
- * @var array delete Array with the Sphinx variables to delete
- * @since 3.1.7-RC1
- */
- $vars = array(
- 'config_data',
- 'non_unique',
- 'delete',
- );
- extract($this->phpbb_dispatcher->trigger_event('core.search_sphinx_modify_config_data', compact($vars)));
-
- foreach ($config_data as $section_name => $section_data)
- {
- $section = $config_object->get_section_by_name($section_name);
- if (!$section)
- {
- $section = $config_object->add_section($section_name);
- }
-
- foreach ($delete as $key => $void)
- {
- $section->delete_variables_by_name($key);
- }
-
- foreach ($non_unique as $key => $void)
- {
- $section->delete_variables_by_name($key);
- }
-
- foreach ($section_data as $entry)
- {
- $key = $entry[0];
- $value = $entry[1];
-
- if (!isset($non_unique[$key]))
- {
- $variable = $section->get_variable_by_name($key);
- if (!$variable)
- {
- $section->create_variable($key, $value);
- }
- else
- {
- $variable->set_value($value);
- }
- }
- else
- {
- $section->create_variable($key, $value);
- }
- }
- }
- $this->config_file_data = $config_object->get_data();
-
- return true;
+ return $this->search_query;
}
/**
- * Splits keywords entered by a user into an array of words stored in $this->split_words
- * Stores the tidied search query in $this->search_query
- *
- * @param string $keywords Contains the keyword as entered by the user
- * @param string $terms is either 'all' or 'any'
- * @return false if no valid keywords were found and otherwise true
- */
- public function split_keywords(&$keywords, $terms)
+ * {@inheritdoc}
+ */
+ public function get_common_words(): array
+ {
+ return array();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_word_length()
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function split_keywords(string &$keywords, string $terms): bool
{
// Keep quotes and new lines
$keywords = str_replace(['"', "\n"], ['"', ' '], trim($keywords));
@@ -465,85 +278,10 @@ class fulltext_sphinx
}
/**
- * Cleans search query passed into Sphinx search engine, as follows:
- * 1. Hyphenated words are replaced with keyword search for either the exact phrase with spaces
- * or as a single word without spaces eg search for "know-it-all" becomes ("know it all"|"knowitall*")
- * 2. Words with apostrophes are contracted eg "it's" becomes "its"
- * 3. <, >, " and & are decoded from HTML entities.
- * 4. Following special characters used as search operators in Sphinx are preserved when used with correct syntax:
- * (a) quorum matching: "the world is a wonderful place"/3
- * Finds 3 of the words within the phrase. Number must be between 1 and 9.
- * (b) proximity search: "hello world"~10
- * Finds hello and world within 10 words of each other. Number can be between 1 and 99.
- * (c) strict word order: aaa << bbb << ccc
- * Finds "aaa" only where it appears before "bbb" and only where "bbb" appears before "ccc".
- * (d) exact match operator: if lemmatizer or stemming enabled,
- * search will find exact match only and ignore other grammatical forms of the same word stem.
- * eg. raining =cats and =dogs
- * will not return "raining cat and dog"
- * eg. ="search this exact phrase"
- * will not return "searched this exact phrase", "searching these exact phrases".
- * 5. Special characters /, ~, << and = not complying with the correct syntax
- * and other reserved operators are escaped and searched literally.
- * Special characters not explicitly listed in charset_table or blend_chars in sphinx.conf
- * will not be indexed and keywords containing them will be ignored by Sphinx.
- * By default, only $, %, & and @ characters are indexed and searchable.
- * String transformation is in backend only and not visible to the end user
- * nor reflected in the results page URL or keyword highlighting.
- *
- * @param string $search_string
- * @return string
- */
- public function sphinx_clean_search_string($search_string)
+ * {@inheritdoc}
+ */
+ public function keyword_search(string $type, string $fields, string $terms, array $sort_by_sql, string $sort_key, string $sort_dir, string $sort_days, array $ex_fid_ary, string $post_visibility, int $topic_id, array $author_ary, string $author_name, array &$id_ary, int &$start, int $per_page)
{
- $from = ['@', '^', '$', '!', '<', '>', '"', '&', '\''];
- $to = ['\@', '\^', '\$', '\!', '<', '>', '"', '&', ''];
-
- $search_string = str_replace($from, $to, $search_string);
-
- $search_string = strrev($search_string);
- $search_string = preg_replace(['#\/(?!"[^"]+")#', '#~(?!"[^"]+")#'], ['/\\', '~\\'], $search_string);
- $search_string = strrev($search_string);
-
- $match = ['#(/|\\\\/)(?)#', '#(~|\\\\~)(?!\d{1,2}(\s|$))#', '#((?:\p{L}|\p{N})+)-((?:\p{L}|\p{N})+)(?:-((?:\p{L}|\p{N})+))?(?:-((?:\p{L}|\p{N})+))?#i', '#<<\s*$#', '#(\S\K=|=(?=\s)|=$)#'];
- $replace = ['\/', '\~', '("$1 $2 $3 $4"|$1$2$3$4*)', '\<\<', '\='];
-
- $search_string = preg_replace($match, $replace, $search_string);
- $search_string = preg_replace('#\s+"\|#', '"|', $search_string);
-
- /**
- * OPTIONAL: Thousands separator stripped from numbers, eg search for '90,000' is queried as '90000'.
- * By default commas are stripped from search index so that '90,000' is indexed as '90000'
- */
- // $search_string = preg_replace('#[0-9]{1,3}\K,(?=[0-9]{3})#', '', $search_string);
-
- return $search_string;
- }
-
- /**
- * Performs a search on keywords depending on display specific params. You have to run split_keywords() first
- *
- * @param string $type contains either posts or topics depending on what should be searched for
- * @param string $fields contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched)
- * @param string $terms is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
- * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query
- * @param string $sort_key is the key of $sort_by_sql for the selected sorting
- * @param string $sort_dir is either a or d representing ASC and DESC
- * @param string $sort_days specifies the maximum amount of days a post may be old
- * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
- * @param string $post_visibility specifies which types of posts the user can view in which forums
- * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
- * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty
- * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
- * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
- * @param int $start indicates the first index of the page
- * @param int $per_page number of ids each page is supposed to contain
- * @return boolean|int total number of results
- */
- public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page)
- {
- global $user, $phpbb_log;
-
// No keywords? No posts.
if (!strlen($this->search_query) && !count($author_ary))
{
@@ -710,28 +448,28 @@ class fulltext_sphinx
$this->sphinx->SetFilter('deleted', array(0));
- $this->sphinx->SetLimits((int) $start, (int) $per_page, max(SPHINX_MAX_MATCHES, (int) $start + $per_page));
+ $this->sphinx->SetLimits((int) $start, (int) $per_page, max(self::SPHINX_MAX_MATCHES, (int) $start + $per_page));
$result = $this->sphinx->Query($search_query_prefix . $this->sphinx_clean_search_string(str_replace('"', '"', $this->search_query)), $this->indexes);
// Could be connection to localhost:9312 failed (errno=111,
// msg=Connection refused) during rotate, retry if so
- $retries = SPHINX_CONNECT_RETRIES;
+ $retries = self::SPHINX_CONNECT_RETRIES;
while (!$result && (strpos($this->sphinx->GetLastError(), "errno=111,") !== false) && $retries--)
{
- usleep(SPHINX_CONNECT_WAIT_TIME);
+ usleep(self::SPHINX_CONNECT_WAIT_TIME);
$result = $this->sphinx->Query($search_query_prefix . $this->sphinx_clean_search_string(str_replace('"', '"', $this->search_query)), $this->indexes);
}
if ($this->sphinx->GetLastError())
{
- $phpbb_log->add('critical', $user->data['user_id'], $user->ip, 'LOG_SPHINX_ERROR', false, array($this->sphinx->GetLastError()));
+ $this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_SPHINX_ERROR', false, array($this->sphinx->GetLastError()));
if ($this->auth->acl_get('a_'))
{
- trigger_error($this->user->lang('SPHINX_SEARCH_FAILED', $this->sphinx->GetLastError()));
+ trigger_error($this->language->lang('SPHINX_SEARCH_FAILED', $this->sphinx->GetLastError()));
}
else
{
- trigger_error($this->user->lang('SPHINX_SEARCH_FAILED_LOG'));
+ trigger_error($this->language->lang('SPHINX_SEARCH_FAILED_LOG'));
}
}
@@ -741,15 +479,15 @@ class fulltext_sphinx
{
$start = floor(($result_count - 1) / $per_page) * $per_page;
- $this->sphinx->SetLimits((int) $start, (int) $per_page, max(SPHINX_MAX_MATCHES, (int) $start + $per_page));
+ $this->sphinx->SetLimits((int) $start, (int) $per_page, max(self::SPHINX_MAX_MATCHES, (int) $start + $per_page));
$result = $this->sphinx->Query($search_query_prefix . $this->sphinx_clean_search_string(str_replace('"', '"', $this->search_query)), $this->indexes);
// Could be connection to localhost:9312 failed (errno=111,
// msg=Connection refused) during rotate, retry if so
- $retries = SPHINX_CONNECT_RETRIES;
+ $retries = self::SPHINX_CONNECT_RETRIES;
while (!$result && (strpos($this->sphinx->GetLastError(), "errno=111,") !== false) && $retries--)
{
- usleep(SPHINX_CONNECT_WAIT_TIME);
+ usleep(self::SPHINX_CONNECT_WAIT_TIME);
$result = $this->sphinx->Query($search_query_prefix . $this->sphinx_clean_search_string(str_replace('"', '"', $this->search_query)), $this->indexes);
}
}
@@ -780,25 +518,9 @@ class fulltext_sphinx
}
/**
- * Performs a search on an author's posts without caring about message contents. Depends on display specific params
- *
- * @param string $type contains either posts or topics depending on what should be searched for
- * @param boolean $firstpost_only if true, only topic starting posts will be considered
- * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query
- * @param string $sort_key is the key of $sort_by_sql for the selected sorting
- * @param string $sort_dir is either a or d representing ASC and DESC
- * @param string $sort_days specifies the maximum amount of days a post may be old
- * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
- * @param string $post_visibility specifies which types of posts the user can view in which forums
- * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
- * @param array $author_ary an array of author ids
- * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
- * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
- * @param int $start indicates the first index of the page
- * @param int $per_page number of ids each page is supposed to contain
- * @return boolean|int total number of results
- */
- public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page)
+ * {@inheritdoc}
+ */
+ public function author_search(string $type, bool $firstpost_only, array $sort_by_sql, string $sort_key, string $sort_dir, string $sort_days, array $ex_fid_ary, string $post_visibility, int $topic_id, array $author_ary, string $author_name, array &$id_ary, int &$start, int $per_page)
{
$this->search_query = '';
@@ -809,16 +531,17 @@ class fulltext_sphinx
}
/**
- * Updates wordlist and wordmatch tables when a message is posted or changed
- *
- * @param string $mode Contains the post mode: edit, post, reply, quote
- * @param int $post_id The id of the post which is modified/created
- * @param string &$message New or updated post content
- * @param string &$subject New or updated post subject
- * @param int $poster_id Post author's user id
- * @param int $forum_id The id of the forum in which the post is located
+ * {@inheritdoc}
*/
- public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
+ public function supports_phrase_search(): bool
+ {
+ return false;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function index(string $mode, int $post_id, string &$message, string &$subject, int $poster_id, int $forum_id)
{
/**
* Event to modify method arguments before the Sphinx search index is updated
@@ -882,9 +605,9 @@ class fulltext_sphinx
}
/**
- * Delete a post from the index after it was deleted
- */
- public function index_remove($post_ids, $author_ids, $forum_ids)
+ * {@inheritdoc}
+ */
+ public function index_remove(array $post_ids, array $author_ids, array $forum_ids): void
{
$values = array();
foreach ($post_ids as $post_id)
@@ -896,21 +619,19 @@ class fulltext_sphinx
}
/**
- * Nothing needs to be destroyed
- */
- public function tidy($create = false)
+ * Nothing needs to be destroyed
+ */
+ public function tidy(): void
{
$this->config->set('search_last_gc', time(), false);
}
/**
- * Create sphinx table
- *
- * @return string|bool error string is returned incase of errors otherwise false
- */
- public function create_index($acp_module, $u_action)
+ * {@inheritdoc}
+ */
+ public function create_index(int &$post_counter = 0): ?array
{
- if (!$this->index_created())
+ if ($this->index_created())
{
$table_data = array(
'COLUMNS' => array(
@@ -932,32 +653,26 @@ class fulltext_sphinx
$this->db->sql_query($sql);
}
- return false;
+ return null;
}
/**
- * Drop sphinx table
- *
- * @return string|bool error string is returned incase of errors otherwise false
+ * {@inheritdoc}
*/
- public function delete_index($acp_module, $u_action)
+ public function delete_index(int &$post_counter = null): ?array
{
- if (!$this->index_created())
+ if ($this->index_created())
{
- return false;
+ $this->db_tools->sql_table_drop(SPHINX_TABLE);
}
- $this->db_tools->sql_table_drop(SPHINX_TABLE);
-
- return false;
+ return null;
}
/**
- * Returns true if the sphinx table was created
- *
- * @return bool true if sphinx table was created
+ * {@inheritdoc}
*/
- public function index_created($allow_new_files = true)
+ public function index_created($allow_new_files = true): bool
{
$created = false;
@@ -970,9 +685,7 @@ class fulltext_sphinx
}
/**
- * Returns an associative array containing information about the indexes
- *
- * @return string|bool Language string of error false otherwise
+ * {@inheritdoc}
*/
public function index_stats()
{
@@ -982,15 +695,15 @@ class fulltext_sphinx
}
return array(
- $this->user->lang['FULLTEXT_SPHINX_MAIN_POSTS'] => ($this->index_created()) ? $this->stats['main_posts'] : 0,
- $this->user->lang['FULLTEXT_SPHINX_DELTA_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] - $this->stats['main_posts'] : 0,
- $this->user->lang['FULLTEXT_MYSQL_TOTAL_POSTS'] => ($this->index_created()) ? $this->stats['total_posts'] : 0,
+ $this->language->lang('FULLTEXT_SPHINX_MAIN_POSTS') => ($this->index_created()) ? $this->stats['main_posts'] : 0,
+ $this->language->lang('FULLTEXT_SPHINX_DELTA_POSTS') => ($this->index_created()) ? $this->stats['total_posts'] - $this->stats['main_posts'] : 0,
+ $this->language->lang('FULLTEXT_MYSQL_TOTAL_POSTS') => ($this->index_created()) ? $this->stats['total_posts'] : 0,
);
}
/**
- * Collects stats that can be displayed on the index maintenance page
- */
+ * Computes the stats and store them in the $this->stats associative array
+ */
protected function get_stats()
{
if ($this->index_created())
@@ -1012,11 +725,65 @@ class fulltext_sphinx
}
/**
- * Returns a list of options for the ACP to display
- *
- * @return associative array containing template and config variables
- */
- public function acp()
+ * Cleans search query passed into Sphinx search engine, as follows:
+ * 1. Hyphenated words are replaced with keyword search for either the exact phrase with spaces
+ * or as a single word without spaces eg search for "know-it-all" becomes ("know it all"|"knowitall*")
+ * 2. Words with apostrophes are contracted eg "it's" becomes "its"
+ * 3. <, >, " and & are decoded from HTML entities.
+ * 4. Following special characters used as search operators in Sphinx are preserved when used with correct syntax:
+ * (a) quorum matching: "the world is a wonderful place"/3
+ * Finds 3 of the words within the phrase. Number must be between 1 and 9.
+ * (b) proximity search: "hello world"~10
+ * Finds hello and world within 10 words of each other. Number can be between 1 and 99.
+ * (c) strict word order: aaa << bbb << ccc
+ * Finds "aaa" only where it appears before "bbb" and only where "bbb" appears before "ccc".
+ * (d) exact match operator: if lemmatizer or stemming enabled,
+ * search will find exact match only and ignore other grammatical forms of the same word stem.
+ * eg. raining =cats and =dogs
+ * will not return "raining cat and dog"
+ * eg. ="search this exact phrase"
+ * will not return "searched this exact phrase", "searching these exact phrases".
+ * 5. Special characters /, ~, << and = not complying with the correct syntax
+ * and other reserved operators are escaped and searched literally.
+ * Special characters not explicitly listed in charset_table or blend_chars in sphinx.conf
+ * will not be indexed and keywords containing them will be ignored by Sphinx.
+ * By default, only $, %, & and @ characters are indexed and searchable.
+ * String transformation is in backend only and not visible to the end user
+ * nor reflected in the results page URL or keyword highlighting.
+ *
+ * @param string $search_string
+ * @return string
+ */
+ protected function sphinx_clean_search_string($search_string)
+ {
+ $from = ['@', '^', '$', '!', '<', '>', '"', '&', '\''];
+ $to = ['\@', '\^', '\$', '\!', '<', '>', '"', '&', ''];
+
+ $search_string = str_replace($from, $to, $search_string);
+
+ $search_string = strrev($search_string);
+ $search_string = preg_replace(['#\/(?!"[^"]+")#', '#~(?!"[^"]+")#'], ['/\\', '~\\'], $search_string);
+ $search_string = strrev($search_string);
+
+ $match = ['#(/|\\\\/)(?)#', '#(~|\\\\~)(?!\d{1,2}(\s|$))#', '#((?:\p{L}|\p{N})+)-((?:\p{L}|\p{N})+)(?:-((?:\p{L}|\p{N})+))?(?:-((?:\p{L}|\p{N})+))?#i', '#<<\s*$#', '#(\S\K=|=(?=\s)|=$)#'];
+ $replace = ['\/', '\~', '("$1 $2 $3 $4"|$1$2$3$4*)', '\<\<', '\='];
+
+ $search_string = preg_replace($match, $replace, $search_string);
+ $search_string = preg_replace('#\s+"\|#', '"|', $search_string);
+
+ /**
+ * OPTIONAL: Thousands separator stripped from numbers, eg search for '90,000' is queried as '90000'.
+ * By default commas are stripped from search index so that '90,000' is indexed as '90000'
+ */
+ // $search_string = preg_replace('#[0-9]{1,3}\K,(?=[0-9]{3})#', '', $search_string);
+
+ return $search_string;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function get_acp_options(): array
{
$config_vars = array(
'fulltext_sphinx_data_path' => 'string',
@@ -1026,25 +793,25 @@ class fulltext_sphinx
);
$tpl = '
- ' . $this->user->lang['FULLTEXT_SPHINX_CONFIGURE']. '
+ ' . $this->language->lang('FULLTEXT_SPHINX_CONFIGURE'). '
';
@@ -1055,4 +822,204 @@ class fulltext_sphinx
'config' => $config_vars
);
}
+
+ /**
+ * Generates content of sphinx.conf
+ *
+ * @return bool True if sphinx.conf content is correctly generated, false otherwise
+ */
+ protected function config_generate()
+ {
+ // Check if Database is supported by Sphinx
+ if ($this->db->get_sql_layer() == 'mysqli')
+ {
+ $this->dbtype = 'mysql';
+ }
+ else if ($this->db->get_sql_layer() == 'postgres')
+ {
+ $this->dbtype = 'pgsql';
+ }
+ else
+ {
+ $this->config_file_data = $this->language->lang('FULLTEXT_SPHINX_WRONG_DATABASE');
+ return false;
+ }
+
+ // Check if directory paths have been filled
+ if (!$this->config['fulltext_sphinx_data_path'])
+ {
+ $this->config_file_data = $this->language->lang('FULLTEXT_SPHINX_NO_CONFIG_DATA');
+ return false;
+ }
+
+ 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
+ fulltext_sphinx_id for this, as it should be unique. */
+ $config_object = new \phpbb\search\sphinx\config($this->config_file_data);
+ $config_data = array(
+ 'source source_phpbb_' . $this->id . '_main' => array(
+ array('type', $this->dbtype . ' # mysql or pgsql'),
+ // This config value sql_host needs to be changed incase sphinx and sql are on different servers
+ array('sql_host', $dbhost . ' # SQL server host sphinx connects to'),
+ array('sql_user', '[dbuser]'),
+ array('sql_pass', '[dbpassword]'),
+ array('sql_db', $dbname),
+ array('sql_port', $dbport . ' # optional, default is 3306 for mysql and 5432 for pgsql'),
+ array('sql_query_pre', 'SET NAMES \'utf8\''),
+ array('sql_query_pre', 'UPDATE ' . SPHINX_TABLE . ' SET max_doc_id = (SELECT MAX(post_id) FROM ' . POSTS_TABLE . ') WHERE counter_id = 1'),
+ array('sql_query_range', 'SELECT MIN(post_id), MAX(post_id) FROM ' . POSTS_TABLE . ''),
+ array('sql_range_step', '5000'),
+ array('sql_query', 'SELECT
+ p.post_id AS id,
+ p.forum_id,
+ p.topic_id,
+ p.poster_id,
+ p.post_visibility,
+ CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post,
+ p.post_time,
+ p.post_subject,
+ p.post_subject as title,
+ p.post_text as data,
+ t.topic_last_post_time,
+ 0 as deleted
+ FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
+ WHERE
+ p.topic_id = t.topic_id
+ AND p.post_id >= $start AND p.post_id <= $end'),
+ array('sql_query_post', ''),
+ array('sql_query_post_index', 'UPDATE ' . SPHINX_TABLE . ' SET max_doc_id = $maxid WHERE counter_id = 1'),
+ array('sql_attr_uint', 'forum_id'),
+ array('sql_attr_uint', 'topic_id'),
+ array('sql_attr_uint', 'poster_id'),
+ array('sql_attr_uint', 'post_visibility'),
+ array('sql_attr_bool', 'topic_first_post'),
+ array('sql_attr_bool', 'deleted'),
+ array('sql_attr_timestamp', 'post_time'),
+ array('sql_attr_timestamp', 'topic_last_post_time'),
+ array('sql_attr_string', 'post_subject'),
+ ),
+ 'source source_phpbb_' . $this->id . '_delta : source_phpbb_' . $this->id . '_main' => array(
+ array('sql_query_pre', 'SET NAMES \'utf8\''),
+ array('sql_query_range', ''),
+ array('sql_range_step', ''),
+ array('sql_query', 'SELECT
+ p.post_id AS id,
+ p.forum_id,
+ p.topic_id,
+ p.poster_id,
+ p.post_visibility,
+ CASE WHEN p.post_id = t.topic_first_post_id THEN 1 ELSE 0 END as topic_first_post,
+ p.post_time,
+ p.post_subject,
+ p.post_subject as title,
+ p.post_text as data,
+ t.topic_last_post_time,
+ 0 as deleted
+ FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
+ WHERE
+ p.topic_id = t.topic_id
+ AND p.post_id >= ( SELECT max_doc_id FROM ' . SPHINX_TABLE . ' WHERE counter_id=1 )'),
+ array('sql_query_post_index', ''),
+ ),
+ 'index index_phpbb_' . $this->id . '_main' => array(
+ array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_main'),
+ array('source', 'source_phpbb_' . $this->id . '_main'),
+ array('docinfo', 'extern'),
+ array('morphology', 'none'),
+ array('stopwords', ''),
+ array('wordforms', ' # optional, specify path to wordforms file. See ./docs/sphinx_wordforms.txt for example'),
+ array('exceptions', ' # optional, specify path to exceptions file. See ./docs/sphinx_exceptions.txt for example'),
+ array('min_word_len', '2'),
+ array('charset_table', 'U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00E0..U+00F6, U+00E0..U+00F6, U+00D8..U+00DE->U+00F8..U+00FE, U+00F8..U+00FE, U+0100->U+0101, U+0101, U+0102->U+0103, U+0103, U+0104->U+0105, U+0105, U+0106->U+0107, U+0107, U+0108->U+0109, U+0109, U+010A->U+010B, U+010B, U+010C->U+010D, U+010D, U+010E->U+010F, U+010F, U+0110->U+0111, U+0111, U+0112->U+0113, U+0113, U+0114->U+0115, U+0115, U+0116->U+0117, U+0117, U+0118->U+0119, U+0119, U+011A->U+011B, U+011B, U+011C->U+011D, U+011D, U+011E->U+011F, U+011F, U+0130->U+0131, U+0131, U+0132->U+0133, U+0133, U+0134->U+0135, U+0135, U+0136->U+0137, U+0137, U+0139->U+013A, U+013A, U+013B->U+013C, U+013C, U+013D->U+013E, U+013E, U+013F->U+0140, U+0140, U+0141->U+0142, U+0142, U+0143->U+0144, U+0144, U+0145->U+0146, U+0146, U+0147->U+0148, U+0148, U+014A->U+014B, U+014B, U+014C->U+014D, U+014D, U+014E->U+014F, U+014F, U+0150->U+0151, U+0151, U+0152->U+0153, U+0153, U+0154->U+0155, U+0155, U+0156->U+0157, U+0157, U+0158->U+0159, U+0159, U+015A->U+015B, U+015B, U+015C->U+015D, U+015D, U+015E->U+015F, U+015F, U+0160->U+0161, U+0161, U+0162->U+0163, U+0163, U+0164->U+0165, U+0165, U+0166->U+0167, U+0167, U+0168->U+0169, U+0169, U+016A->U+016B, U+016B, U+016C->U+016D, U+016D, U+016E->U+016F, U+016F, U+0170->U+0171, U+0171, U+0172->U+0173, U+0173, U+0174->U+0175, U+0175, U+0176->U+0177, U+0177, U+0178->U+00FF, U+00FF, U+0179->U+017A, U+017A, U+017B->U+017C, U+017C, U+017D->U+017E, U+017E, U+0410..U+042F->U+0430..U+044F, U+0430..U+044F, U+4E00..U+9FFF'),
+ array('ignore_chars', 'U+0027, U+002C'),
+ array('min_prefix_len', '3 # Minimum number of characters for wildcard searches by prefix (min 1). Default is 3. If specified, set min_infix_len to 0'),
+ array('min_infix_len', '0 # Minimum number of characters for wildcard searches by infix (min 2). If specified, set min_prefix_len to 0'),
+ array('html_strip', '1'),
+ array('index_exact_words', '0 # Set to 1 to enable exact search operator. Requires wordforms or morphology'),
+ array('blend_chars', 'U+23, U+24, U+25, U+26, U+40'),
+ ),
+ 'index index_phpbb_' . $this->id . '_delta : index_phpbb_' . $this->id . '_main' => array(
+ array('path', $this->config['fulltext_sphinx_data_path'] . 'index_phpbb_' . $this->id . '_delta'),
+ array('source', 'source_phpbb_' . $this->id . '_delta'),
+ ),
+ 'indexer' => array(
+ array('mem_limit', $this->config['fulltext_sphinx_indexer_mem_limit'] . 'M'),
+ ),
+ 'searchd' => array(
+ array('listen' , ($this->config['fulltext_sphinx_host'] ? $this->config['fulltext_sphinx_host'] : 'localhost') . ':' . ($this->config['fulltext_sphinx_port'] ? $this->config['fulltext_sphinx_port'] : '9312')),
+ array('log', $this->config['fulltext_sphinx_data_path'] . 'log/searchd.log'),
+ array('query_log', $this->config['fulltext_sphinx_data_path'] . 'log/sphinx-query.log'),
+ array('read_timeout', '5'),
+ array('max_children', '30'),
+ array('pid_file', $this->config['fulltext_sphinx_data_path'] . 'searchd.pid'),
+ array('binlog_path', $this->config['fulltext_sphinx_data_path']),
+ ),
+ );
+
+ $non_unique = array('sql_query_pre' => true, 'sql_attr_uint' => true, 'sql_attr_timestamp' => true, 'sql_attr_str2ordinal' => true, 'sql_attr_bool' => true);
+ $delete = array('sql_group_column' => true, 'sql_date_column' => true, 'sql_str2ordinal_column' => true);
+
+ /**
+ * Allow adding/changing the Sphinx configuration data
+ *
+ * @event core.search_sphinx_modify_config_data
+ * @var array config_data Array with the Sphinx configuration data
+ * @var array non_unique Array with the Sphinx non-unique variables to delete
+ * @var array delete Array with the Sphinx variables to delete
+ * @since 3.1.7-RC1
+ */
+ $vars = array(
+ 'config_data',
+ 'non_unique',
+ 'delete',
+ );
+ extract($this->phpbb_dispatcher->trigger_event('core.search_sphinx_modify_config_data', compact($vars)));
+
+ foreach ($config_data as $section_name => $section_data)
+ {
+ $section = $config_object->get_section_by_name($section_name);
+ if (!$section)
+ {
+ $section = $config_object->add_section($section_name);
+ }
+
+ foreach ($delete as $key => $void)
+ {
+ $section->delete_variables_by_name($key);
+ }
+
+ foreach ($non_unique as $key => $void)
+ {
+ $section->delete_variables_by_name($key);
+ }
+
+ foreach ($section_data as $entry)
+ {
+ $key = $entry[0];
+ $value = $entry[1];
+
+ if (!isset($non_unique[$key]))
+ {
+ $variable = $section->get_variable_by_name($key);
+ if (!$variable)
+ {
+ $section->create_variable($key, $value);
+ }
+ else
+ {
+ $variable->set_value($value);
+ }
+ }
+ else
+ {
+ $section->create_variable($key, $value);
+ }
+ }
+ }
+ $this->config_file_data = $config_object->get_data();
+
+ return true;
+ }
}
diff --git a/phpBB/phpbb/search/backend/search_backend_interface.php b/phpBB/phpbb/search/backend/search_backend_interface.php
new file mode 100644
index 0000000000..1fdc138028
--- /dev/null
+++ b/phpBB/phpbb/search/backend/search_backend_interface.php
@@ -0,0 +1,196 @@
+
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\search\backend;
+
+interface search_backend_interface
+{
+ /**
+ * Returns the name of this search backend to be displayed to administrators
+ *
+ * @return string Name
+ */
+ public function get_name(): string;
+
+ /**
+ * Returns if the search engine is available
+ *
+ * @return bool
+ */
+ public function is_available(): bool;
+
+ /**
+ * Method executed when a search backend is set from acp.
+ *
+ * Checks permissions and paths, if everything is correct it generates the config file
+ *
+ * @return string|false False if everything was ok or string with error message
+ */
+ public function init();
+
+ /**
+ * Returns the search_query
+ *
+ * @return string search query
+ */
+ public function get_search_query(): string;
+
+ /**
+ * Returns the common_words array
+ *
+ * @return array common words that are ignored by search backend
+ */
+ public function get_common_words(): array;
+
+ /**
+ * Returns the word_length array
+ *
+ * @return array|false min and max word length for searching
+ */
+ public function get_word_length();
+
+ /**
+ * Splits keywords entered by a user into an array of words stored in $this->split_words
+ * This function fills $this->search_query with the cleaned user search query
+ *
+ * If $terms is 'any' then the words will be extracted from the search query
+ * and combined with | inside brackets. They will afterwards be treated like
+ * an standard search query.
+ *
+ * Then it analyses the query and fills the internal arrays $must_not_contain_ids,
+ * $must_contain_ids and $must_exclude_one_ids which are later used by keyword_search()
+ *
+ * @param string $keywords contains the search query string as entered by the user
+ * @param string $terms is either 'all' (use search query as entered, default words to 'must be contained in post')
+ * or 'any' (find all posts containing at least one of the given words)
+ * @return boolean false if no valid keywords were found and otherwise true
+ */
+ public function split_keywords(string &$keywords, string $terms): bool;
+
+ /**
+ * Performs a search on keywords depending on display specific params. You have to run split_keywords() first
+ *
+ * @param string $type contains either posts or topics depending on what should be searched for
+ * @param string $fields contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched)
+ * @param string $terms is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
+ * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query
+ * @param string $sort_key is the key of $sort_by_sql for the selected sorting
+ * @param string $sort_dir is either a or d representing ASC and DESC
+ * @param string $sort_days specifies the maximum amount of days a post may be old
+ * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
+ * @param string $post_visibility specifies which types of posts the user can view in which forums
+ * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
+ * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty
+ * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
+ * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
+ * @param int $start indicates the first index of the page
+ * @param int $per_page number of ids each page is supposed to contain
+ * @return boolean|int total number of results
+ */
+ public function keyword_search(string $type, string $fields, string $terms, array $sort_by_sql, string $sort_key, string $sort_dir, string $sort_days, array $ex_fid_ary, string $post_visibility, int $topic_id, array $author_ary, string $author_name, array &$id_ary, int &$start, int $per_page);
+
+ /**
+ * Performs a search on an author's posts without caring about message contents. Depends on display specific params
+ *
+ * @param string $type contains either posts or topics depending on what should be searched for
+ * @param boolean $firstpost_only if true, only topic starting posts will be considered
+ * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query
+ * @param string $sort_key is the key of $sort_by_sql for the selected sorting
+ * @param string $sort_dir is either a or d representing ASC and DESC
+ * @param string $sort_days specifies the maximum amount of days a post may be old
+ * @param array $ex_fid_ary specifies an array of forum ids which should not be searched
+ * @param string $post_visibility specifies which types of posts the user can view in which forums
+ * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
+ * @param array $author_ary an array of author ids
+ * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match
+ * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
+ * @param int $start indicates the first index of the page
+ * @param int $per_page number of ids each page is supposed to contain
+ * @return boolean|int total number of results
+ */
+ public function author_search(string $type, bool $firstpost_only, array $sort_by_sql, string $sort_key, string $sort_dir, string $sort_days, array $ex_fid_ary, string $post_visibility, int $topic_id, array $author_ary, string $author_name, array &$id_ary, int &$start, int $per_page);
+
+ /**
+ * Returns if phrase search is supported or not
+ *
+ * @return bool
+ */
+ public function supports_phrase_search(): bool;
+
+ /**
+ * Updates wordlist and wordmatch tables when a message is posted or changed
+ * 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
+ */
+ public function index(string $mode, int $post_id, string &$message, string &$subject, int $poster_id, int $forum_id);
+
+ /**
+ * Destroy cached results, that might be outdated after deleting a post
+ * @param array $post_ids
+ * @param array $author_ids
+ * @param array $forum_ids
+ *
+ * @return void
+ */
+ public function index_remove(array $post_ids, array $author_ids, array $forum_ids): void;
+
+ /**
+ * Destroy old cache entries
+ *
+ * @return void
+ */
+ public function tidy(): void;
+
+ /**
+ * Create fulltext index
+ *
+ * @param int $post_counter
+ * @return array|null array with current status or null if finished
+ */
+ public function create_index(int &$post_counter = 0): ?array;
+
+ /**
+ * Drop fulltext index
+ *
+ * @param int $post_counter
+ * @return array|null array with current status or null if finished
+ */
+ public function delete_index(int &$post_counter = 0): ?array;
+
+ /**
+ * Returns true if both FULLTEXT indexes exist
+ *
+ * @return bool
+ */
+ public function index_created(): bool;
+
+ /**
+ * Returns an associative array containing information about the indexes
+ *
+ * @return array|false Language string of error false otherwise
+ */
+ public function index_stats();
+
+ /**
+ * Display various options that can be configured for the backend from the acp
+ *
+ * @return array array containing template and config variables
+ */
+ public function get_acp_options(): array;
+}
diff --git a/phpBB/phpbb/search/sphinx/config.php b/phpBB/phpbb/search/backend/sphinx/config.php
similarity index 99%
rename from phpBB/phpbb/search/sphinx/config.php
rename to phpBB/phpbb/search/backend/sphinx/config.php
index 3205574b45..68a6c8684c 100644
--- a/phpBB/phpbb/search/sphinx/config.php
+++ b/phpBB/phpbb/search/backend/sphinx/config.php
@@ -11,7 +11,7 @@
*
*/
-namespace phpbb\search\sphinx;
+namespace phpbb\search\backend\sphinx;
/**
* An object representing the sphinx configuration
diff --git a/phpBB/phpbb/search/sphinx/config_comment.php b/phpBB/phpbb/search/backend/sphinx/config_comment.php
similarity index 95%
rename from phpBB/phpbb/search/sphinx/config_comment.php
rename to phpBB/phpbb/search/backend/sphinx/config_comment.php
index b5cd0a3db5..b49b9f903f 100644
--- a/phpBB/phpbb/search/sphinx/config_comment.php
+++ b/phpBB/phpbb/search/backend/sphinx/config_comment.php
@@ -11,7 +11,7 @@
*
*/
-namespace phpbb\search\sphinx;
+namespace phpbb\search\backend\sphinx;
/**
* \phpbb\search\sphinx\config_comment
diff --git a/phpBB/phpbb/search/sphinx/config_section.php b/phpBB/phpbb/search/backend/sphinx/config_section.php
similarity index 98%
rename from phpBB/phpbb/search/sphinx/config_section.php
rename to phpBB/phpbb/search/backend/sphinx/config_section.php
index 2fc8b2da17..56409809f4 100644
--- a/phpBB/phpbb/search/sphinx/config_section.php
+++ b/phpBB/phpbb/search/backend/sphinx/config_section.php
@@ -11,7 +11,7 @@
*
*/
-namespace phpbb\search\sphinx;
+namespace phpbb\search\backend\sphinx;
/**
* \phpbb\search\sphinx\config_section
diff --git a/phpBB/phpbb/search/sphinx/config_variable.php b/phpBB/phpbb/search/backend/sphinx/config_variable.php
similarity index 97%
rename from phpBB/phpbb/search/sphinx/config_variable.php
rename to phpBB/phpbb/search/backend/sphinx/config_variable.php
index 85cee20b62..8ff237d676 100644
--- a/phpBB/phpbb/search/sphinx/config_variable.php
+++ b/phpBB/phpbb/search/backend/sphinx/config_variable.php
@@ -11,7 +11,7 @@
*
*/
-namespace phpbb\search\sphinx;
+namespace phpbb\search\backend\sphinx;
/**
* \phpbb\search\sphinx\config_variable
diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php
deleted file mode 100644
index e7d0774b6c..0000000000
--- a/phpBB/phpbb/search/base.php
+++ /dev/null
@@ -1,292 +0,0 @@
-
-* @license GNU General Public License, version 2 (GPL-2.0)
-*
-* For full copyright and license information, please see
-* the docs/CREDITS.txt file.
-*
-*/
-
-namespace phpbb\search;
-
-/**
-* @ignore
-*/
-define('SEARCH_RESULT_NOT_IN_CACHE', 0);
-define('SEARCH_RESULT_IN_CACHE', 1);
-define('SEARCH_RESULT_INCOMPLETE', 2);
-
-/**
-* optional base class for search plugins providing simple caching based on ACM
-* and functions to retrieve ignore_words and synonyms
-*/
-class base
-{
- var $ignore_words = array();
- var $match_synonym = array();
- var $replace_synonym = array();
-
- function search_backend(&$error)
- {
- // This class cannot be used as a search plugin
- $error = true;
- }
-
- /**
- * Retrieves cached search results
- *
- * @param string $search_key an md5 string generated from all the passed search options to identify the results
- * @param int &$result_count will contain the number of all results for the search (not only for the current page)
- * @param array &$id_ary is filled with the ids belonging to the requested page that are stored in the cache
- * @param int &$start indicates the first index of the page
- * @param int $per_page number of ids each page is supposed to contain
- * @param string $sort_dir is either a or d representing ASC and DESC
- *
- * @return int SEARCH_RESULT_NOT_IN_CACHE or SEARCH_RESULT_IN_CACHE or SEARCH_RESULT_INCOMPLETE
- */
- function obtain_ids($search_key, &$result_count, &$id_ary, &$start, $per_page, $sort_dir)
- {
- global $cache;
-
- if (!($stored_ids = $cache->get('_search_results_' . $search_key)))
- {
- // no search results cached for this search_key
- return SEARCH_RESULT_NOT_IN_CACHE;
- }
- else
- {
- $result_count = $stored_ids[-1];
- $reverse_ids = ($stored_ids[-2] != $sort_dir) ? true : false;
- $complete = true;
-
- // Change start parameter in case out of bounds
- if ($result_count)
- {
- if ($start < 0)
- {
- $start = 0;
- }
- else if ($start >= $result_count)
- {
- $start = floor(($result_count - 1) / $per_page) * $per_page;
- }
- }
-
- // change the start to the actual end of the current request if the sort direction differs
- // from the dirction in the cache and reverse the ids later
- if ($reverse_ids)
- {
- $start = $result_count - $start - $per_page;
-
- // the user requested a page past the last index
- if ($start < 0)
- {
- return SEARCH_RESULT_NOT_IN_CACHE;
- }
- }
-
- for ($i = $start, $n = $start + $per_page; ($i < $n) && ($i < $result_count); $i++)
- {
- if (!isset($stored_ids[$i]))
- {
- $complete = false;
- }
- else
- {
- $id_ary[] = $stored_ids[$i];
- }
- }
- unset($stored_ids);
-
- if ($reverse_ids)
- {
- $id_ary = array_reverse($id_ary);
- }
-
- if (!$complete)
- {
- return SEARCH_RESULT_INCOMPLETE;
- }
- return SEARCH_RESULT_IN_CACHE;
- }
- }
-
- /**
- * Caches post/topic ids
- *
- * @param string $search_key an md5 string generated from all the passed search options to identify the results
- * @param string $keywords contains the keywords as entered by the user
- * @param array $author_ary an array of author ids, if the author should be ignored during the search the array is empty
- * @param int $result_count contains the number of all results for the search (not only for the current page)
- * @param array &$id_ary contains a list of post or topic ids that shall be cached, the first element
- * must have the absolute index $start in the result set.
- * @param int $start indicates the first index of the page
- * @param string $sort_dir is either a or d representing ASC and DESC
- *
- * @return null
- */
- function save_ids($search_key, $keywords, $author_ary, $result_count, &$id_ary, $start, $sort_dir)
- {
- global $cache, $config, $db, $user;
-
- $length = min(count($id_ary), $config['search_block_size']);
-
- // nothing to cache so exit
- if (!$length)
- {
- return;
- }
-
- $store_ids = array_slice($id_ary, 0, $length);
-
- // create a new resultset if there is none for this search_key yet
- // or add the ids to the existing resultset
- if (!($store = $cache->get('_search_results_' . $search_key)))
- {
- // add the current keywords to the recent searches in the cache which are listed on the search page
- if (!empty($keywords) || count($author_ary))
- {
- $sql = 'SELECT search_time
- FROM ' . SEARCH_RESULTS_TABLE . '
- WHERE search_key = \'' . $db->sql_escape($search_key) . '\'';
- $result = $db->sql_query($sql);
-
- if (!$db->sql_fetchrow($result))
- {
- $sql_ary = array(
- 'search_key' => $search_key,
- 'search_time' => time(),
- 'search_keywords' => $keywords,
- 'search_authors' => ' ' . implode(' ', $author_ary) . ' '
- );
-
- $sql = 'INSERT INTO ' . SEARCH_RESULTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
- $db->sql_query($sql);
- }
- $db->sql_freeresult($result);
- }
-
- $sql = 'UPDATE ' . USERS_TABLE . '
- SET user_last_search = ' . time() . '
- WHERE user_id = ' . $user->data['user_id'];
- $db->sql_query($sql);
-
- $store = array(-1 => $result_count, -2 => $sort_dir);
- $id_range = range($start, $start + $length - 1);
- }
- else
- {
- // we use one set of results for both sort directions so we have to calculate the indizes
- // for the reversed array and we also have to reverse the ids themselves
- if ($store[-2] != $sort_dir)
- {
- $store_ids = array_reverse($store_ids);
- $id_range = range($store[-1] - $start - $length, $store[-1] - $start - 1);
- }
- else
- {
- $id_range = range($start, $start + $length - 1);
- }
- }
-
- $store_ids = array_combine($id_range, $store_ids);
-
- // append the ids
- if (is_array($store_ids))
- {
- $store += $store_ids;
-
- // if the cache is too big
- if (count($store) - 2 > 20 * $config['search_block_size'])
- {
- // remove everything in front of two blocks in front of the current start index
- for ($i = 0, $n = $id_range[0] - 2 * $config['search_block_size']; $i < $n; $i++)
- {
- if (isset($store[$i]))
- {
- unset($store[$i]);
- }
- }
-
- // remove everything after two blocks after the current stop index
- end($id_range);
- for ($i = $store[-1] - 1, $n = current($id_range) + 2 * $config['search_block_size']; $i > $n; $i--)
- {
- if (isset($store[$i]))
- {
- unset($store[$i]);
- }
- }
- }
- $cache->put('_search_results_' . $search_key, $store, $config['search_store_results']);
-
- $sql = 'UPDATE ' . SEARCH_RESULTS_TABLE . '
- SET search_time = ' . time() . '
- WHERE search_key = \'' . $db->sql_escape($search_key) . '\'';
- $db->sql_query($sql);
- }
-
- unset($store);
- unset($store_ids);
- unset($id_range);
- }
-
- /**
- * Removes old entries from the search results table and removes searches with keywords that contain a word in $words.
- */
- function destroy_cache($words, $authors = false)
- {
- global $db, $cache, $config;
-
- // clear all searches that searched for the specified words
- if (count($words))
- {
- $sql_where = '';
- foreach ($words as $word)
- {
- $sql_where .= " OR search_keywords " . $db->sql_like_expression($db->get_any_char() . $word . $db->get_any_char());
- }
-
- $sql = 'SELECT search_key
- FROM ' . SEARCH_RESULTS_TABLE . "
- WHERE search_keywords LIKE '%*%' $sql_where";
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- $cache->destroy('_search_results_' . $row['search_key']);
- }
- $db->sql_freeresult($result);
- }
-
- // clear all searches that searched for the specified authors
- if (is_array($authors) && count($authors))
- {
- $sql_where = '';
- foreach ($authors as $author)
- {
- $sql_where .= (($sql_where) ? ' OR ' : '') . 'search_authors ' . $db->sql_like_expression($db->get_any_char() . ' ' . (int) $author . ' ' . $db->get_any_char());
- }
-
- $sql = 'SELECT search_key
- FROM ' . SEARCH_RESULTS_TABLE . "
- WHERE $sql_where";
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- $cache->destroy('_search_results_' . $row['search_key']);
- }
- $db->sql_freeresult($result);
- }
-
- $sql = 'DELETE
- FROM ' . SEARCH_RESULTS_TABLE . '
- WHERE search_time < ' . (time() - (int) $config['search_store_results']);
- $db->sql_query($sql);
- }
-}
diff --git a/phpBB/phpbb/search/index.htm b/phpBB/phpbb/search/index.htm
deleted file mode 100644
index ee1f723a7d..0000000000
--- a/phpBB/phpbb/search/index.htm
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/phpBB/phpbb/search/search_backend_factory.php b/phpBB/phpbb/search/search_backend_factory.php
new file mode 100644
index 0000000000..eac31885ed
--- /dev/null
+++ b/phpBB/phpbb/search/search_backend_factory.php
@@ -0,0 +1,65 @@
+
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+namespace phpbb\search;
+
+use phpbb\config\config;
+use phpbb\di\service_collection;
+use phpbb\search\backend\search_backend_interface;
+
+class search_backend_factory
+{
+ /**
+ * @var config
+ */
+ protected $config;
+
+ /**
+ * @var service_collection
+ */
+ protected $search_backends;
+
+ /**
+ * Constructor
+ *
+ * @param config $config
+ * @param service_collection $search_backends
+ */
+ public function __construct(config $config, service_collection $search_backends)
+ {
+ $this->config = $config;
+ $this->search_backends = $search_backends;
+ }
+
+ /**
+ * Obtains a specified search backend
+ *
+ * @param string $class
+ *
+ * @return search_backend_interface
+ */
+ public function get(string $class): search_backend_interface
+ {
+ return $this->search_backends->get_by_class($class);
+ }
+
+ /**
+ * Obtains active search backend
+ *
+ * @return search_backend_interface
+ */
+ public function get_active(): search_backend_interface
+ {
+ return $this->get($this->config['search_type']);
+ }
+}
diff --git a/phpBB/search.php b/phpBB/search.php
index 048985b023..8decc78bb5 100644
--- a/phpBB/search.php
+++ b/phpBB/search.php
@@ -294,19 +294,21 @@ if ($keywords || $author || $author_id || $search_id || $submit)
}
// Select which method we'll use to obtain the post_id or topic_id information
- $search_type = $config['search_type'];
-
- if (!class_exists($search_type))
+ try
{
- trigger_error('NO_SUCH_SEARCH_MODULE');
+ $search_backend_factory = $phpbb_container->get('search.backend_factory');
+ $search = $search_backend_factory->get_active();
}
- // We do some additional checks in the module to ensure it can actually be utilised
- $error = false;
- $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
-
- if ($error)
+ catch (RuntimeException $e)
{
- trigger_error($error);
+ if (strpos($e->getMessage(), 'No service found') === 0)
+ {
+ trigger_error('NO_SUCH_SEARCH_MODULE');
+ }
+ else
+ {
+ throw $e;
+ }
}
// let the search module split up the keywords
@@ -542,7 +544,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
extract($phpbb_dispatcher->trigger_event('core.search_modify_param_after', compact($vars)));
// show_results should not change after this
- $per_page = ($show_results == 'posts') ? $config['posts_per_page'] : $config['topics_per_page'];
+ $per_page = ($show_results == 'posts') ? (int) $config['posts_per_page'] : (int) $config['topics_per_page'];
$total_match_count = 0;
// Set limit for the $total_match_count to reduce server load
@@ -1299,7 +1301,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
// Check if search backend supports phrase search or not
$phrase_search_disabled = '';
- if (strpos(html_entity_decode($keywords), '"') !== false && method_exists($search, 'supports_phrase_search'))
+ if (strpos(html_entity_decode($keywords), '"') !== false)
{
$phrase_search_disabled = $search->supports_phrase_search() ? false : true;
}
diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php
index 5a646bb57e..8f3c6295e6 100644
--- a/tests/content_visibility/delete_post_test.php
+++ b/tests/content_visibility/delete_post_test.php
@@ -13,7 +13,6 @@
require_once __DIR__ . '/../../phpBB/includes/functions_admin.php';
require_once __DIR__ . '/../../phpBB/includes/functions_posting.php';
-require_once __DIR__ . '/../mock/search.php';
class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
{
@@ -292,7 +291,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
$config = new \phpbb\config\config(array(
'num_posts' => 3,
'num_topics' => 1,
- 'search_type' => 'phpbb_mock_search',
+ 'search_type' => 'foo',
));
$cache = new phpbb_mock_cache;
$db = $this->new_dbal();
@@ -323,6 +322,11 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case
// Works as a workaround for tests
$phpbb_container->set('attachment.manager', $attachment_delete);
+ $search_backend = $this->createMock(\phpbb\search\backend\search_backend_interface::class);
+ $search_backend_factory = $this->createMock(\phpbb\search\search_backend_factory::class);
+ $search_backend_factory->method('get_active')->willReturn($search_backend);
+ $phpbb_container->set('search.backend_factory', $search_backend_factory);
+
delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason);
$result = $db->sql_query('SELECT post_id, post_visibility, post_delete_reason
diff --git a/tests/functional/search/base.php b/tests/functional/search/base.php
index 9e49ba93ab..885cd9c684 100644
--- a/tests/functional/search/base.php
+++ b/tests/functional/search/base.php
@@ -38,7 +38,7 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
$this->login();
$this->admin_login();
- $this->create_search_index('\phpbb\search\fulltext_native');
+ $this->create_search_index('phpbb\\search\\backend\\fulltext_native');
$post = $this->create_topic(2, 'Test Topic 1 foosubject', 'This is a test topic posted by the barsearch testing framework.');
@@ -49,18 +49,28 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
if ($values["config[search_type]"] != $this->search_backend)
{
$values["config[search_type]"] = $this->search_backend;
- $form->setValues($values);
+
+ try
+ {
+ $form->setValues($values);
+ }
+ catch(\InvalidArgumentException $e)
+ {
+ // Search backed is not supported because don't appear in the select
+ $this->delete_topic($post['topic_id']);
+ $this->markTestSkipped("Search backend is not supported/running");
+ }
+
$crawler = self::submit($form);
$form = $crawler->selectButton('Yes')->form();
$values = $form->getValues();
$crawler = self::submit($form);
- // check if search backend is not supported
+ // Unknown error selecting search backend
if ($crawler->filter('.errorbox')->count() > 0)
{
- $this->delete_topic($post['topic_id']);
- $this->markTestSkipped("Search backend is not supported/running");
+ $this->fail('Error when trying to select available search backend');
}
$this->create_search_index();
diff --git a/tests/functional/search/mysql_test.php b/tests/functional/search/mysql_test.php
index 0f857e9167..50b2d6487b 100644
--- a/tests/functional/search/mysql_test.php
+++ b/tests/functional/search/mysql_test.php
@@ -18,7 +18,7 @@ require_once __DIR__ . '/base.php';
*/
class phpbb_functional_search_mysql_test extends phpbb_functional_search_base
{
- protected $search_backend = '\phpbb\search\fulltext_mysql';
+ protected $search_backend = 'phpbb\search\backend\fulltext_mysql';
protected function create_search_index($backend = null)
{
diff --git a/tests/functional/search/native_test.php b/tests/functional/search/native_test.php
index 52a653d585..5b8d8f2206 100644
--- a/tests/functional/search/native_test.php
+++ b/tests/functional/search/native_test.php
@@ -18,5 +18,5 @@ require_once __DIR__ . '/base.php';
*/
class phpbb_functional_search_native_test extends phpbb_functional_search_base
{
- protected $search_backend = '\phpbb\search\fulltext_native';
+ protected $search_backend = 'phpbb\search\backend\fulltext_native';
}
diff --git a/tests/functional/search/postgres_test.php b/tests/functional/search/postgres_test.php
index 6f5e7e48c2..4389705d66 100644
--- a/tests/functional/search/postgres_test.php
+++ b/tests/functional/search/postgres_test.php
@@ -18,6 +18,6 @@ require_once __DIR__ . '/base.php';
*/
class phpbb_functional_search_postgres_test extends phpbb_functional_search_base
{
- protected $search_backend = '\phpbb\search\fulltext_postgres';
+ protected $search_backend = 'phpbb\search\backend\fulltext_postgres';
}
diff --git a/tests/functional/search/sphinx_test.php b/tests/functional/search/sphinx_test.php
index 926f1c6424..6e42da0e86 100644
--- a/tests/functional/search/sphinx_test.php
+++ b/tests/functional/search/sphinx_test.php
@@ -18,7 +18,7 @@ require_once __DIR__ . '/base.php';
*/
class phpbb_functional_search_sphinx_test extends phpbb_functional_search_base
{
- protected $search_backend = '\phpbb\search\fulltext_sphinx';
+ protected $search_backend = 'phpbb\search\backend\fulltext_sphinx';
public function test_search_backend()
{
diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php
index f18a8091be..76a0aa50ce 100644
--- a/tests/functions_user/delete_user_test.php
+++ b/tests/functions_user/delete_user_test.php
@@ -33,7 +33,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
$config = new \phpbb\config\config(array(
'load_online_time' => 5,
- 'search_type' => '\phpbb\search\fulltext_mysql',
+ 'search_type' => '\phpbb\search\backend\fulltext_mysql',
));
$cache = new phpbb_mock_null_cache();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
@@ -54,6 +54,13 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
'auth.provider_collection',
$provider_collection
);
+
+ $search_backend = $this->createMock(\phpbb\search\backend\search_backend_interface::class);
+ $search_backend_factory = $this->createMock(\phpbb\search\search_backend_factory::class);
+ $search_backend_factory->method('get_active')->willReturn($search_backend);
+ $phpbb_container->set('search.backend_factory', $search_backend_factory);
+
+
$phpbb_container->setParameter('tables.auth_provider_oauth_token_storage', 'phpbb_oauth_tokens');
$phpbb_container->setParameter('tables.auth_provider_oauth_states', 'phpbb_oauth_states');
$phpbb_container->setParameter('tables.auth_provider_oauth_account_assoc', 'phpbb_oauth_accounts');
diff --git a/tests/mock/search.php b/tests/mock/search.php
deleted file mode 100644
index f30876b4da..0000000000
--- a/tests/mock/search.php
+++ /dev/null
@@ -1,27 +0,0 @@
-
-* @license GNU General Public License, version 2 (GPL-2.0)
-*
-* For full copyright and license information, please see
-* the docs/CREDITS.txt file.
-*
-*/
-
-/**
-*/
-class phpbb_mock_search
-{
-
- public function __construct($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
- {
- }
-
- public function index_remove($post_ids, $poster_ids, $forum_ids)
- {
- }
-}
-
diff --git a/tests/mock/user.php b/tests/mock/user.php
index 5352a22b27..254c02f669 100644
--- a/tests/mock/user.php
+++ b/tests/mock/user.php
@@ -26,7 +26,7 @@ class phpbb_mock_user
public $lang = [];
private $options = array();
- public function optionget($item)
+ public function optionget($item, $data = false)
{
if (!isset($this->options[$item]))
{
@@ -36,7 +36,7 @@ class phpbb_mock_user
return $this->options[$item];
}
- public function optionset($item, $value)
+ public function optionset($item, $value, $data = false)
{
$this->options[$item] = $value;
}
diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php
index 9ff0b7d518..1e822b92af 100644
--- a/tests/search/mysql_test.php
+++ b/tests/search/mysql_test.php
@@ -24,12 +24,14 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case
protected function setUp(): void
{
- global $phpbb_root_path, $phpEx, $config, $user, $cache;
+ global $phpbb_root_path, $phpEx, $config, $cache;
parent::setUp();
// dbal uses cache
- $cache = new phpbb_mock_cache();
+ $cache = $this->createMock('\phpbb\cache\service');
+ $language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
+ $user = $this->createMock('\phpbb\user');
// set config values
$config['fulltext_mysql_min_word_len'] = 4;
@@ -37,8 +39,7 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case
$this->db = $this->new_dbal();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
- $error = null;
- $class = self::get_search_wrapper('\phpbb\search\fulltext_mysql');
- $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user, $phpbb_dispatcher);
+ $class = self::get_search_wrapper('\phpbb\search\backend\fulltext_mysql');
+ $this->search = new $class($config, $this->db, $phpbb_dispatcher, $language, $user, $phpbb_root_path, $phpEx);
}
}
diff --git a/tests/search/native_test.php b/tests/search/native_test.php
index e0b8a86f4b..6d8a03f4aa 100644
--- a/tests/search/native_test.php
+++ b/tests/search/native_test.php
@@ -24,20 +24,21 @@ class phpbb_search_native_test extends phpbb_search_test_case
protected function setUp(): void
{
- global $phpbb_root_path, $phpEx, $config, $user, $cache;
+ global $phpbb_root_path, $phpEx, $config, $cache;
parent::setUp();
// dbal uses cache
- $cache = new phpbb_mock_cache();
+ $cache = $this->createMock('\phpbb\cache\service');
+ $language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
+ $user = $this->createMock('\phpbb\user');
$this->db = $this->new_dbal();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
- $error = null;
- $class = self::get_search_wrapper('\phpbb\search\fulltext_native');
+ $class = self::get_search_wrapper('\phpbb\search\backend\fulltext_native');
$config['fulltext_native_min_chars'] = 2;
$config['fulltext_native_max_chars'] = 14;
- $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user, $phpbb_dispatcher);
+ $this->search = new $class($config, $this->db, $phpbb_dispatcher, $language, $user, $phpbb_root_path, $phpEx);
}
public function keywords()
diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php
index b4edd974ac..545ffafd50 100644
--- a/tests/search/postgres_test.php
+++ b/tests/search/postgres_test.php
@@ -24,12 +24,14 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case
protected function setUp(): void
{
- global $phpbb_root_path, $phpEx, $config, $user, $cache;
+ global $phpbb_root_path, $phpEx, $config, $cache;
parent::setUp();
// dbal uses cache
- $cache = new phpbb_mock_cache();
+ $cache = $this->createMock('\phpbb\cache\service');
+ $language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
+ $user = $this->createMock('\phpbb\user');
// set config values
$config['fulltext_postgres_min_word_len'] = 4;
@@ -37,8 +39,7 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case
$this->db = $this->new_dbal();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
- $error = null;
- $class = self::get_search_wrapper('\phpbb\search\fulltext_postgres');
- $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user, $phpbb_dispatcher);
+ $class = self::get_search_wrapper('\phpbb\search\backend\fulltext_postgres');
+ $this->search = new $class($config, $this->db, $phpbb_dispatcher, $language, $user, $phpbb_root_path, $phpEx);
}
}