<?xml version="1.0" encoding="utf-8"?>
<test>

<name>sorting vs string</name>

<config>
indexer
{
	mem_limit		= 16M
}

searchd
{
	<searchd_settings/>
	workers = threads
}

source src
{
	type			= mysql
	<sql_settings/>

	sql_query		= SELECT id, idd1, str1, body FROM test_table
	sql_attr_uint	= idd1
	sql_attr_string	= str1
}

index plain
{
	source			= src
    docinfo			= extern
    charset_type	= sbcs
	path			= <data_path/>/plain
}

index rt
{
	type			= rt
    docinfo			= extern
    charset_type	= sbcs
	path			= <data_path/>/rt

	rt_attr_uint	= IDD1
	rt_attr_uint	= iDD2
	rt_attr_string	= Str1
	rt_attr_string	= Str2
	rt_field		= body
	
	rt_mem_limit	= 128K 
}

index dist
{
	type = distributed
	local = plain
	local = rt
}


</config>

<db_create>
CREATE TABLE `test_table`
(
	`id` int(11) NOT NULL default '0',
	`idd1` int(11) NOT NULL default '0',
	`idd2` int(11) NOT NULL default '0',
	`str1` varchar(1024) NOT NULL default '',
	`str2` varchar(1024) NOT NULL default '',
	`body` varchar(1024) NOT NULL default ''
)
</db_create>

<db_drop>
DROP TABLE IF EXISTS `test_table`
</db_drop>

<db_insert>
INSERT INTO `test_table` VALUES
( 1, 1, 9, 'aaa', 'h', 'the dog' ),
( 2, 11, 8, 'c cc', 'c', 'the cat' ),
( 3, 13, 7, 'a a', 'cc', 'the bird' ), 
( 4, 11, 6, 'cc', 'cc', 'cat eats bird' ),
( 5, 3, 5, 'cc', 'c', 'dog eats cat' ), 
( 6, 11, 4, 'ddd', 'hh', 'bird' ), 
( 7, 5, 4, 'a', 'cc', 'the' ),
( 8, 6, 4, '', 'cc', 'the' ),
( 9, 7, 4, 'a', '', 'the' )
</db_insert>

<sphqueries>
<sphinxql>insert into rt (id, Idd1, idd2, str1, str2, body) values ( 10, 5, 4, '', 'cc', 'the' )</sphinxql>
<sphinxql>insert into rt (id, idd1, IDD2, str1, str2, body) values ( 11, 5, 4, 'a', '', 'the' )</sphinxql>
<sphinxql>insert into rt (id, idd1, idd2, Str1, str2, body) values ( 12, 6, 4, 'a', 'cc', 'the' )</sphinxql>
<sphinxql>insert into rt (id, idd1, idd2, str1, STR2, body) values ( 13, 4, 4, 'ddd', 'hh', 'bird' )</sphinxql>
<sphinxql>insert into rt (id, idd1, idd2, str1, str2, Body) values ( 14, 3, 5, 'cc', 'c', 'dog eats cat' )</sphinxql>
<sphinxql>insert into rt (id, idd1, idd2, str1, str2, BODY) values ( 15, 2, 6, 'cc', 'cc', 'cat eats bird' )</sphinxql>
<sphinxql>insert into rt (id, idd1, idd2, str1, sTr2, body) values ( 16, 1, 7, 'a a', 'cc', 'the bird' )</sphinxql>
<sphinxql>insert into rt (id, idd1, idd2, stR1, str2, body) values ( 17, 1, 8, 'c cc', 'c', 'the cat' )</sphinxql>
<sphinxql>insert into rt (id, idd1, iDD2, str1, str2, body) values ( 18, 11, 9, 'aaa', 'h', 'the dog' )</sphinxql>

<sphinxql>select * from plain order by Str1 desc</sphinxql>
<sphinxql>select * from rt order by sTR1 desc</sphinxql>
<sphinxql>select * from rt order by STR2 asc, Str1 desc</sphinxql>
<sphinxql>select * from dist order by Str1 desc</sphinxql>
<sphinxql>select * from dist order by Str1 desc, IDD1 asc</sphinxql>
<sphinxql>select * from dist where match ('the') order by Str1 desc</sphinxql>
<sphinxql>select * from dist where match ('the') order by Str1 desc, iDD1 asc</sphinxql>
<sphinxql>select * from dist where match ('cat | eats') order by Str1 asc</sphinxql>
<sphinxql>select * from dist where match ('cat | eats') order by Str1 asc, sTr2 desc</sphinxql>
<sphinxql>select * from dist where match ('cat | eats') order by Str1 asc, Idd1 asc</sphinxql>
<!-- regression missed string pool in grouper on match -->
<sphinxql>select * from dist where match ('cat | eats') group by str1 within group order by id desc</sphinxql>
<sphinxql>select * from dist group by str2  within group order by id desc</sphinxql>
<!-- regression sorter gives first matches instead bests -->
<sphinxql>select id, str1 from rt group by idd1 order by id asc limit 0,2 option max_matches=2</sphinxql>
<sphinxql>select id, str1 from rt group by idd1 order by id asc limit 2,2 option max_matches=4</sphinxql>
</sphqueries>

</test>
