<commit_before><?php

namespace Kunstmaan\SearchBundle\Sherlock;

use Kunstmaan\SearchBundle\Provider\SearchProviderInterface;
use Sherlock\Sherlock;

/**
 * The Sherlock SearchProvider
 */
class SherlockSearchProvider implements SearchProviderInterface
{
    private $sherlock;

    public function __construct($hostname, $port)
    {
        $this->sherlock = new Sherlock;
        $this->sherlock->addNode($hostname, $port);
    }

    /**
     * @inheritdoc
     */
    public function getName()
    {
        return "Sherlock";
    }

    /**
     * @inheritdoc
     */
    public function createIndex($name)
    {
        return $this->sherlock->index($name);
    }

    /**
     * @inheritdoc
     */
    public function addDocument($indexName, $indexType, $doc, $uid)
    {
        $doc = $this->sherlock
            ->document()
            ->index($indexName)
            ->type($indexType)
            ->document($doc, $uid);
        $doc->execute();
    }

    /**
     * @inheritdoc
     */
    public function deleteDocument($indexName, $indexType, $uid)
    {
        $this->sherlock
            ->deleteDocument()
            ->index($indexName)
            ->type($indexType)
            ->document($uid)
            ->execute();
    }

    /**
     * @inheritdoc
     */<commit_msg>gracefully handle the DocumentMissingException<commit_after><?php

namespace Kunstmaan\SearchBundle\Sherlock;

use Kunstmaan\SearchBundle\Provider\SearchProviderInterface;
use Sherlock\common\exceptions\DocumentMissingException;
use Sherlock\Sherlock;

/**
 * The Sherlock SearchProvider
 */
class SherlockSearchProvider implements SearchProviderInterface
{
    private $sherlock;

    public function __construct($hostname, $port)
    {
        $this->sherlock = new Sherlock;
        $this->sherlock->addNode($hostname, $port);
    }

    /**
     * @inheritdoc
     */
    public function getName()
    {
        return "Sherlock";
    }

    /**
     * @inheritdoc
     */
    public function createIndex($name)
    {
        return $this->sherlock->index($name);
    }

    /**
     * @inheritdoc
     */
    public function addDocument($indexName, $indexType, $doc, $uid)
    {
        $doc = $this->sherlock
            ->document()
            ->index($indexName)
            ->type($indexType)
            ->document($doc, $uid);
        $doc->execute();
    }

    /**
     * @inheritdoc
     */
    public function deleteDocument($indexName, $indexType, $uid)
    {
        try {
            $this->sherlock
                ->deleteDocument()
            ->index($indexName)
            ->type($indexType)
            ->document($uid)
            ->execute();
        } catch (DocumentMissingException $e) {
            // Document already not in index anymore
        }
    }

    /**
     * @inheritdoc
     */
{'fraction_non_alphanumeric': 0.13354587318455544, 'fraction_numerical': 0.0, 'mean_word_length': 1.978902953586498, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '256410', 'n_tokens_mistral': 819, 'n_tokens_neox': 809, 'n_words': 145}