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

<test>
<name>RT: ram vs disk chunk search</name>

<skip_indexer/>
<config>
searchd
{
	<searchd_settings/>
	workers = threads	
	binlog_path =
}

index rt0
{
    docinfo			= extern
    morphology		= none
    charset_type	= utf-8

	type			= rt

	rt_field		= title
	rt_field		= content
	rt_attr_uint	= id1
	rt_attr_uint	= id2
	
	path = <data_path/>/index
	rt_mem_limit      		= 128K
}
</config>

<db_drop>
drop table if exists rt0
</db_drop>
<db_create>
create table rt0
(
	id int not null,
	title varchar(255) not null,
	content varchar(255) not null,
	id1 int,
	id2 int
);
</db_create>
<db_insert>
insert into rt0 values
( 1000000, 'first title', 'first content',  1000000, 1000000 );
</db_insert>

<custom_test><![CDATA[

global $g_locals, $sd_address, $sd_sphinxql_port;
$results = array();
$sockStr = "$sd_address:$sd_sphinxql_port";
if ($sd_address == "localhost")
	$sockStr = "127.0.0.1:$sd_sphinxql_port";
$sock = @mysql_connect (
	$sockStr,
	$g_locals['db-user'],
	$g_locals['db-password'] ,
	true );

if ( $sock === false )
{
	$results[] = "error: can't connect to searchd: " . @mysql_errno ( $sock ) . " : " . @mysql_error ( $sock );
	return;
}

$errors = '';

mysql_query ( "INSERT INTO rt0 VALUES ( 1, 'submarine', 'submarine', 1001, 300001 )", $sock );

$lastID = 300;
$title = '';
$content = '';
for ( $i=2; $i<$lastID; $i++ )
{
	$title .= ' dusty' . $i;
	$content .= ' itsupposedtobeaverylongrecord' . $i;
	$id1 = $i + 1000;
	$id2 = $i + 300000;

	mysql_query ( "INSERT INTO rt0 VALUES ( $i, '$title', '$content', $id1, $id2 )", $sock );
	
	if ( $i % 50 == 0 )
	{
		$title = '';
		$content = '';
	}
}

$lastID = $lastID + 1;
mysql_query ( "INSERT INTO rt0 VALUES ( $lastID, 'submarine', 'submarine', 77, 77 )", $sock);
mysql_query ( "REPLACE INTO rt0 VALUES ( 1, 'submarine', 'submarine', 11, 11 )", $sock);

$queries = array ( "match('submarine')", "id=1" );
for ( $i=0; $i<count ( $queries ); $i++ )
{
	$q = "select * from rt0 where $queries[$i]";
	$res = @mysql_query ( $q, $sock );
	if ($res===true)
	{
		$results[] = "query $i: total_affected=" . mysql_affected_rows($sock);
	}
	else if ($res===false)
	{
		$results[] = "query $i: res=$res";
		$results[] = "error: query: " . @mysql_errno ( $sock ) . " : " . @mysql_error ( $sock );
		return;
	}
	else
	{
		$results[] = "query $i: total_rows=" . @mysql_num_rows($res) . " str=" . $queries[$i];
		while ($row = @mysql_fetch_array($res, MYSQL_ASSOC))
		{
			$foo = array();
			foreach ($row as $key => $value)
				$foo[$key] = $value;
			$results[] = $foo;
		}	
	}
}

@mysql_close($sock);

]]></custom_test>

</test>
