<commit_before><?php
namespace Kdde\EdbStoreBundle\Entity;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\ResultSetMapping;

class EpigraphRepository extends EntityRepository {

	
	
	public function findBasicSearch($searchArray, $roles) {
	
		$isAdmin = false;
		if (in_array("administrator", $roles))
			$isAdmin = true;
	
	
		// Read the search parameters
		//--------------------------------------------------------------------------------	
		$icvrId = null;
		if (strlen($searchArray['icvr']))
			$icvrId = $searchArray['icvr'];
	
		$type = $searchArray['type'];
		$inSitu = $searchArray['insitu'];
		$lost = $searchArray['lost'];
		
		$opistographic = $searchArray['opistographic'];
		$metrical = $searchArray['metrical'];
		$greek = $searchArray['greek'];
		$greeklatin = $searchArray['greeklatin'];
		$support = $searchArray['support'];
		$technique = $searchArray['technique'];
		$function = $searchArray['function'];
		$compiler = $searchArray['compiler'];
			
		$dating = $searchArray['dating'];
		$from = $searchArray['from'];
		$to = $searchArray['to'];
			
		$areaId = null;
		if (strlen($searchArray['area']))
		{
			$areaContext = explode('@_@', $searchArray['area']);
			$areaId = $areaContext[0];
			$contextId = $areaContext[1];
			if($contextId == '')
				$contextId = null;
		}
	
		$cons_areaId = null;
		if (strlen($searchArray['cons_area']))
		{
			$consareaContext = explode('@_@', $searchArray['cons_area']);
			$cons_areaId = $consareaContext[0];
			$cons_contextId = $consareaContext[1];
			if($cons_contextId == '')
				$cons_contextId = null;
		}
			
		$transcription = null;
		if (strlen($searchArray['transcription']))
			$transcription = $searchArray['transcription'];
	
		$useThesaurus = false;
		if (isset($searchArray['thesaurus']))
			$useThesaurus = true;
	
		$yesDiacr = false;
		if (isset($searchArray['yesdiacr']))
			$yesDiacr = true;
	
		$yesGreek = false;
		if (isset($searchArray['yesgreek']))
			$yesGreek = true;
		//--------------------------------------------------------------------------------

		
		
		// Compose the query
		//--------------------------------------------------------------------------------
		$strQuerySelect = "SELECT ep FROM KddeEdbStoreBundle:Epigraph ep ";
		$strQueryWhere = "";
	
	
		if ($icvrId != null) {
			$strQuerySelect .= "JOIN ep.icvr ic ";
			$strQueryWhere .= "AND ic.id = :icvrId ";
		}
		
		
		if ($areaId != null || $inSitu != "All")
		{	
			$strQuerySelect .= "JOIN ep.pertinences pe JOIN pe.pertinenceArea pa ";
			
			if($areaId != null)
				$strQueryWhere .= "AND pa.id = :areaId ";
			
			if($inSitu != "All")
				$strQueryWhere .= "AND pe.inSitu = :inSitu ";	
		}
	
		if ($contextId != null) {
			$strQuerySelect .= "JOIN pe.context pc ";
			$strQueryWhere .= "AND pc.id = :contextId ";
		}
	
		if ($cons_areaId != null) {
			$strQuerySelect .= "JOIN ep.conservations co JOIN co.conservationLocation cl ";
			$strQueryWhere .= "AND cl.id = :cons_areaId ";
		}
	
		if ($cons_contextId != null) {
			$strQuerySelect .= "JOIN co.conservationContext cc ";
			$strQueryWhere .= "AND cc.id = :cons_contextId ";
		}
		
		
		if($dating != "All")
		{
			$strQuerySelect .= "JOIN ep.datings dat ";
			
			if($from != null)
				$strQueryWhere .= "AND dat.to >= :from ";
			
			if($to != null)
				$strQueryWhere .= "AND dat.from <= :to ";
		}
		
		if ($transcription != null) {
			if ($useThesaurus == true) {
				$words = str_replace(" ", " & ", $transcription);
				$strQueryWhere .= "AND MATCHTEXT(:queryWords,ep.ts_testo) = 1 ";
			}
			else{
				if($yesGreek && $yesDiacr)
					$field = "ep.trascription";
				else if($yesGreek)
					$field = "ep.trascription_nodiacr";
				else if($yesDiacr)
					$field = "ep.trascription_nogreek";
				else
					$field = "ep.trascription_nodiacr_nogreek";
	
				$words = explode(" ", $transcription);
				$count = 1;
				foreach($words as $word)
				{
					$strQueryWhere .= "AND LOWER(" . $field . ") LIKE ";
					if($yesGreek && $yesDiacr)
						$transc = "CONCAT(CONCAT('%', :transcription" . $count . "),'%') ";
					else if($yesGreek)
						$transc = "CONCAT(CONCAT('%',REMOVEDIACR(:transcription" . $count . ")),'%') ";
					else if($yesDiacr)
						$transc = "CONCAT(CONCAT('%',REMOVEGREEKS(:transcription" . $count . ")),'%') ";
					else
						$transc = "CONCAT(CONCAT('%',REMOVEGREEKS(REMOVEDIACR(:transcription" . $count . "))),'%') ";
					$strQueryWhere .= $transc;
						
					$count++;
				}
			}
		}
	
		if ($type != -1)
			$strQueryWhere .= "AND ep.epigraph_type = :epi_type ";
		
		if ($lost != "All")
			$strQueryWhere .= "AND ep.lost = :lost ";
					
		if ($opistographic != "All")
			$strQueryWhere .= "AND ep.reimpiego_opistografia = :opistographic ";
		
		if ($metrical != "All")
			$strQueryWhere .= "AND ep.metricText = :metrical ";
		
		if ($greek != "All")
			$strQueryWhere .= "AND ep.greek = :greek ";
		
		if ($greeklatin != "All")
			$strQueryWhere .= "AND ep.presenceLG = :greeklatin ";
		
		if ($function != "All")
			$strQueryWhere .= "AND ep.funzione = :function ";
		
		if ($compiler != "All")
			$strQueryWhere .= "AND ep.oldCompilator = :compiler ";
				
		if ($support != "All" || $technique != "All")
		{
			$strQuerySelect .= "JOIN ep.material mat ";
			
			if ($technique != "All")
				$strQueryWhere .= "AND mat.technique = :technique ";
		
			if ($support != "All")
				$strQueryWhere .= "AND mat.support = :support ";
		}
			
		if (!$isAdmin)<commit_msg>Fixed a bug in the search<commit_after><?php
namespace Kdde\EdbStoreBundle\Entity;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\ResultSetMapping;

class EpigraphRepository extends EntityRepository {

	
	
	public function findBasicSearch($searchArray, $roles) {
	
		$isAdmin = false;
		if (in_array("administrator", $roles))
			$isAdmin = true;
	
	
		// Read the search parameters
		//--------------------------------------------------------------------------------	
		$icvrId = null;
		if (strlen($searchArray['icvr']))
			$icvrId = $searchArray['icvr'];
	
		$type = $searchArray['type'];
		$inSitu = $searchArray['insitu'];
		$lost = $searchArray['lost'];
		
		$opistographic = $searchArray['opistographic'];
		$metrical = $searchArray['metrical'];
		$greek = $searchArray['greek'];
		$greeklatin = $searchArray['greeklatin'];
		$support = $searchArray['support'];
		$technique = $searchArray['technique'];
		$function = $searchArray['function'];
		$compiler = $searchArray['compiler'];
			
		$dating = $searchArray['dating'];
		$from = $searchArray['from'];
		$to = $searchArray['to'];
			
		$areaId = null;
		if (strlen($searchArray['area']))
		{
			$areaContext = explode('@_@', $searchArray['area']);
			$areaId = $areaContext[0];
			$contextId = $areaContext[1];
			if($contextId == '')
				$contextId = null;
		}
	
		$cons_areaId = null;
		if (strlen($searchArray['cons_area']))
		{
			$consareaContext = explode('@_@', $searchArray['cons_area']);
			$cons_areaId = $consareaContext[0];
			$cons_contextId = $consareaContext[1];
			if($cons_contextId == '')
				$cons_contextId = null;
		}
			
		$transcription = null;
		if (strlen($searchArray['transcription']))
			$transcription = $searchArray['transcription'];
	
		$useThesaurus = false;
		if (isset($searchArray['thesaurus']))
			$useThesaurus = true;
	
		$yesDiacr = false;
		if (isset($searchArray['yesdiacr']))
			$yesDiacr = true;
	
		$yesGreek = false;
		if (isset($searchArray['yesgreek']))
			$yesGreek = true;
		//--------------------------------------------------------------------------------

		
		
		// Compose the query
		//--------------------------------------------------------------------------------
		$strQuerySelect = "SELECT ep FROM KddeEdbStoreBundle:Epigraph ep ";
		$strQueryWhere = "";
	
	
		if ($icvrId != null) {
			$strQuerySelect .= "JOIN ep.icvr ic ";
			$strQueryWhere .= "AND ic.id = :icvrId ";
		}
		
		
		if ($areaId != null || $inSitu != "All")
		{	
			$strQuerySelect .= "JOIN ep.pertinences pe JOIN pe.pertinenceArea pa ";
			
			if($areaId != null)
				$strQueryWhere .= "AND pa.id = :areaId ";
			
			if($inSitu != "All")
				$strQueryWhere .= "AND pe.inSitu = :inSitu ";	
		}
	
		if ($contextId != null) {
			$strQuerySelect .= "JOIN pe.context pc ";
			$strQueryWhere .= "AND pc.id = :contextId ";
		}
	
		if ($cons_areaId != null) {
			$strQuerySelect .= "JOIN ep.conservations co JOIN co.conservationLocation cl ";
			$strQueryWhere .= "AND cl.id = :cons_areaId ";
		}
	
		if ($cons_contextId != null) {
			$strQuerySelect .= "JOIN co.conservationContext cc ";
			$strQueryWhere .= "AND cc.id = :cons_contextId ";
		}
		
				
		if ($transcription != null) {
			if ($useThesaurus == true) {
				$words = str_replace(" ", " & ", $transcription);
				$strQueryWhere .= "AND MATCHTEXT(:queryWords,ep.ts_testo) = 1 ";
			}
			else{
				if($yesGreek && $yesDiacr)
					$field = "ep.trascription";
				else if($yesGreek)
					$field = "ep.trascription_nodiacr";
				else if($yesDiacr)
					$field = "ep.trascription_nogreek";
				else
					$field = "ep.trascription_nodiacr_nogreek";
	
				$words = explode(" ", $transcription);
				$count = 1;
				foreach($words as $word)
				{
					$strQueryWhere .= "AND LOWER(" . $field . ") LIKE ";
					if($yesGreek && $yesDiacr)
						$transc = "CONCAT(CONCAT('%', :transcription" . $count . "),'%') ";
					else if($yesGreek)
						$transc = "CONCAT(CONCAT('%',REMOVEDIACR(:transcription" . $count . ")),'%') ";
					else if($yesDiacr)
						$transc = "CONCAT(CONCAT('%',REMOVEGREEKS(:transcription" . $count . ")),'%') ";
					else
						$transc = "CONCAT(CONCAT('%',REMOVEGREEKS(REMOVEDIACR(:transcription" . $count . "))),'%') ";
					$strQueryWhere .= $transc;
						
					$count++;
				}
			}
		}
	
		if ($type != -1)
			$strQueryWhere .= "AND ep.epigraph_type = :epi_type ";
		
		if ($lost != "All")
			$strQueryWhere .= "AND ep.lost = :lost ";
					
		if ($opistographic != "All")
			$strQueryWhere .= "AND ep.reimpiego_opistografia = :opistographic ";
		
		if ($metrical != "All")
			$strQueryWhere .= "AND ep.metricText = :metrical ";
		
		if ($greek != "All")
			$strQueryWhere .= "AND ep.greek = :greek ";
		
		if ($greeklatin != "All")
			$strQueryWhere .= "AND ep.presenceLG = :greeklatin ";
		
		if ($function != "All")
			$strQueryWhere .= "AND ep.funzione = :function ";
		
		if ($compiler != "All")
			$strQueryWhere .= "AND ep.oldCompilator = :compiler ";
				
		if($dating != "All")
		{
			$strQuerySelect .= "JOIN ep.datings dat ";
				
			if($from != null)
				$strQueryWhere .= "AND dat.to >= :from ";
				
			if($to != null)
				$strQueryWhere .= "AND dat.from <= :to ";
		}
		
		if ($support != "All" || $technique != "All")
		{
			$strQuerySelect .= "JOIN ep.material mat ";
			
			if ($technique != "All")
				$strQueryWhere .= "AND mat.technique = :technique ";
		
			if ($support != "All")
				$strQueryWhere .= "AND mat.support = :support ";
		}
			
		if (!$isAdmin)
{'fraction_non_alphanumeric': 0.22091527292777063, 'fraction_numerical': 0.0012865282117257857, 'mean_word_length': 2.711800818553888, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4906388', 'n_tokens_mistral': 4524, 'n_tokens_neox': 3689, 'n_words': 718}