<?php
function fn_findrel_c($aql)
{
	$data = $aql->Consume(1);
	
	$rels = Relationships::GetAllRelationships();
	
	$propshortlist = array();	
	$bing = array();
	
	$allprops = Properties::GetAllProperties();
	if ($data[0]->islist == true)
		$propset = $data[0]->value;
	else
		$propset = array($data[0]->value);
	
	$targetscore = count($propset);
	
	foreach($rels as $pr)
	{
		$bing[$pr->id] = 0;
		foreach($propset as $psx)
		{			
			if (strpos(strtolower($pr->name),$psx) !== FALSE)
			{
				//echo $psx.' hit on '.$pr->name.'<br/>';
				$bing[$pr->id]++;
			}
		}
	}
	
	foreach($bing as $k => $v)
	{
		if ($v == $targetscore)
		{
			$propid = $k;			
			$propshortlist[] = $k;
		}
	}	
	
	$a = new AQLStackElement();
	$a->typename = "const";
	$a->islist = true;
	if (count($propshortlist) > 0)
		$a->value = $propshortlist[0];
	else
		$a->value = 0;
	
	array_push($aql->stack,$a);
	
	//echo "Found ...";
	//print_r($propshortlist);
	return;
}
?>