NAME
Sphinx::Config::Builder - Perl extension dynamically creating Sphinx configuration files on the fly, using a backend datasource to drive the indexes, sources, and their relationships.
VERSION
This module is being released as version 1.00.
SYNOPSIS
use Sphinx::Config::Builder;
my $INDEXPATH = q{/path/to/indexes};
my $XMLPATH = q{/path/to/xmlpipe2/output};
$builder = Sphinx::Config::Builder->new();
# %categories may be stored elsewhere, e.g. a .ini file or MySQL database
my $categories = { cars => [qw/sedan truck ragtop/], boats => [qw/sail row motor/] };
foreach my $category ( keys %$categories ) {
foreach my $document_set ( @{ $categories->{$category} } ) {
my $xmlfile = qq{$document_set-$category} . q{.xml};
my $source_name = qq{$document_set-$category} . q{_xml};
my $index_name = qq{$document_set-$category};
my $src = Sphinx::Config::Entry::Source->new();
my $index = Sphinx::Config::Entry::Index->new();
$src->name($source_name);
$src->push(
{ type => q{xmlpipe} },
{ xmlpipe_command => qq{/bin/cat $XMLPATH/$xmlfile} },
);
$builder->push_source($src);
$index->name($index_name);
$index->push(
{ source => qq{$source_name} },
{ path => qq{$INDEXPATH/$document_set} },
{ charset_type => q{utf-8} },
);
$builder->push_index($index);
}
}
$builder->indexer->push( { mem_limit => q{64m} } );
$builder->searchd->push(
{ compat_sphinxql_magics => 0 },
{ listen => q{192.168.0.41:9312} },
{ listen => q{192.168.0.41:9306:mysql41} },
{ log => q{/var/log/sphinx/searchd.log} },
{ query_log => q{/var/log/sphinx/log/query.log} },
{ read_timeout => 30 },
{ max_children => 30 },
{ pid_file => q{/var/log/sphinx/searchd.pid} },
{ seamless_rotate => 1 },
{ preopen_indexes => 1 },
{ unlink_old => 1 },
{ workers => q{threads} }, # for RT to work
{ binlog_path => q{/var/log/sphinx} },
);
print $builder->as_string;
This script may now be passed to the Sphinx indexer using the --config
option:
$ indexer --config /path/to/gen_config.pl --all --rotate
DESCRIPTION
The motivation behind this module is the need to manage many indexes and corresponding sources handled by a single Sphinx searchd
instance. Managing a configuration file with many indexes and sources quickly becomes unweildy, and a programatic solution is necessary. Using Sphinx::Config::Builder
, one may more easily manage Sphinx configurations using a more appropriate backend (e.g., a simple .ini
file or even a MySQL database). This is particularly useful if one is frequently adding or deleting indexes and sources. This approach is particularly useful for managing non-natively supported Sphinx datasources that might require the additional step of generating XMLPipe/Pipe2 sources.
This module doesn't read in Sphinx configuration files, it simply allows one to construct and output a configuration file programmtically.
This module allows one to systematically construct a Sphinx configuration file that contains so many entries that it is best created dynamically. It's fairly low level, and provides containers for the following:
- A list of
Sphinx::Config::Entry::Index
objects, one perindex
section; - A list of
Sphinx::Config::Entry::Source
objects, one persource
section; - A singular
Sphinx::Config::Entry::Indexer
object, one per configuration forindexer
options - A singular
Sphinx::Config::Entry::Searchd
object, one per configuration forsearchd
options -
The general idea is that one builds up a list of
index
sections and correspondingsource
sections. One then defines theindexer
andsearchd
options. One is not bound to specific keywords in each section, meaning that they may add any key/value pair (as a singletonHASH
referece). Each key/value pair corresponds to a key/value line in each section.All
Sphinx::Config::Entry
derived classes implement aas_string
method. This method outputs the section in the format that Sphinx expects. The overallSphinx::Config::Builder
class has aas_string
method that will iterate over all members, calling theiras_string
method. The result is the full configuration file that may be printed to STDOUT for theindexer
to consume using the--config
option.
SUBROUTINES/METHODS
DEPENDENCIES
None.
DIAGNOSTICS
None.
CONFIGURATION AND ENVIRONMENT
None.
INCOMPATIBILITIES
None.
BUGS AND LIMITATIONS
Please report - https://github.com/estrabd/perl-Sphinx-Config-Builder/issues
AUTHOR
B. Estrade, <estrabd@gmail.com<gt>
LICENSE AND COPYRIGHT
Same terms as Perl itself.