<commit_before><?php
/**
 * @package plugins.elasticSearch
 * @subpackage lib
 */
class elasticSearchUtils
{
	const UNDERSCORE_FIELD_DELIMITER ='_';
	const DOT_FIELD_DELIMITER = '.';
	
	private static $html_chars_to_replace = array('<br />', '<br>',
		'<br/>', '<div>', '</div>', '<div/>', '<p>', '</p>', '<p/>');

	protected static $elastic_negation_booleans = array('0', 'false', 'off', 'no');

    /**
     * return the analyzed language field name
     * @param $language
     * @param $fieldName
	 * @param $delimiter
     * @return null|string
     */
    public static function getAnalyzedFieldName($language, $fieldName, $delimiter)
    {
        $fieldMap = array(
            'english' => 'english',
            'arabic' => 'arabic',
            'brazilian' => 'brazilian',
            'chinese' => 'cjk',
            'korean' => 'cjk',
            'japanese' => 'cjk',
            'danish' => 'danish',
            'dutch' => 'dutch',
            'finnish' => 'finnish',
            'french' => 'french',
            'german' => 'german',
            'greek' => 'greek',
            'hindi' => 'hindi',
            'indonesian' => 'indonesian',
            'italian' => 'italian',
            'norwegian' => 'norwegian',
            'portuguese' => 'portuguese',
            'russian' => 'russian',
            'spanish' => 'spanish',
            'swedish' => 'swedish',
            'turkish' => 'turkish',
            'thai' => 'thai',
        );

        $language = strtolower($language);
        if(isset($fieldMap[$language]))
            return $fieldName.$delimiter.$fieldMap[$language];

        return null;
    }

	public static function getSynonymFieldName($language, $fieldName, $delimiter)
	{
		$fieldMap = array(
			'english' => kESearchQueryManager::SYNONYM_FIELD_SUFFIX,
		);

		$language = strtolower($language);
		if(isset($fieldMap[$language]))
			return $fieldName.$delimiter.$fieldMap[$language];
	}

	public static function formatGroupIdCreationMode($groupId, $creationMode)
	{
		return sprintf("g%scm%s", $groupId, $creationMode);
	}

	public static function formatPartnerStatus($partnerId, $status)
	{
		return sprintf("p%ss%s", $partnerId, $status);
	}

	public static function formatCategoryIdStatus($categoryId, $status)
	{
		return sprintf("c%ss%s", $categoryId, $status);
	}

	public static function formatCategoryFullIdStatus($categoryId, $status)
	{
		return sprintf("s%sfid>%s", $status, $categoryId);
	}

	public static function formatParentCategoryIdStatus($categoryId, $status)
	{
		return sprintf("p%ss%s", $categoryId, $status);
	}

	public static function formatCategoryNameStatus($categoryName, $status)
	{
		return sprintf("s%sc>%s", $status, $categoryName);
	}

	public static function reverseFormatCategoryNameStatus($categoryNameStatus)
	{
		list($status , $categoryName) = explode ('>',$categoryNameStatus);
		$status = substr($status,1,strlen ($status)-1 );
		return array($status, $categoryName);
	}
	

	public static function formatParentCategoryNameStatus($categoryName, $status)
	{
		return sprintf("s%sp>%s", $status, $categoryName);
	}

	public static function formatCategoryEntryStatus($status)
	{
		return sprintf("ces%s", $status);
	}

	public static function formatCategoryUserPermissionLevel($userId, $permissionLevel)
	{
		return sprintf("uid%spl%s", $userId, $permissionLevel);
	}

	public static function formatCategoryUserPermissionName($userId, $permissionName)
	{
		return sprintf("uid%spn%s", $userId, $permissionName);
	}

