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.
This module is being released as version 1.02.
use Sphinx::Config::Builder; my $INDEXPATH = q{/path/to/indexes}; my $XMLPATH = q{/path/to/xmlpipe2/output}; my $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->kv_push( { type => q{xmlpipe} }, { xmlpipe_command => qq{/bin/cat $XMLPATH/$xmlfile} }, ); $builder->push_source($src); $index->name($index_name); $index->kv_push( { source => qq{$source_name} }, { path => qq{$INDEXPATH/$document_set} }, { charset_type => q{utf-8} }, ); $builder->push_index($index); } } $builder->indexer->kv_push( { mem_limit => q{64m} } ); $builder->searchd->kv_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:
--config
$ indexer --config /path/to/gen_config.pl --all --rotate
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.
searchd
Sphinx::Config::Builder
.ini
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:
Sphinx::Config::Entry::Index
index
Sphinx::Config::Entry::Source
source
Sphinx::Config::Entry::Indexer
indexer
Sphinx::Config::Entry::Searchd
The general idea is that one builds up a list of index sections and corresponding source sections. One then defines the indexer and searchd options. One is not bound to specific keywords in each section, meaning that they may add any key/value pair (as a singleton HASH referece). Each key/value pair corresponds to a key/value line in each section.
HASH
All Sphinx::Config::Entry derived classes implement a as_string method. This method outputs the section in the format that Sphinx expects. The overall Sphinx::Config::Builder class has a as_string method that will iterate over all members, calling their as_string method. The result is the full configuration file that may be printed to STDOUT for the indexer to consume using the --config option.
Sphinx::Config::Entry
as_string
new
Highest level constructor.
push_index
Push a reference of Sphinx::Config::Entry::Index into builder.
pop_index
Pop a reference of Sphinx::Config::Entry::Index into builder.
push_source
Push a reference of Sphinx::Config::Entry::Source into builder.
pop_source
Pop a reference of Sphinx::Config::Entry::Source into builder.
index_list
Get container list of all Index references.
source_list
Get container list of all Source references.
Get Sphinx::Config::Entry::Indexer member reference.
sourced
Get Sphinx::Config::Entry::Searchd member reference.
Calls as_string method for all members of the builder object, which results in the entire configuration file.
Constructor.
kv_push
Push key/value HASH ref into Index, Source list.
kv_pop
Pop key/value HASH ref from Index, Source list.
Return string reprentation of Index, Source.
name
Set name of Index, Source.
Push key/value HASH ref into Indexer, Searchd.
Pop key/value HASH ref from Indexer, Searchd.
Return string representation of Indexer, Searchd.
None.
There is no validation, garbage in, garbage out.
Please report - https://github.com/estrabd/perl-Sphinx-Config-Builder/issues
B. Estrade, <estrabd@gmail.com>
Same terms as Perl itself.
To install Sphinx::Config::Builder, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sphinx::Config::Builder
CPAN shell
perl -MCPAN -e shell install Sphinx::Config::Builder
For more information on module installation, please visit the detailed CPAN module installation guide.