<commit_before><?php

namespace Sineflow\ElasticsearchBundle\Manager;

use Elasticsearch\Client;
use Elasticsearch\Common\Exceptions\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Sineflow\ElasticsearchBundle\DTO\BulkQueryItem;
use Sineflow\ElasticsearchBundle\Event\Events;
use Sineflow\ElasticsearchBundle\Event\PostCommitEvent;
use Sineflow\ElasticsearchBundle\Exception\BulkRequestException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
 * This class interacts with elasticsearch using injected client.
 */
class ConnectionManager
{
    /**
     * @var string The unique connection manager name (the key from the index configuration)
     */
    private $connectionName;

    /**
     * @var Client
     */
    private $client;

    /**
     * @var array
     */
    private $connectionSettings;

    /**
     * @var BulkQueryItem[] Container for bulk queries.
     */
    private $bulkQueries;

    /**
     * @var array Holder for consistency, refresh and replication parameters.
     */
    private $bulkParams;

    /**
     * @var LoggerInterface
     */
    private $logger = null;

    /**
     * @var bool
     */
    private $autocommit;

    /**
     * @var EventDispatcherInterface
     */
    private $eventDispatcher;

    /**
     * Construct.
     *
     * @param string $connectionName     The unique connection name
     * @param Client $client             Elasticsearch client.
     * @param array  $connectionSettings Settings array.
     */
    public function __construct($connectionName, Client $client, $connectionSettings)
    {
        $this->connectionName = $connectionName;
        $this->client = $client;
        $this->connectionSettings = $connectionSettings;
        $this->bulkQueries = [];
        $this->bulkParams = [];
        $this->autocommit = false;
    }

    /**
     * @param LoggerInterface $logger
     */
    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    /**
     * @return LoggerInterface|null
     */
    public function getLogger()
    {
        return $this->logger;
    }

    /**
     * @return string
     */
    public function getConnectionName()
    {
        return $this->connectionName;
    }

    /**
     * @return Client
     */
    public function getClient()
    {
        return $this->client;
    }

    /**
     * @return array
     */
    public function getConnectionSettings()
    {
        return $this->connectionSettings;
    }

    /**
     * @return bool
     */
    public function isAutocommit()
    {
        return $this->autocommit;
    }

    /**
     * @param bool $autocommit
     */
    public function setAutocommit($autocommit)
    {
        // If the autocommit mode is being turned on, commit any pending bulk items
        if (!$this->autocommit && $autocommit) {
            $this->commit();
        }

        $this->autocommit = $autocommit;
    }

    /**
     * @return EventDispatcherInterface
     */
    public function getEventDispatcher()
    {
        return $this->eventDispatcher;
    }

    /**
     * @param EventDispatcherInterface $eventDispatcher
     */
    public function setEventDispatcher($eventDispatcher)
    {
        $this->eventDispatcher = $eventDispatcher;
    }

    /**
     * Adds query to bulk queries container.
     *
     * @param string $operation  One of: index, update, delete, create.
     * @param string $index      Elasticsearch index name.
     * @param string $type       Elasticsearch type name.
     * @param array  $query      Bulk item query (aka optional_source in the ES docs)
     * @param array  $metaParams Additional meta data params for the bulk item
     */
    public function addBulkOperation($operation, $index, $type, array $query, array $metaParams = [])
    {
        $this->bulkQueries[] = new BulkQueryItem($operation, $index, $type, $query, $metaParams);
    }

    /**
     * Returns the number of bulk operations currently queued
     *
     * @return int
     */
    public function getBulkOperationsCount()
    {
        return count($this->bulkQueries);
    }

    /**
     * @return BulkQueryItem[]
     */
    public function getBulkOperations()
    {
        return $this->bulkQueries;
    }<commit_msg>Removed unnecessarily added ConnectionManager::getBulkOperations() public method<commit_after><?php

namespace Sineflow\ElasticsearchBundle\Manager;

use Elasticsearch\Client;
use Elasticsearch\Common\Exceptions\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Sineflow\ElasticsearchBundle\DTO\BulkQueryItem;
use Sineflow\ElasticsearchBundle\Event\Events;
use Sineflow\ElasticsearchBundle\Event\PostCommitEvent;
use Sineflow\ElasticsearchBundle\Exception\BulkRequestException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
 * This class interacts with elasticsearch using injected client.
 */
class ConnectionManager
{
    /**
     * @var string The unique connection manager name (the key from the index configuration)
     */
    private $connectionName;

    /**
     * @var Client
     */
    private $client;

    /**
     * @var array
     */
    private $connectionSettings;

    /**
     * @var BulkQueryItem[] Container for bulk queries.
     */
    private $bulkQueries;

    /**
     * @var array Holder for consistency, refresh and replication parameters.
     */
    private $bulkParams;

    /**
     * @var LoggerInterface
     */
    private $logger = null;

    /**
     * @var bool
     */
    private $autocommit;

    /**
     * @var EventDispatcherInterface
     */
    private $eventDispatcher;

    /**
     * Construct.
     *
     * @param string $connectionName     The unique connection name
     * @param Client $client             Elasticsearch client.
     * @param array  $connectionSettings Settings array.
     */
    public function __construct($connectionName, Client $client, $connectionSettings)
    {
        $this->connectionName = $connectionName;
        $this->client = $client;
        $this->connectionSettings = $connectionSettings;
        $this->bulkQueries = [];
        $this->bulkParams = [];
        $this->autocommit = false;
    }

    /**
     * @param LoggerInterface $logger
     */
    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    /**
     * @return LoggerInterface|null
     */
    public function getLogger()
    {
        return $this->logger;
    }

    /**
     * @return string
     */
    public function getConnectionName()
    {
        return $this->connectionName;
    }

    /**
     * @return Client
     */
    public function getClient()
    {
        return $this->client;
    }

    /**
     * @return array
     */
    public function getConnectionSettings()
    {
        return $this->connectionSettings;
    }

    /**
     * @return bool
     */
    public function isAutocommit()
    {
        return $this->autocommit;
    }

    /**
     * @param bool $autocommit
     */
    public function setAutocommit($autocommit)
    {
        // If the autocommit mode is being turned on, commit any pending bulk items
        if (!$this->autocommit && $autocommit) {
            $this->commit();
        }

        $this->autocommit = $autocommit;
    }

    /**
     * @return EventDispatcherInterface
     */
    public function getEventDispatcher()
    {
        return $this->eventDispatcher;
    }

    /**
     * @param EventDispatcherInterface $eventDispatcher
     */
    public function setEventDispatcher($eventDispatcher)
    {
        $this->eventDispatcher = $eventDispatcher;
    }

    /**
     * Adds query to bulk queries container.
     *
     * @param string $operation  One of: index, update, delete, create.
     * @param string $index      Elasticsearch index name.
     * @param string $type       Elasticsearch type name.
     * @param array  $query      Bulk item query (aka optional_source in the ES docs)
     * @param array  $metaParams Additional meta data params for the bulk item
     */
    public function addBulkOperation($operation, $index, $type, array $query, array $metaParams = [])
    {
        $this->bulkQueries[] = new BulkQueryItem($operation, $index, $type, $query, $metaParams);
    }

    /**
     * Returns the number of bulk operations currently queued
     *
     * @return int
     */
    public function getBulkOperationsCount()
    {
        return count($this->bulkQueries);
    }
{'fraction_non_alphanumeric': 0.10721040189125296, 'fraction_numerical': 0.0, 'mean_word_length': 2.3206436420722136, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, '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': '216670', 'n_tokens_mistral': 2367, 'n_tokens_neox': 2316, 'n_words': 578}