<commit_before><?php

namespace Application\Bundle\FrontBundle\EventListener;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
//use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Application\Bundle\FrontBundle\Entity\Records;
use Application\Bundle\FrontBundle\Entity\AudioRecords;
use Application\Bundle\FrontBundle\Entity\FilmRecords;
use Application\Bundle\FrontBundle\Entity\VideoRecords;
use Application\Bundle\FrontBundle\SphinxSearch\SphinxSearch;

class SearchIndexerSubscriber implements EventSubscriber
{

	public function getSubscribedEvents()
	{
		return array(
			'postPersist',
			'postUpdate',
		);
	}

	public function postUpdate(LifecycleEventArgs $args)
	{
		$this->index($args, 'update');
	}

	public function postPersist(LifecycleEventArgs $args)
	{
		$this->index($args, 'insert');
	}

	public function index(LifecycleEventArgs $args, $type)
	{
		$entity = $args->getEntity();
		$entityManager = $args->getEntityManager();
//echo '<pre>';print_r($entity->getAudioRecord()->getId()); exit;
		if ($entity instanceof AudioRecords || $entity instanceof VideoRecords || $entity instanceof FilmRecords)
		{
			$sphinxSearch = new SphinxSearch($entityManager, $entity->getId());
			if ($type === 'insert')
				$sphinxSearch->insert();
			else
				$sphinxSearch->update();
		}
	}

}<commit_msg>inset records in shpinx while adding new records<commit_after><?php

namespace Application\Bundle\FrontBundle\EventListener;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
//use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Application\Bundle\FrontBundle\Entity\Records;
use Application\Bundle\FrontBundle\Entity\AudioRecords;
use Application\Bundle\FrontBundle\Entity\FilmRecords;
use Application\Bundle\FrontBundle\Entity\VideoRecords;
use Application\Bundle\FrontBundle\SphinxSearch\SphinxSearch;

class SearchIndexerSubscriber implements EventSubscriber
{

	public function getSubscribedEvents()
	{
		return array(
			'postPersist',
			'postUpdate',
		);
	}

	public function postUpdate(LifecycleEventArgs $args)
	{
		$this->index($args, 'update');
	}

	public function postPersist(LifecycleEventArgs $args)
	{
		$this->index($args, 'insert');
	}

	public function index(LifecycleEventArgs $args, $type)
	{
		$entity = $args->getEntity();
		$entityManager = $args->getEntityManager();
echo '<pre>';print_r($entity->getAudioRecord()->getId()); exit;
		if ($entity instanceof AudioRecords || $entity instanceof VideoRecords || $entity instanceof FilmRecords)
		{
			$sphinxSearch = new SphinxSearch($entityManager, $entity->getId());
			if ($type === 'insert')
				$sphinxSearch->insert();
			else
				$sphinxSearch->update();
		}
	}

}
{'fraction_non_alphanumeric': 0.13016453382084095, 'fraction_numerical': 0.0, 'mean_word_length': 5.8059701492537314, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '378444', 'n_tokens_mistral': 868, 'n_tokens_neox': 811, 'n_words': 155}