Commit 2bcc58ac authored by Sergei Golubchik's avatar Sergei Golubchik

add sphinx suite

parent e03e3b81
......@@ -87,7 +87,7 @@ TEST_DIRS = t r include std_data std_data/parts collections \
suite/pbxt/t suite/pbxt/r suite/pbxt \
suite/vcol suite/vcol/t suite/vcol/r suite/vcol/inc \
suite/oqgraph suite/oqgraph/t suite/oqgraph/r suite/oqgraph/include \
suite/percona \
suite/percona suite/sphinx \
suite/funcs_1 suite/funcs_1/bitdata \
suite/funcs_1/include suite/funcs_1/lib suite/funcs_1/r \
suite/funcs_1/t suite/funcs_1/views suite/funcs_1/cursors \
......
......@@ -130,7 +130,7 @@ my $path_config_file; # The generated config file, var/my.cnf
# executables will be used by the test suite.
our $opt_vs_config = $ENV{'MTR_VS_CONFIG'};
my $DEFAULT_SUITES= "main,binlog,federated,rpl,maria,parts,innodb,innodb_plugin,percona,vcol,oqgraph,ndb";
my $DEFAULT_SUITES= "main,binlog,federated,rpl,maria,parts,innodb,innodb_plugin,percona,ndb,vcol,oqgraph,sphinx";
my $opt_suites;
our $opt_verbose= 0; # Verbose output, enable with --verbose
......
!include include/default_my.cnf
[mysqld.1]
plugin-load=@ENV.HA_SPHINX_SO
[source src1]
type = xmlpipe2
xmlpipe_command = cat suite/sphinx/testdata.xml
[index test1]
source = src1
docinfo = extern
charset_type = utf-8
path = @OPT.vardir/searchd/test1
[indexer]
mem_limit = 32M
[searchd]
read_timeout = 5
max_children = 30
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
log = @OPT.vardir/searchd/sphinx-searchd.log
query_log = @OPT.vardir/searchd/sphinx-query.log
#log-error = @OPT.vardir/searchd/sphinx.log
pid_file = @OPT.vardir/run/searchd.pid
port = @ENV.SPHINXSEARCH_PORT
[ENV]
SPHINXSEARCH_PORT = @OPT.port
create table ts ( id bigint unsigned not null, w int not null, q varchar(255) not null, index(q) ) engine=sphinx connection="sphinx://127.0.0.1:SPHINXSEARCH_PORT/*";
select * from ts where q='test';
id w q
1 2 test
2 2 test
4 1 test
drop table ts;
create table ts ( id bigint unsigned not null, w int not null, q varchar(255) not null, index(q) ) engine=sphinx connection="sphinx://127.0.0.1:SPHINXSEARCH_PORT/*";
select * from ts where q='test;filter=gid,1;mode=extended';
id w q
1 2421 test;filter=gid,1;mode=extended
2 2421 test;filter=gid,1;mode=extended
select * from ts where q='test|one;mode=extended';
id w q
1 3595 test|one;mode=extended
2 2460 test|one;mode=extended
4 1471 test|one;mode=extended
select * from ts where q='test;offset=1;limit=1';
id w q
2 2 test;offset=1;limit=1
alter table ts connection="sphinx://127.0.0.1:SPHINXSEARCH_PORT/test1";
select id, w from ts where q='one';
id w
1 2
drop table ts;
create table ts ( id bigint unsigned not null, w int not null, q varchar(255) not null, gid int not null, _sph_count int not null, index(q) ) engine=sphinx connection="sphinx://127.0.0.1:SPHINXSEARCH_PORT/test1";
select * from ts;
id w q gid _sph_count
select * from ts where q='';
id w q gid _sph_count
1 1 1 0
2 1 1 0
3 1 2 0
4 1 2 0
select * from ts where q=';groupby=attr:gid';
id w q gid _sph_count
3 1 ;groupby=attr:gid 2 2
1 1 ;groupby=attr:gid 1 2
drop table ts;
--replace_result $SPHINXSEARCH_PORT SPHINXSEARCH_PORT
eval create table ts ( id bigint unsigned not null, w int not null, q varchar(255) not null, index(q) ) engine=sphinx connection="sphinx://127.0.0.1:$SPHINXSEARCH_PORT/*";
select * from ts where q='test';
drop table ts;
--replace_result $SPHINXSEARCH_PORT SPHINXSEARCH_PORT
eval create table ts ( id bigint unsigned not null, w int not null, q varchar(255) not null, index(q) ) engine=sphinx connection="sphinx://127.0.0.1:$SPHINXSEARCH_PORT/*";
select * from ts where q='test;filter=gid,1;mode=extended';
select * from ts where q='test|one;mode=extended';
select * from ts where q='test;offset=1;limit=1';
--replace_result $SPHINXSEARCH_PORT SPHINXSEARCH_PORT
eval alter table ts connection="sphinx://127.0.0.1:$SPHINXSEARCH_PORT/test1";
select id, w from ts where q='one';
drop table ts;
--replace_result $SPHINXSEARCH_PORT SPHINXSEARCH_PORT
eval create table ts ( id bigint unsigned not null, w int not null, q varchar(255) not null, gid int not null, _sph_count int not null, index(q) ) engine=sphinx connection="sphinx://127.0.0.1:$SPHINXSEARCH_PORT/test1";
select * from ts;
select * from ts where q='';
select * from ts where q=';groupby=attr:gid';
drop table ts;
package My::Suite::Sphinx;
use My::SafeProcess;
use My::File::Path;
use mtr_report;
@ISA = qw(My::Suite);
use Carp;
$Carp::Verbose=1;
############# initialization ######################
sub locate_sphinx_binary {
my ($name)= @_;
my $res;
my @list= map "$_/$name", split /:/, $ENV{PATH};
my $env_override= $ENV{"SPHINXSEARCH_\U$name"};
@list= ($env_override) if $env_override;
for (@list) { return $_ if -x $_; }
}
# Look for Sphinx binaries.
my $exe_sphinx_indexer = &locate_sphinx_binary('indexer');
my $exe_sphinx_searchd = &locate_sphinx_binary('searchd');
return "No Sphinx" unless $exe_sphinx_indexer and $exe_sphinx_searchd;
return "No SphinxSE" unless $ENV{HA_SPHINX_SO};
{
local $_ = `"$exe_sphinx_searchd" --help`;
my $ver = sprintf "%04d.%04d.%04d", (/([0-9]+)\.([0-9]+)\.([0-9]+)/);
return "Sphinx 0.9.9 or later is needed" unless $ver ge '0000.0009.0009';
}
############# action methods ######################
sub write_sphinx_conf {
my ($config) = @_; # My::Config
my $res;
foreach my $group ($config->groups()) {
my $name= $group->{name};
# Only the ones relevant to Sphinx search.
next unless ($name eq 'indexer' or $name eq 'searchd' or
$name =~ /^(source|index) \w+$/);
$res .= "$name\n{\n";
foreach my $option ($group->options()) {
$res .= $option->name();
my $value= $option->value();
if (defined $value) {
$res .= "=$value";
}
$res .= "\n";
}
$res .= "}\n\n";
}
$res;
}
sub searchd_start {
my ($sphinx, $test) = @_; # My::Config::Group, My::Test
return unless $exe_sphinx_indexer and $exe_sphinx_searchd;
# First we must run the indexer to create the data.
my $sphinx_data_dir= "$::opt_vardir/" . $sphinx->name();
mkpath($sphinx_data_dir);
my $sphinx_log= $sphinx->value('#log-error');
my $sphinx_config= "$::opt_vardir/my_sphinx.conf";
my $cmd= "\"$exe_sphinx_indexer\" --config \"$sphinx_config\" test1 > \"$sphinx_log\" 2>&1";
&::mtr_verbose("cmd: $cmd");
system $cmd;
# Then start the searchd daemon.
my $args;
&::mtr_init_args(\$args);
&::mtr_add_arg($args, "--config");
&::mtr_add_arg($args, $sphinx_config);
&::mtr_add_arg($args, "--console");
&::mtr_add_arg($args, "--pidfile");
$sphinx->{'proc'}= My::SafeProcess->new
(
name => 'sphinx-' . $sphinx->name(),
path => $exe_sphinx_searchd,
args => \$args,
output => $sphinx_log,
error => $sphinx_log,
append => 1,
nocore => 1,
);
&::mtr_verbose("Started $sphinx->{proc}");
}
sub searchd_wait {
my ($sphinx) = @_; # My::Config::Group
return not &::sleep_until_file_created($sphinx->value('pid_file'), 20,
$sphinx->{'proc'})
}
############# declaration methods ######################
sub config_files() {
( 'my_sphinx.conf' => \&write_sphinx_conf )
}
sub servers {
( qr/^searchd$/ => {
SORT => 400,
START => \&searchd_start,
WAIT => \&searchd_wait,
}
)
}
############# return an object ######################
bless { };
<?xml version="1.0" encoding="utf-8"?>
<sphinx:docset>
<sphinx:schema>
<sphinx:field name="title"/>
<sphinx:field name="content"/>
<sphinx:attr name="gid" type="int"/>
</sphinx:schema>
<sphinx:document id="1">
<title>test one</title>
<content>this is my test document number one. also checking search within phrases.</content>
<gid>1</gid>
</sphinx:document>
<sphinx:document id="2">
<title>test two</title>
<content>this is my test document number two</content>
<gid>1</gid>
</sphinx:document>
<sphinx:document id="3">
<title>another doc</title>
<content>this is another group</content>
<gid>2</gid>
</sphinx:document>
<sphinx:document id="4">
<title>doc number four</title>
<content>this is to test groups</content>
<gid>2</gid>
</sphinx:document>
</sphinx:docset>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment