<commit_before><?php
/**
 * @package api
 * @subpackage filters
 */
class MetadataSearchFilter extends AdvancedSearchFilterOperator
{
	const KMC_FIELD_TYPE_TEXT = 'textType';
	const KMC_FIELD_TYPE_LIST = 'listType';
	const KMC_FIELD_TYPE_DATE = 'dateType';
	const KMC_FIELD_TYPE_INT = 'intType';
	const KMC_FIELD_TYPE_OBJECT = 'objectType';
	 
	/**
	 * @var string
	 */
	protected $condition = null;
	
	/**
	 * @var string
	 */
	protected $orderBy = null;
	
	/**
	 * @var int
	 */
	protected $metadataProfileId;
	
	public function setMetadataProfileId($metadataProfileId)
	{
		$this->metadataProfileId = $metadataProfileId;
	}
	
	public function getMetadataProfileId()
	{
		return $this->metadataProfileId;
	}
	
	public function setOrderBy($orderBy)
	{
		$this->orderBy = $orderBy;
	}
	
	public function getOrderBy()
	{
		return $this->orderBy;
	}
	
/*	public function getCondition()
	{
		throw new Exception("get condition is not in use!");
		return $this->doGetCondition();
	}
	*/
	public function applyCondition(array &$whereClause, array &$conditionClause, $xPaths = null)
	{		
		if($this->condition)
			return $this->condition;
			
		if(is_null($xPaths))
		{
			$xPaths = array();
			$profileFields = MetadataProfileFieldPeer::retrieveActiveByMetadataProfileId($this->metadataProfileId);
			foreach($profileFields as $profileField)
				$xPaths[$profileField->getXpath()] = $profileField;
		}

		$dataConditions = array();
		$subConditions = array();
		$pluginName = MetadataPlugin::PLUGIN_NAME;
		
		if(count($this->items))
		{
			foreach($this->items as $item)
			{
				$dataCondition = null;
				
				if ($item instanceof AdvancedSearchFilterComparableCondition){
					/* @var $item AdvancedSearchFilterComparableCondition  */
					$field = $item->getField();
					if(!isset($xPaths[$field])){
						KalturaLog::ERR("Missing field: $field in xpath array: " . print_r($xPaths,true));
						continue;
					}
						
					switch ($item->getComparison()){
						case KalturaSearchConditionComparison::EQUEL:
							$comparison = ' = ';
							break;
						case KalturaSearchConditionComparison::GREATER_THAN:
							$comparison = ' > ';
							break;
						case KalturaSearchConditionComparison::GREATER_THAN_OR_EQUEL:
							$comparison = ' >= ';
							break;
						case KalturaSearchConditionComparison::LESS_THAN:
							$comparison = " < ";
							break;
						case KalturaSearchConditionComparison::LESS_THAN_OR_EQUEL:
							$comparison = " <= ";
							break;
						default:
							KalturaLog::ERR("Missing comparison type");
							continue;
					}
										
					$metadataField = $this->getMetadataSearchField($field, $xPaths);
					if (!$metadataField){
						KalturaLog::ERR("Missing metadataField for $field in xpath array: " . print_r($xPaths,true));
						continue;
					}
									
					$this->conditionClause[] = $metadataField . $comparison . $item->getValue();
				}
				elseif ($item instanceof AdvancedSearchFilterCondition)
				{
					$field = $item->getField();
					if(!isset($xPaths[$field])){
						KalturaLog::ERR("Missing field: $field in xpath array: " . print_r($xPaths,true));
						continue;
					}
					
					$value = $item->getValue();
					$value = SphinxUtils::escapeString($value);
					$fieldId = $xPaths[$field]->getId();
					$dataCondition = "\"{$pluginName}_{$fieldId} $value " . kMetadataManager::SEARCH_TEXT_SUFFIX . "\"";
					kalturalog::debug("add $dataCondition");
					$dataConditions[] = "( $dataCondition )";
				}
				elseif($item instanceof MetadataSearchFilter)
				{
					$subConditions[] = $item->applyCondition($this->whereClause, $this->conditionClause, $xPaths);
				}					
			}
		}	
			
		if (count($dataConditions)){
			$metadataConditions = array();
			$glue = ($this->type == MetadataSearchFilter::SEARCH_AND ? ' ' : ' | ');
			$dataConditions = array_unique($dataConditions);
			$metadataConditions['@'. $this->getMetadataSearchField()] = implode($glue, $dataConditions);
			$this->condition = $this->appendToDataCondition($this->condition, $metadataConditions, $this->type);<commit_msg>qnd: fixed text search list Vs. text<commit_after><?php
/**
 * @package api
 * @subpackage filters
 */
class MetadataSearchFilter extends AdvancedSearchFilterOperator
{
	const KMC_FIELD_TYPE_TEXT = 'textType';
	const KMC_FIELD_TYPE_LIST = 'listType';
	const KMC_FIELD_TYPE_DATE = 'dateType';
	const KMC_FIELD_TYPE_INT = 'intType';
	const KMC_FIELD_TYPE_OBJECT = 'objectType';
	 
	/**
	 * @var string
	 */
	protected $condition = null;
	
	/**
	 * @var string
	 */
	protected $orderBy = null;
	
	/**
	 * @var int
	 */
	protected $metadataProfileId;
	
	public function setMetadataProfileId($metadataProfileId)
	{
		$this->metadataProfileId = $metadataProfileId;
	}
	
	public function getMetadataProfileId()
	{
		return $this->metadataProfileId;
	}
	
	public function setOrderBy($orderBy)
	{
		$this->orderBy = $orderBy;
	}
	
	public function getOrderBy()
	{
		return $this->orderBy;
	}
	
/*	public function getCondition()
	{
		throw new Exception("get condition is not in use!");
		return $this->doGetCondition();
	}
	*/
	public function applyCondition(array &$whereClause, array &$conditionClause, $xPaths = null)
	{		
		if($this->condition)
			return $this->condition;
			
		if(is_null($xPaths))
		{
			$xPaths = array();
			$profileFields = MetadataProfileFieldPeer::retrieveActiveByMetadataProfileId($this->metadataProfileId);
			foreach($profileFields as $profileField)
				$xPaths[$profileField->getXpath()] = $profileField;
		}

		$dataConditions = array();
		$subConditions = array();
		$pluginName = MetadataPlugin::PLUGIN_NAME;
		
		if(count($this->items))
		{
			foreach($this->items as $item)
			{
				$dataCondition = null;
				
				if ($item instanceof AdvancedSearchFilterComparableCondition){
					/* @var $item AdvancedSearchFilterComparableCondition  */
					$field = $item->getField();
					if(!isset($xPaths[$field])){
						KalturaLog::ERR("Missing field: $field in xpath array: " . print_r($xPaths,true));
						continue;
					}
						
					switch ($item->getComparison()){
						case KalturaSearchConditionComparison::EQUEL:
							$comparison = ' = ';
							break;
						case KalturaSearchConditionComparison::GREATER_THAN:
							$comparison = ' > ';
							break;
						case KalturaSearchConditionComparison::GREATER_THAN_OR_EQUEL:
							$comparison = ' >= ';
							break;
						case KalturaSearchConditionComparison::LESS_THAN:
							$comparison = " < ";
							break;
						case KalturaSearchConditionComparison::LESS_THAN_OR_EQUEL:
							$comparison = " <= ";
							break;
						default:
							KalturaLog::ERR("Missing comparison type");
							continue;
					}
										
					$metadataField = $this->getMetadataSearchField($field, $xPaths);
					if (!$metadataField){
						KalturaLog::ERR("Missing metadataField for $field in xpath array: " . print_r($xPaths,true));
						continue;
					}
									
					$this->conditionClause[] = $metadataField . $comparison . $item->getValue();
				}
				elseif ($item instanceof AdvancedSearchFilterCondition)
				{
					$field = $item->getField();
					if(!isset($xPaths[$field])){
						KalturaLog::ERR("Missing field: $field in xpath array: " . print_r($xPaths,true));
						continue;
					}
					
					$value = $item->getValue();
					$value = SphinxUtils::escapeString($value);
					$fieldId = $xPaths[$field]->getId();
					if ($xPaths[$field]->getType() == self::KMC_FIELD_TYPE_LIST)
					{
						$dataCondition = "\"{$pluginName}_{$fieldId} $value " . kMetadataManager::SEARCH_TEXT_SUFFIX . "\"";
					}
					else
					{
						$dataCondition = "{$pluginName}_{$fieldId} << $value << " . kMetadataManager::SEARCH_TEXT_SUFFIX;
					}
					
					kalturalog::debug("add $dataCondition");
					$dataConditions[] = "( $dataCondition )";
				}
				elseif($item instanceof MetadataSearchFilter)
				{
					$subConditions[] = $item->applyCondition($this->whereClause, $this->conditionClause, $xPaths);
				}					
			}
		}	
			
		if (count($dataConditions)){
			$metadataConditions = array();
			$glue = ($this->type == MetadataSearchFilter::SEARCH_AND ? ' ' : ' | ');
			$dataConditions = array_unique($dataConditions);
			$metadataConditions['@'. $this->getMetadataSearchField()] = implode($glue, $dataConditions);
			$this->condition = $this->appendToDataCondition($this->condition, $metadataConditions, $this->type);
{'fraction_non_alphanumeric': 0.14438054157680325, 'fraction_numerical': 0.0, 'mean_word_length': 3.5938359933957074, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4441600', 'n_tokens_mistral': 3331, 'n_tokens_neox': 2592, 'n_words': 453}