<commit_before><?php

/**
 * @package plugins.beacon
 * @subpackage api.filters
 */
class KalturaBeaconEnhanceFilter extends KalturaFilter
{
	/**
	 * @var string
	 */
	public $externalElasticQueryObject;
	
	/**
	 * @var KalturaBeaconIndexType
	 */
	public $indexTypeEqual;
	
	public function getCoreFilter()
	{
		return null;
	}
	
	public function enhanceSearch(KalturaFilterPager $pager)
	{
		$utf8Query = utf8_encode($this->externalElasticQueryObject);
		$queryJsonObject = json_decode($utf8Query, true);
		
		if(!$queryJsonObject)
			throw new KalturaAPIException(APIErrors::INTERNAL_SERVERL_ERROR);
		
		if(!isset($queryJsonObject['query']))
			throw new KalturaAPIException(APIErrors::INTERNAL_SERVERL_ERROR);
		
		$searchQuery = array();
		$searchQuery['body']['query']['bool']['must'] = $queryJsonObject['query'];
		$searchQuery['body']['query']['bool']['filter']['term'] = array ("partner_id" => kCurrentContext::getCurrentPartnerId());
		$searchQuery[elasticClient::ELASTIC_INDEX_KEY] = kBeacon::ELASTIC_BEACONS_INDEX_NAME;
		$searchQuery[kESearchQueryManager::BODY_KEY][elasticClient::ELASTIC_SIZE_KEY] = $pager->pageSize;
		$searchQuery[kESearchQueryManager::BODY_KEY][elasticClient::ELASTIC_FROM_KEY] = $pager->calcOffset();
		
		if(isset($queryJsonObject['sort']))
			$searchQuery[kESearchQueryManager::BODY_KEY][kESearchQueryManager::SORT_KEY] = $queryJsonObject['sort'];
		
		if($this->indexTypeEqual)
			$searchQuery[elasticClient::ELASTIC_TYPE_KEY] = $this->indexTypeEqual;
		
		$searchMgr = new kBeaconSearchQueryManger();
		$responseArray = $searchMgr->search($searchQuery);
		$totalCount = $searchMgr->getTotalCount($responseArray);
		$responseArray = $searchMgr->getHitsFromElasticResponse($responseArray);
		<commit_msg>No-Plat: Fix empty result when filtering on indexType<commit_after><?php

/**
 * @package plugins.beacon
 * @subpackage api.filters
 */
class KalturaBeaconEnhanceFilter extends KalturaFilter
{
	/**
	 * @var string
	 */
	public $externalElasticQueryObject;
	
	/**
	 * @var KalturaBeaconIndexType
	 */
	public $indexTypeEqual;
	
	public function getCoreFilter()
	{
		return null;
	}
	
	public function enhanceSearch(KalturaFilterPager $pager)
	{
		$utf8Query = utf8_encode($this->externalElasticQueryObject);
		$queryJsonObject = json_decode($utf8Query, true);
		
		if(!$queryJsonObject)
			throw new KalturaAPIException(APIErrors::INTERNAL_SERVERL_ERROR);
		
		if(!isset($queryJsonObject['query']))
			throw new KalturaAPIException(APIErrors::INTERNAL_SERVERL_ERROR);
		
		$searchQuery = array();
		$searchQuery['body']['query']['bool']['must'] = $queryJsonObject['query'];
		$searchQuery['body']['query']['bool']['filter'][]['term'] = array ("partner_id" => kCurrentContext::getCurrentPartnerId());
		
		if($this->indexTypeEqual)
			$searchQuery['body']['query']['bool']['filter'][]['term'] = array (kBeacon::FIELD_IS_LOG => ($this->indexTypeEqual == KalturaBeaconIndexType::LOG) ? true : false);
		
		$searchQuery[elasticClient::ELASTIC_INDEX_KEY] = kBeacon::ELASTIC_BEACONS_INDEX_NAME;
		$searchQuery[kESearchQueryManager::BODY_KEY][elasticClient::ELASTIC_SIZE_KEY] = $pager->pageSize;
		$searchQuery[kESearchQueryManager::BODY_KEY][elasticClient::ELASTIC_FROM_KEY] = $pager->calcOffset();
		
		if(isset($queryJsonObject['sort']))
			$searchQuery[kESearchQueryManager::BODY_KEY][kESearchQueryManager::SORT_KEY] = $queryJsonObject['sort'];
		
		$searchMgr = new kBeaconSearchQueryManger();
		$responseArray = $searchMgr->search($searchQuery);
		$totalCount = $searchMgr->getTotalCount($responseArray);
		$responseArray = $searchMgr->getHitsFromElasticResponse($responseArray);
		
{'fraction_non_alphanumeric': 0.15129762562120375, 'fraction_numerical': 0.0016565433462175593, 'mean_word_length': 7.3672055427251735, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '5010731', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1161, 'n_words': 148}