mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[feature/sphinx-fulltext-search] modify config class
Sphinx config class is modified to return the configuration data instead of writing it to a file. Search backend property config_file_data stores the generated data. PHPBB3-10946
This commit is contained in:
parent
01261179ce
commit
f0692bb9e8
2 changed files with 146 additions and 159 deletions
|
@ -45,6 +45,7 @@ class phpbb_search_fulltext_sphinx
|
|||
private $db;
|
||||
private $db_tools;
|
||||
private $user;
|
||||
private $config_file_data = '';
|
||||
public $word_length = array();
|
||||
public $search_query;
|
||||
public $common_words = array();
|
||||
|
@ -138,7 +139,7 @@ class phpbb_search_fulltext_sphinx
|
|||
/* Now that we're sure everything was entered correctly,
|
||||
generate a config for the index. We misuse the avatar_salt
|
||||
for this, as it should be unique. */
|
||||
$config_object = new phpbb_search_sphinx_config($this->config['fulltext_sphinx_config_path'] . 'sphinx.conf');
|
||||
$config_object = new phpbb_search_sphinx_config($this->config_file_data);
|
||||
|
||||
$config_data = array(
|
||||
'source source_phpbb_' . $this->id . '_main' => array(
|
||||
|
@ -236,7 +237,6 @@ class phpbb_search_fulltext_sphinx
|
|||
|
||||
$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);
|
||||
|
||||
foreach ($config_data as $section_name => $section_data)
|
||||
{
|
||||
$section = $config_object->get_section_by_name($section_name);
|
||||
|
@ -278,6 +278,7 @@ class phpbb_search_fulltext_sphinx
|
|||
}
|
||||
}
|
||||
}
|
||||
$this->config_file_data = $config_object->get_data();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -27,15 +27,15 @@ class phpbb_search_sphinx_config
|
|||
var $sections = array();
|
||||
|
||||
/**
|
||||
* Constructor which optionally loads data from a file
|
||||
* Constructor which optionally loads data from a variable
|
||||
*
|
||||
* @param string $filename The path to a file containing the sphinx configuration
|
||||
* @param string $config_data Variable containing the sphinx configuration data
|
||||
*/
|
||||
function __construct($filename = false)
|
||||
function __construct($config_data)
|
||||
{
|
||||
if ($filename !== false && file_exists($filename))
|
||||
if ($config_data != '')
|
||||
{
|
||||
$this->read($filename);
|
||||
$this->read($config_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,22 +70,19 @@ class phpbb_search_sphinx_config
|
|||
}
|
||||
|
||||
/**
|
||||
* Parses the config file at the given path, which is stored in $this->loaded for later use
|
||||
* Reads the config file data
|
||||
*
|
||||
* @param string $filename The path to the config file
|
||||
* @param string $config_data The config file data
|
||||
*/
|
||||
function read($filename)
|
||||
function read($config_data)
|
||||
{
|
||||
// Split the file into lines, we'll process it line by line
|
||||
$config_file = file($filename);
|
||||
|
||||
$this->sections = array();
|
||||
|
||||
$section = null;
|
||||
$found_opening_bracket = false;
|
||||
$in_value = false;
|
||||
|
||||
foreach ($config_file as $i => $line)
|
||||
foreach ($config_data as $i => $line)
|
||||
{
|
||||
/* If the value of a variable continues to the next line because the line
|
||||
break was escaped then we don't trim leading space but treat it as a part of the value */
|
||||
|
@ -262,32 +259,21 @@ class phpbb_search_sphinx_config
|
|||
}
|
||||
}
|
||||
|
||||
// Keep the filename for later use
|
||||
$this->loaded = $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the config data into a file
|
||||
* Returns the config data
|
||||
*
|
||||
* @param string $filename The optional filename into which the config data shall be written.
|
||||
* If it's not specified it will be written into the file that the config
|
||||
* was originally read from.
|
||||
* @return string $data The config data that is generated.
|
||||
*/
|
||||
function write($filename = false)
|
||||
function get_data()
|
||||
{
|
||||
if ($filename === false && $this->loaded)
|
||||
{
|
||||
$filename = $this->loaded;
|
||||
}
|
||||
|
||||
$data = "";
|
||||
foreach ($this->sections as $section)
|
||||
{
|
||||
$data .= $section->to_string();
|
||||
}
|
||||
|
||||
$fp = fopen($filename, 'wb');
|
||||
fwrite($fp, $data);
|
||||
fclose($fp);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue