[ticket/15540] Refactor search backend classes to Symfony services

PHPBB3-15540
This commit is contained in:
Ruben Calvo 2018-11-07 06:21:46 +00:00 committed by rubencm
parent 271d6d3169
commit 2aabf560b4
36 changed files with 567 additions and 522 deletions

View file

@ -24,6 +24,7 @@ imports:
- { resource: services_profilefield.yml }
- { resource: services_report.yml }
- { resource: services_routing.yml }
- { resource: services_search.yml }
- { resource: services_storage.yml }
- { resource: services_text_formatter.yml }
- { resource: services_text_reparser.yml }

View file

@ -0,0 +1,69 @@
services:
# Search backends
search.fulltext.native:
class: phpbb\search\backend\fulltext_native
arguments:
- '@auth'
- '@config'
- '@dbal.conn'
- '@dispatcher'
- '@user'
- '%core.root_path%'
- '%core.php_ext%'
tags:
- { name: search.backend }
search.fulltext.mysql:
class: phpbb\search\backend\fulltext_mysql
arguments:
- '@auth'
- '@config'
- '@dbal.conn'
- '@dispatcher'
- '@user'
- '%core.root_path%'
- '%core.php_ext%'
tags:
- { name: search.backend }
search.fulltext.postgres:
class: phpbb\search\backend\fulltext_postgres
arguments:
- '@auth'
- '@config'
- '@dbal.conn'
- '@dispatcher'
- '@user'
- '%core.root_path%'
- '%core.php_ext%'
tags:
- { name: search.backend }
search.fulltext.sphinx:
class: phpbb\search\backend\fulltext_sphinx
arguments:
- '@auth'
- '@config'
- '@dbal.conn'
- '@dispatcher'
- '@user'
- '%core.root_path%'
- '%core.php_ext%'
tags:
- { name: search.backend }
# Factory
search.backend_factory:
class: phpbb\search\search_backend_factory
arguments:
- '@config'
- '@search.backend_collection'
# Collections
search.backend_collection:
class: phpbb\di\service_collection
arguments:
- '@service_container'
tags:
- { name: service_collection, tag: search.backend, class_name_aware: true }

View file

@ -39,13 +39,7 @@ if (!class_exists($search_type))
trigger_error('NO_SUCH_SEARCH_MODULE');
}
$error = false;
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
if ($error)
{
trigger_error($error);
}
$search = new $search_type($auth, $config, $db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx);
print "<html>\n<body>\n";

View file

