diff options
author | Sergei Golubchik <sergii@pisem.net> | 2010-09-12 14:33:04 +0200 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2010-09-12 14:33:04 +0200 |
commit | 2bcc58acf55356a76d74163c1320cb18bada63fe (patch) | |
tree | e94fdb4a1633ae8ac0a624f6c724d6aa55f94d25 | |
parent | e03e3b8187aad86110cb32e7279a3732553501a0 (diff) | |
download | mariadb-git-2bcc58acf55356a76d74163c1320cb18bada63fe.tar.gz |
add sphinx suite
-rw-r--r-- | mysql-test/Makefile.am | 2 | ||||
-rwxr-xr-x | mysql-test/mysql-test-run.pl | 2 | ||||
-rw-r--r-- | mysql-test/suite/sphinx/my.cnf | 33 | ||||
-rw-r--r-- | mysql-test/suite/sphinx/sphinx.result | 39 | ||||
-rw-r--r-- | mysql-test/suite/sphinx/sphinx.test | 23 | ||||
-rw-r--r-- | mysql-test/suite/sphinx/suite.pm | 119 | ||||
-rw-r--r-- | mysql-test/suite/sphinx/testdata.xml | 35 |
7 files changed, 251 insertions, 2 deletions
diff --git a/mysql-test/Makefile.am b/mysql-test/Makefile.am index e133a4648a1..e565521a8b0 100644 --- a/mysql-test/Makefile.am +++ b/mysql-test/Makefile.am @@ -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 \ diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 3f37fc5f285..3279c9a0089 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -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 diff --git a/mysql-test/suite/sphinx/my.cnf b/mysql-test/suite/sphinx/my.cnf new file mode 100644 index 00000000000..78e5cad6894 --- /dev/null +++ b/mysql-test/suite/sphinx/my.cnf @@ -0,0 +1,33 @@ +!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 diff --git a/mysql-test/suite/sphinx/sphinx.result b/mysql-test/suite/sphinx/sphinx.result new file mode 100644 index 00000000000..46fefc6f8ae --- /dev/null +++ b/mysql-test/suite/sphinx/sphinx.result @@ -0,0 +1,39 @@ +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; diff --git a/mysql-test/suite/sphinx/sphinx.test b/mysql-test/suite/sphinx/sphinx.test new file mode 100644 index 00000000000..f6d2c7ac709 --- /dev/null +++ b/mysql-test/suite/sphinx/sphinx.test @@ -0,0 +1,23 @@ + +--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; + diff --git a/mysql-test/suite/sphinx/suite.pm b/mysql-test/suite/sphinx/suite.pm new file mode 100644 index 00000000000..ee5c3941b63 --- /dev/null +++ b/mysql-test/suite/sphinx/suite.pm @@ -0,0 +1,119 @@ +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 { }; + diff --git a/mysql-test/suite/sphinx/testdata.xml b/mysql-test/suite/sphinx/testdata.xml new file mode 100644 index 00000000000..e0d7394190f --- /dev/null +++ b/mysql-test/suite/sphinx/testdata.xml @@ -0,0 +1,35 @@ +<?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> + |