<commit_before><?php namespace Buonzz\Evorg;

use \Elasticsearch\Client;
use Illuminate\Support\Collection;

class EventRepository{

	private $client;

	public function __construct(){

		$hosts = \Config::get('evorg::hosts');		
		
		$params = array();		
		$params['hosts'] = $hosts;		
		$params['logging'] =\Config::get('evorg::logging');
		$params['logPath'] = storage_path() .'/logs/evorg.log';

		$this->client = new Client($params);
	}

	public function create($eventName, $eventData){	
		
		$params = array();

		$params['body']  = $eventData;
		
		$params['body']['settings']['number_of_shards']  = \Config::get('evorg::number_of_shards');
		$params['body']['settings']['number_of_replicas']  = \Config::get('evorg::number_of_replicas');		

		$params['index'] = 'events';
		$params['type']  = $eventName;		

		return $this->client->index($params);
	}

	public function get_all($event_name){

		$params = array();

		$params['body']['query']['matchAll']  = new \stdclass;
		$params['index'] = 'events';
		$params['type']  = $event_name;		

		return $this->convert_to_collection(
					$this->client->search($params)
			);	
	}

	public function read(){
		
	}

	public function update(){
		
	}

	public function delete(){
		
	}

	private function convert_to_collection($search_result){
		
		$data = $search_result['hits']['hits'];
        $tmp = array();

        if(is_array($data))
        {
            foreach($data as $item)
            {
                    $cur_item = $item['_source'];
                    $cur_item['id'] =  $item['_id'];
                    $tmp[] = $cur_item;
            }
        }
        else
                $tmp[] =  $data['_source'];

        return new Collection($tmp);
	}
}<commit_msg>put the params in its own function<commit_after><?php namespace Buonzz\Evorg;

use \Elasticsearch\Client;
use Illuminate\Support\Collection;

class EventRepository{

	private $client;

	public function __construct(){

		$hosts = \Config::get('evorg::hosts');		
		
		$params = array();		
		$params['hosts'] = $hosts;		
		$params['logging'] =\Config::get('evorg::logging');
		$params['logPath'] = storage_path() .'/logs/evorg.log';

		$this->client = new Client($params);
	}

	public function create($eventName, $eventData){			
		
		$params = $this->build_parameters($eventData, $eventName);

		return $this->client->index($params);
	}

	public function get_all($event_name){

		$params = array();

		$params['body']['query']['matchAll']  = new \stdclass;
		$params['index'] = 'events';
		$params['type']  = $event_name;		

		return $this->convert_to_collection(
					$this->client->search($params)
			);	
	}

	public function read(){
		
	}

	public function update(){
		
	}

	public function delete(){
		
	}

	private function convert_to_collection($search_result){
		
		$data = $search_result['hits']['hits'];
        $tmp = array();

        if(is_array($data))
        {
            foreach($data as $item)
            {
                    $cur_item = $item['_source'];
                    $cur_item['id'] =  $item['_id'];
                    $tmp[] = $cur_item;
            }
        }
        else
                $tmp[] =  $data['_source'];

        return new Collection($tmp);
	}

	private function build_parameters($eventData, $eventName){
		
		$params = array();

		$params['body']  = $eventData;
		
		$params['body']['settings']['number_of_shards']  = \Config::get('evorg::number_of_shards');
		$params['body']['settings']['number_of_replicas']  = \Config::get('evorg::number_of_replicas');		

		$params['index'] = 'events';
		$params['type']  = $eventName;		

		return $params;
	}
}
{'fraction_non_alphanumeric': 0.18407960199004975, 'fraction_numerical': 0.0, 'mean_word_length': 3.057174887892377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, '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': '1064822', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1152, 'n_words': 201}