@ -646,11 +646,10 @@ class acp_main
}
// Warn if no search index is created
if ($config['num_posts'] && class_exists($config['search_type']))
if ($config['num_posts'])
{
$error = false;
$search_type = $config['search_type'];
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
$search_backend_factory = $phpbb_container->get('search.backend_factory');
$search = $search_backend_factory->get_active();
if (!$search->index_created())
{

View file

@ -52,6 +52,7 @@ class acp_search
{
global $user, $template, $phpbb_log, $request;
global $config, $phpbb_admin_path, $phpEx;
global $phpbb_container;
$submit = $request->is_set_post('submit');
@ -60,7 +61,7 @@ class acp_search
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
$search_types = $this->get_search_types();
$search_types = $phpbb_container->get('search.backend_collection');
$settings = [
'search_interval' => 'float',
@ -74,14 +75,11 @@ class acp_search
];
$search = null;
$error = false;
$search_options = '';
foreach ($search_types as $type)
foreach ($search_types as $search)
{
if ($this->init_search($type, $search, $error))
{
continue;
}
$type = get_class($search);
$name = $search->get_name();
@ -108,7 +106,6 @@ class acp_search
}
}
unset($search);
unset($error);
$cfg_array = (isset($_REQUEST['config'])) ? $request->variable('config', array('' => ''), true) : array();
$updated = $request->variable('updated', false);
@ -240,7 +237,7 @@ class acp_search
function index($id, $mode)
{
global $db, $user, $template, $phpbb_log, $request;
global $config, $phpbb_admin_path, $phpEx;
global $config, $phpbb_admin_path, $phpEx, $phpbb_container;
$action = $request->variable('action', '');
$this->state = explode(',', $config['search_indexing_state']);
@ -285,12 +282,11 @@ class acp_search
$this->state[0] = $request->variable('search_type', '');
}
$this->search = null;
$error = false;
if ($this->init_search($this->state[0], $this->search, $error))
{
trigger_error($error . adm_back_link($this->u_action), E_USER_WARNING);
}
$search_backend_factory = $phpbb_container->get('search.backend_factory');
$this->search = $search_backend_factory->get($this->state[0]);
$name = $this->search->get_name();
$action = &$this->state[1];
@ -454,16 +450,13 @@ class acp_search
}
}
$search_types = $this->get_search_types();
$search_types = $phpbb_container->get('search.backend_collection');
$search = null;
$error = false;
foreach ($search_types as $type)
foreach ($search_types as $search)
{
if ($this->init_search($type, $search, $error) || !method_exists($search, 'index_created'))
{
continue;
}
$type = get_class($search);
$name = $search->get_name();
@ -508,7 +501,6 @@ class acp_search
}
}
unset($search);
unset($error);
unset($statistics);
unset($data);
@ -562,19 +554,6 @@ class acp_search
"</script>\n";
}
function get_search_types()
{
global $phpbb_extension_manager;
$finder = $phpbb_extension_manager->get_finder();
return $finder
->extension_suffix('_backend')
->extension_directory('/search')
->core_path('phpbb/search/')
->get_classes();
}
function get_max_post_id()
{
global $db;
@ -601,25 +580,4 @@ class acp_search
$config->set('search_indexing_state', implode(',', $this->state), true);
}
/**
* Initialises a search backend object
*
* @return false if no error occurred else an error message
*/
function init_search($type, &$search, &$error)
{
global $phpbb_root_path, $phpEx, $user, $auth, $config, $db, $phpbb_dispatcher;
if (!class_exists($type) || !method_exists($type, 'keyword_search'))
{
$error = $user->lang['NO_SUCH_SEARCH_MODULE'];
return $error;
}
$error = false;
$search = new $type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
return $error;
}
}

View file

@ -904,7 +904,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s
*/
function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = true, $post_count_sync = true, $call_delete_topics = true)
{
global $db, $config, $phpbb_root_path, $phpEx, $auth, $user, $phpbb_container, $phpbb_dispatcher;
global $db, $config, $phpbb_container, $phpbb_dispatcher;
// Notifications types to delete
$delete_notifications_types = array(
@ -1086,20 +1086,8 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
}
// Remove the message from the search index
$search_type = $config['search_type'];
if (!class_exists($search_type))
{
trigger_error('NO_SUCH_SEARCH_MODULE');
}
$error = false;
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
if ($error)
{
trigger_error($error);
}
$search_backend_factory = $phpbb_container->get('search.backend_factory');
$search = $search_backend_factory->get_active();
$search->index_remove($post_ids, $poster_ids, $forum_ids);

View file

@ -2291,21 +2291,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data
// Index message contents
if ($update_search_index && $data_ary['enable_indexing'])
{
// Select the search method and do some additional checks to ensure it can actually be utilised
$search_type = $config['search_type'];
if (!class_exists($search_type))
{
trigger_error('NO_SUCH_SEARCH_MODULE');
}
$error = false;
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
if ($error)
{
trigger_error($error);
}
$search_backend_factory = $phpbb_container->get('search.backend_factory');
$search = $search_backend_factory->get_active();
$search->index($mode, $data_ary['post_id'], $data_ary['message'], $subject, $poster_id, $data_ary['forum_id']);
}

View file

@ -1401,15 +1401,8 @@ function mcp_fork_topic($topic_ids)
if (!isset($search_type) && $topic_row['enable_indexing'])
{
// Select the search method and do some additional checks to ensure it can actually be utilised
$search_type = $config['search_type'];
if (!class_exists($search_type))
{
trigger_error('NO_SUCH_SEARCH_MODULE');
}
$error = false;
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
$search_backend_factory = $phpbb_container->get('search.backend_factory');
$search = $search_backend_factory->get_active();
$search_mode = 'post';
if ($error)

View file

@ -561,7 +561,7 @@ function phpbb_get_num_ips_for_poster(\phpbb\db\driver\driver_interface $db, $po
*/
function change_poster(&$post_info, $userdata)
{
global $auth, $db, $config, $phpbb_root_path, $phpEx, $user, $phpbb_log, $phpbb_dispatcher;
global $db, $config, $user, $phpbb_log, $phpbb_dispatcher;
if (empty($userdata) || $userdata['user_id'] == $post_info['user_id'])
{
@ -632,19 +632,13 @@ function change_poster(&$post_info, $userdata)
}
// refresh search cache of this post
$search_type = $config['search_type'];
$search_backend_factory = $phpbb_container->get('search.backend_factory');
$search = $search_backend_factory->get_active();
if (class_exists($search_type))
{
// 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 && method_exists($search, 'destroy_cache'))
if (method_exists($search, 'destroy_cache'))
{
$search->destroy_cache(array(), array($post_info['user_id'], $userdata['user_id']));
}
}
$from_username = $post_info['username'];
$to_username = $userdata['username'];

View file

@ -428,7 +428,7 @@ function mcp_topic_view($id, $mode, $action)
*/
function split_topic($action, $topic_id, $to_forum_id, $subject)
{
global $db, $template, $user, $phpEx, $phpbb_root_path, $auth, $config, $phpbb_log, $request, $phpbb_dispatcher;
global $db, $template, $user, $phpEx, $phpbb_root_path, $auth, $config, $phpbb_log, $request;
$post_id_list = $request->variable('post_id_list', array(0));
$forum_id = $request->variable('forum_id', 0);
@ -625,20 +625,8 @@ function split_topic($action, $topic_id, $to_forum_id, $subject)
if ($first_post_data['enable_indexing'])
{
// Select the search method and do some additional checks to ensure it can actually be utilised
$search_type = $config['search_type'];
if (!class_exists($search_type))
{
trigger_error('NO_SUCH_SEARCH_MODULE');
}
$error = false;
$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
if ($error)
{
trigger_error($error);
}
$search_backend_factory = $phpbb_container->get('search.backend_factory');
$search = $search_backend_factory->get_active();
$search->index('edit', $first_post_data['post_id'], $first_post_data['post_text'], $subject, $first_post_data['poster_id'], $first_post_data['forum_id']);
}

View file

@ -215,7 +215,7 @@ class convertor
// For conversions we are a bit less strict and set to a search backend we know exist...
if (!class_exists($search_type))
{
$search_type = '\phpbb\search\fulltext_native';
$search_type = 'phpbb\search\backend\fulltext_native';
$config->set('search_type', $search_type);
}
@ -224,13 +224,7 @@ class convertor
trigger_error('NO_SUCH_SEARCH_MODULE');
}
$error = false;
$convert->fulltext_search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
if ($error)
{
trigger_error($error);
}
$convert->fulltext_search = new $search_type($auth, $config, $db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx);
include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
$message_parser = new \parse_message();

View file

@ -275,7 +275,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_block_size'
INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_gc', '7200');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_interval', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_store_results', '1800');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_type', '\phpbb\search\fulltext_native');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('search_type', '\phpbb\search\backend\fulltext_native');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('secure_allow_deny', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('secure_allow_empty_referer', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('secure_downloads', '0');

View file

@ -0,0 +1,39 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @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\db\migration\data\v330;
class search_backend_update extends \phpbb\db\migration\migration
{
public function update_data()
{
switch ($this->config['search_type'])
{
case '\\phpbb\\search\\fulltext_mysql':
$new_search_type = 'phpbb\\search\\backend\\fulltext_mysql';
break;
case '\\phpbb\\search\\fulltext_postgres':
$new_search_type = 'phpbb\\search\\backend\\fulltext_postgres';
break;
case '\\phpbb\\search\\fulltext_sphinx':
$new_search_type = 'phpbb\\search\\backend\\fulltext_sphinx';
break;
default:
$new_search_type = 'phpbb\\search\\backend\\fulltext_native';
}
return [
['config.update', ['search_type', $new_search_type]],
];
}
}

View file

@ -11,7 +11,7 @@
*
*/
namespace phpbb\search;
namespace phpbb\search\backend;
/**
* @ignore
@ -24,18 +24,12 @@ 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
abstract 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
*

View file

@ -11,12 +11,12 @@
*
*/
namespace phpbb\search;
namespace phpbb\search\backend;
/**
* Fulltext search for MySQL
*/
class fulltext_mysql extends \phpbb\search\base
class fulltext_mysql extends base implements search_backend_interface
{
/**
* Associative array holding index stats
@ -76,7 +76,7 @@ class fulltext_mysql extends \phpbb\search\base
/**
* Constructor
* Creates a new \phpbb\search\fulltext_mysql, which is used as a search backend
* Creates a new \phpbb\search\backend\fulltext_mysql, which is used as a search backend
*
* @param string|bool $error Any error that occurs is passed on through this reference variable otherwise false
* @param string $phpbb_root_path Relative path to phpBB root
@ -87,7 +87,7 @@ class fulltext_mysql extends \phpbb\search\base
* @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, $config, $db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx)
{
$this->config = $config;
$this->db = $db;
@ -103,14 +103,10 @@ class fulltext_mysql 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
* {@inheritdoc}
*/
public function get_name()
{
@ -118,9 +114,7 @@ class fulltext_mysql extends \phpbb\search\base
}
/**
* Returns the search_query
*
* @return string search query
* {@inheritdoc}
*/
public function get_search_query()
{
@ -128,9 +122,7 @@ class fulltext_mysql extends \phpbb\search\base
}
/**
* Returns the common_words array
*
* @return array common words that are ignored by search backend
* {@inheritdoc}
*/
public function get_common_words()
{
@ -138,9 +130,7 @@ class fulltext_mysql extends \phpbb\search\base
}
/**
* Returns the word_length array
*
* @return array min and max word length for searching
* {@inheritdoc}
*/
public function get_word_length()
{
@ -214,12 +204,7 @@ class fulltext_mysql extends \phpbb\search\base
}
/**
* 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
* {@inheritdoc}
*/
public function split_keywords(&$keywords, $terms)
{
@ -383,24 +368,7 @@ class fulltext_mysql 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
* {@inheritdoc}
*/
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)
{
@ -648,23 +616,7 @@ class fulltext_mysql 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
* {@inheritdoc}
*/
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)
{
@ -965,7 +917,7 @@ class fulltext_mysql extends \phpbb\search\base
}
/**
* Destroy cached results, that might be outdated after deleting a post
* {@inheritdoc}
*/
public function index_remove($post_ids, $author_ids, $forum_ids)
{
@ -973,7 +925,7 @@ class fulltext_mysql extends \phpbb\search\base
}
/**
* Destroy old cache entries
* {@inheritdoc}
*/
public function tidy()
{
@ -984,9 +936,7 @@ class fulltext_mysql extends \phpbb\search\base
}
/**
* Create fulltext index
*
* @return string|bool error string is returned incase of errors otherwise false
* {@inheritdoc}
*/
public function create_index($acp_module, $u_action)
{
@ -1058,9 +1008,7 @@ class fulltext_mysql extends \phpbb\search\base
}
/**
* Drop fulltext index
*
* @return string|bool error string is returned incase of errors otherwise false
* {@inheritdoc}
*/
public function delete_index($acp_module, $u_action)
{
@ -1126,7 +1074,7 @@ class fulltext_mysql extends \phpbb\search\base
}
/**
* Returns true if both FULLTEXT indexes exist
* {@inheritdoc}
*/
public function index_created()
{
@ -1139,7 +1087,7 @@ class fulltext_mysql extends \phpbb\search\base
}
/**
* Returns an associative array containing information about the indexes
* {@inheritdoc}
*/
public function index_stats()
{
@ -1195,9 +1143,7 @@ class fulltext_mysql extends \phpbb\search\base
}
/**
* Display a note, that UTF-8 support is not available with certain versions of PHP
*
* @return associative array containing template and config variables
* {@inheritdoc}
*/
public function acp()
{

View file

@ -11,12 +11,12 @@
*
*/
namespace phpbb\search;
namespace phpbb\search\backend;
/**
* 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";
@ -117,15 +117,16 @@ class fulltext_native extends \phpbb\search\base
* @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, $config, $db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx)
{
$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->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$this->word_length = array('min' => (int) $this->config['fulltext_native_min_chars'], 'max' => (int) $this->config['fulltext_native_max_chars']);
/**
@ -135,14 +136,10 @@ 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()
{
@ -150,9 +147,7 @@ class fulltext_native extends \phpbb\search\base
}
/**
* Returns the search_query
*
* @return string search query
* {@inheritdoc}
*/
public function get_search_query()
{
@ -160,9 +155,7 @@ class fulltext_native extends \phpbb\search\base
}
/**
* Returns the common_words array
*
* @return array common words that are ignored by search backend
* {@inheritdoc}
*/
public function get_common_words()
{
@ -170,9 +163,7 @@ class fulltext_native extends \phpbb\search\base
}
/**
* Returns the word_length array
*
* @return array min and max word length for searching
* {@inheritdoc}
*/
public function get_word_length()
{
@ -194,7 +185,7 @@ class fulltext_native extends \phpbb\search\base
* 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)
public function split_keywords(&$keywords, $terms)
{
$tokens = '+-|()* ';
@ -514,24 +505,7 @@ 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
* {@inheritdoc}
*/
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)
{
@ -1016,23 +990,7 @@ 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
* {@inheritdoc}
*/
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)
{
@ -1401,14 +1359,7 @@ class fulltext_native extends \phpbb\search\base
}
/**
* 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)
{
@ -1597,7 +1548,7 @@ class fulltext_native extends \phpbb\search\base
}
/**
* Removes entries from the wordmatch table for the specified post_ids
* {@inheritdoc}
*/
public function index_remove($post_ids, $author_ids, $forum_ids)
{
@ -1654,8 +1605,7 @@ class fulltext_native extends \phpbb\search\base
}
/**
* Tidy up indexes: Tag 'common words' and remove
* words no longer referenced in the match table
* {@inheritdoc}
*/
public function tidy()
{
@ -1718,7 +1668,7 @@ class fulltext_native extends \phpbb\search\base
}
/**
* Deletes all words from the index
* {@inheritdoc}
*/
public function delete_index($acp_module, $u_action)
{
@ -1762,7 +1712,7 @@ class fulltext_native extends \phpbb\search\base
}
/**
* Returns true if both FULLTEXT indexes exist
* {@inheritdoc}
*/
public function index_created()
{
@ -1775,7 +1725,7 @@ class fulltext_native extends \phpbb\search\base
}
/**
* Returns an associative array containing information about the indexes
* {@inheritdoc}
*/
public function index_stats()
{
@ -1789,6 +1739,9 @@ class fulltext_native extends \phpbb\search\base
$this->user->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);
@ -2032,7 +1985,7 @@ class fulltext_native extends \phpbb\search\base
}
/**
* Returns a list of options for the ACP to display
* {@inheritdoc}
*/
public function acp()
{

View file

@ -11,12 +11,12 @@
*
*/
namespace phpbb\search;
namespace phpbb\search\backend;
/**
* 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
@ -89,7 +89,7 @@ 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 string $phpbb_root_path Relative path to phpBB root
@ -100,7 +100,7 @@ class fulltext_postgres extends \phpbb\search\base
* @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, $config, $db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx)
{
$this->config = $config;
$this->db = $db;
@ -116,14 +116,10 @@ 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
* {@inheritdoc}
*/
public function get_name()
{
@ -131,9 +127,7 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
* Returns the search_query
*
* @return string search query
* {@inheritdoc}
*/
public function get_search_query()
{
@ -141,9 +135,7 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
* Returns the common_words array
*
* @return array common words that are ignored by search backend
* {@inheritdoc}
*/
public function get_common_words()
{
@ -151,9 +143,7 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
* Returns the word_length array
*
* @return array min and max word length for searching
* {@inheritdoc}
*/
public function get_word_length()
{
@ -186,12 +176,7 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
* 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
* {@inheritdoc}
*/
public function split_keywords(&$keywords, $terms)
{
@ -307,24 +292,7 @@ class fulltext_postgres 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
* {@inheritdoc}
*/
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)
{
@ -588,23 +556,7 @@ 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
* {@inheritdoc}
*/
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)
{
@ -927,7 +879,7 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
* Destroy cached results, that might be outdated after deleting a post
* {@inheritdoc}
*/
public function index_remove($post_ids, $author_ids, $forum_ids)
{
@ -935,7 +887,7 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
* Destroy old cache entries
* {@inheritdoc}
*/
public function tidy()
{
@ -946,9 +898,7 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
* Create fulltext index
*
* @return string|bool error string is returned incase of errors otherwise false
* {@inheritdoc}
*/
public function create_index($acp_module, $u_action)
{
@ -1007,9 +957,7 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
* Drop fulltext index
*
* @return string|bool error string is returned incase of errors otherwise false
* {@inheritdoc}
*/
public function delete_index($acp_module, $u_action)
{
@ -1068,7 +1016,7 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
* Returns true if both FULLTEXT indexes exist
* {@inheritdoc}
*/
public function index_created()
{
@ -1081,7 +1029,7 @@ class fulltext_postgres extends \phpbb\search\base
}
/**
* Returns an associative array containing information about the indexes
* {@inheritdoc}
*/
public function index_stats()
{
@ -1139,9 +1087,7 @@ 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
* {@inheritdoc}
*/
public function acp()
{

View file

@ -11,7 +11,7 @@
*
*/
namespace phpbb\search;
namespace phpbb\search\backend;
define('SPHINX_MAX_MATCHES', 20000);
define('SPHINX_CONNECT_RETRIES', 3);
@ -20,7 +20,7 @@ define('SPHINX_CONNECT_WAIT_TIME', 300);
/**
* Fulltext search based on the sphinx search daemon
*/
class fulltext_sphinx
class fulltext_sphinx implements search_backend_interface
{
/**
* Associative array holding index stats
@ -122,7 +122,7 @@ 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 string $phpbb_root_path Relative path to phpBB root
@ -133,15 +133,16 @@ class fulltext_sphinx
* @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, $config, $db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$this->auth = $auth;
$this->config = $config;
$this->db = $db;
$this->phpbb_dispatcher = $phpbb_dispatcher;
$this->user = $user;
$this->db = $db;
$this->auth = $auth;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
// Initialize \phpbb\db\tools\tools object
global $phpbb_container; // TODO inject into object
@ -163,14 +164,10 @@ 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
* {@inheritdoc}
*/
public function get_name()
{
@ -178,9 +175,7 @@ class fulltext_sphinx
}
/**
* Returns the search_query
*
* @return string search query
* {@inheritdoc}
*/
public function get_search_query()
{
@ -188,9 +183,7 @@ class fulltext_sphinx
}
/**
* Returns false as there is no word_len array
*
* @return false
* {@inheritdoc}
*/
public function get_word_length()
{
@ -198,9 +191,7 @@ class fulltext_sphinx
}
/**
* Returns an empty array as there are no common_words
*
* @return array common words that are ignored by search backend
* {@inheritdoc}
*/
public function get_common_words()
{
@ -426,12 +417,7 @@ class fulltext_sphinx
}
/**
* 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
* {@inheritdoc}
*/
public function split_keywords(&$keywords, $terms)
{
@ -521,24 +507,7 @@ class fulltext_sphinx
}
/**
* 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
* {@inheritdoc}
*/
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)
{
@ -780,23 +749,7 @@ 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
* {@inheritdoc}
*/
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)
{
@ -809,14 +762,7 @@ 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)
{
@ -882,7 +828,7 @@ class fulltext_sphinx
}
/**
* Delete a post from the index after it was deleted
* {@inheritdoc}
*/
public function index_remove($post_ids, $author_ids, $forum_ids)
{
@ -989,7 +935,7 @@ class fulltext_sphinx
}
/**
* 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()
{
@ -1012,9 +958,7 @@ class fulltext_sphinx
}
/**
* Returns a list of options for the ACP to display
*
* @return associative array containing template and config variables
* {@inheritdoc}
*/
public function acp()
{

View file

@ -0,0 +1,156 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @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();
/**
* Returns the search_query
*
* @return string search query
*/
public function get_search_query();
/**
* Returns the common_words array
*
* @return array common words that are ignored by search backend
*/
public function get_common_words();
/**
* Returns the word_length array
*
* @return array min and max word length for searching
*/
public function get_word_length();
//public function init();
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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 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);
/**
* Destroy cached results, that might be outdated after deleting a post
*/
public function index_remove($post_ids, $author_ids, $forum_ids);
/**
* Destroy old cache entries
*/
public function tidy();
/**
* Create fulltext index
*
* @return string|bool error string is returned incase of errors otherwise false
*/
// This method isn't present in fulltext_native, because it's implementation is hardcoded in acp_search
//public function create_index($acp_module, $u_action);
/**
* Drop fulltext index
*
* @return string|bool error string is returned incase of errors otherwise false
*/
public function delete_index($acp_module, $u_action);
/**
* Returns true if both FULLTEXT indexes exist
*/
public function index_created();
/**
* Returns an associative array containing information about the indexes
*
* @return array|bool Language string of error false otherwise
*/
public function index_stats();
/**
* Display various options that can be configured for the backend from the acp
*
* @return associative array containing template and config variables
*/
public function acp();
}

View file

@ -11,7 +11,7 @@
*
*/
namespace phpbb\search\sphinx;
namespace phpbb\search\backend\sphinx;
/**
* An object representing the sphinx configuration

View file

@ -11,7 +11,7 @@
*
*/
namespace phpbb\search\sphinx;
namespace phpbb\search\backend\sphinx;
/**
* \phpbb\search\sphinx\config_comment

View file

@ -11,7 +11,7 @@
*
*/
namespace phpbb\search\sphinx;
namespace phpbb\search\backend\sphinx;
/**
* \phpbb\search\sphinx\config_section

View file

@ -11,7 +11,7 @@
*
*/
namespace phpbb\search\sphinx;
namespace phpbb\search\backend\sphinx;
/**
* \phpbb\search\sphinx\config_variable

View file

@ -1,10 +0,0 @@
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</html>

View file

@ -0,0 +1,64 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @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;
class search_backend_factory
{
/**
* @var \phpbb\config\config
*/
protected $config;
/**
* @var \phpbb\di\service_collection
*/
protected $search_backends;
/**
* Constructor
*
* @param \phpbb\config\config $config
* @param \phpbb\di\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 \phpbb\search\backend\search_backend_interface
*/
public function get($class)
{
return $this->search_backends->get_by_class($class);
}
/**
* Obtains active search backend
*
* @return \phpbb\search\backend\search_backend_interface
*/
public function get_active()
{
return $this->get($this->config['search_type']);
}
}

View file

@ -294,20 +294,8 @@ 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))
{
trigger_error('NO_SUCH_SEARCH_MODULE');
}
// 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)
{
trigger_error($error);
}
$search_backend_factory = $phpbb_container->get('search.backend_factory');
$search = $search_backend_factory->get_search();
// let the search module split up the keywords
if ($keywords)

View file

@ -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.');

View file

@ -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)
{

View file

@ -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';
}

View file

@ -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';
}

View file

@ -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()
{

View file

@ -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();

View file

@ -13,15 +13,78 @@
/**
*/
class phpbb_mock_search
class phpbb_mock_search implements \phpbb\search\backend\search_backend_interface
{
public function __construct($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user)
public function __construct($auth, $config, $db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx)
{
}
public function index_remove($post_ids, $poster_ids, $forum_ids)
public function get_name()
{
}
public function get_search_query()
{
}
public function get_common_words()
{
}
public function get_word_length()
{
}
public function init()
{
}
public function split_keywords(&$keywords, $terms)
{
}
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)
{
}
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)
{
}
public function index($mode, $post_id, &$message, &$subject, $poster_id, $forum_id)
{
}
public function index_remove($post_ids, $author_ids, $forum_ids)
{
}
public function tidy()
{
}
public function create_index($acp_module, $u_action)
{
}
public function delete_index($acp_module, $u_action)
{
}
public function index_created()
{
}
public function index_stats()
{
}
protected function get_stats()
{
}
public function acp()
{
}
}

View file

@ -37,8 +37,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($auth, $config, $this->db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx);
}
}

View file

@ -33,11 +33,10 @@ class phpbb_search_native_test extends phpbb_search_test_case
$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($auth, $config, $this->db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx);
}
public function keywords()

View file

@ -37,8 +37,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($auth, $config, $this->db, $phpbb_dispatcher, $user, $phpbb_root_path, $phpEx);
}
}