	public static function getCategoryUserAllPermissionLevels($userId)
	{<commit_msg>PLAT-9889: code review remarks<commit_after><?php
/**
 * @package plugins.elasticSearch
 * @subpackage lib
 */
class elasticSearchUtils
{
	const UNDERSCORE_FIELD_DELIMITER ='_';
	const DOT_FIELD_DELIMITER = '.';
	
	private static $html_chars_to_replace = array('<br />', '<br>',
		'<br/>', '<div>', '</div>', '<div/>', '<p>', '</p>', '<p/>');

	protected static $elastic_negation_booleans = array('0', 'false', 'off', 'no');

    /**
     * return the analyzed language field name
     * @param $language
     * @param $fieldName
	 * @param $delimiter
     * @return null|string
     */
    public static function getAnalyzedFieldName($language, $fieldName, $delimiter)
    {
        $fieldMap = array(
            'english' => 'english',
            'arabic' => 'arabic',
            'brazilian' => 'brazilian',
            'chinese' => 'cjk',
            'korean' => 'cjk',
            'japanese' => 'cjk',
            'danish' => 'danish',
            'dutch' => 'dutch',
            'finnish' => 'finnish',
            'french' => 'french',
            'german' => 'german',
            'greek' => 'greek',
            'hindi' => 'hindi',
            'indonesian' => 'indonesian',
            'italian' => 'italian',
            'norwegian' => 'norwegian',
            'portuguese' => 'portuguese',
            'russian' => 'russian',
            'spanish' => 'spanish',
            'swedish' => 'swedish',
            'turkish' => 'turkish',
            'thai' => 'thai',
        );

        $language = strtolower($language);
        if(isset($fieldMap[$language]))
            return $fieldName.$delimiter.$fieldMap[$language];

        return null;
    }

	public static function getSynonymFieldName($language, $fieldName, $delimiter)
	{
		$fieldMap = array(
			'english' => kESearchQueryManager::SYNONYM_FIELD_SUFFIX,
		);

		$language = strtolower($language);
		if(isset($fieldMap[$language]))
			return $fieldName.$delimiter.$fieldMap[$language];
	}

	public static function formatGroupIdCreationMode($groupId, $creationMode)
	{
		return sprintf("g%scm%s", $groupId, $creationMode);
	}

	public static function formatPartnerStatus($partnerId, $status)
	{
		return sprintf("p%ss%s", $partnerId, $status);
	}

	public static function formatCategoryIdStatus($categoryId, $status)
	{
		return sprintf("c%ss%s", $categoryId, $status);
	}

	public static function formatCategoryFullIdStatus($categoryId, $status)
	{
		return sprintf("s%sfid>%s", $status, $categoryId);
	}

	public static function formatParentCategoryIdStatus($categoryId, $status)
	{
		return sprintf("p%ss%s", $categoryId, $status);
	}

	public static function formatCategoryNameStatus($categoryName, $status)
	{
		return sprintf("s%sc>%s", $status, $categoryName);
	}

	public static function reverseFormatCategoryNameStatus($categoryNameStatus)
	{
		list($status , $categoryName) = explode ('>',$categoryNameStatus);
		$status = substr($status,1,strlen ($status)-1 );
		return array($status, $categoryName);
	}
	
	public static function formatParentCategoryNameStatus($categoryName, $status)
	{
		return sprintf("s%sp>%s", $status, $categoryName);
	}

	public static function formatCategoryEntryStatus($status)
	{
		return sprintf("ces%s", $status);
	}

	public static function formatCategoryUserPermissionLevel($userId, $permissionLevel)
	{
		return sprintf("uid%spl%s", $userId, $permissionLevel);
	}

	public static function formatCategoryUserPermissionName($userId, $permissionName)
	{
		return sprintf("uid%spn%s", $userId, $permissionName);
	}

	public static function getCategoryUserAllPermissionLevels($userId)
	{
{'fraction_non_alphanumeric': 0.1588628762541806, 'fraction_numerical': 0.0013935340022296545, 'mean_word_length': 3.5539340101522843, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 75, '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': '4154047', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2265, 'n_words': 451}