<commit_before><?php



namespace App;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\URL;
use Intervention\Image\ImageManagerStatic;
use Illuminate\Support\Facades\Cache;
use Fadion\Bouncy\Facades\Elastic;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Fadion\Bouncy\BouncyTrait;
use Illuminate\Database\Eloquent\Model;

class Item extends Model
{
    use \Conner\Tagging\Taggable;
    use \Dimsav\Translatable\Translatable, BouncyTrait {
        BouncyTrait::save as saveBouncyTrait;
        \Dimsav\Translatable\Translatable::save insteadof BouncyTrait;
    }

    const ARTWORKS_DIR = '/images/diela/';
    const ES_TYPE = 'items';

    public $translatedAttributes = [
        'title',
        'description',
        'work_type',
        'work_level',
        'topic',
        'subject',
        'measurement',
        'dating',
        'medium',
        'technique',
        'inscription',
        'place',
        'state_edition',
        'gallery',
        'relationship_type',
        'related_work'
    ];

    // protected $indexName = 'webumenia';
    protected $typeName = self::ES_TYPE;

    public static $filterable = array(
        'autor' => 'author',
        'výtvarný druh' => 'work_type',
        'tagy' => 'tag',
        'galéria' => 'gallery',
        'žáner' => 'topic',
        'materiál' => 'medium',
        'technika' => 'technique',
        'len s obrázkom' => 'has_image',
        'len so zoom' => 'has_iip',
        'len voľné' => 'is_free',
        'zo súboru' => 'related_work'
    );

    public static $sortable = array(
        'updated_at'    => 'sortable.updated_at',
        'created_at'    => 'sortable.created_at',
        'title'         => 'sortable.title',
        'author'        => 'sortable.author',
        'date_earliest' => 'sortable.date_earliest',
        'view_count'    => 'sortable.view_count',
        'random'        => 'sortable.random',
    );

    protected $fillable = array(
        'id',
        'identifier',
        'author',
        'title',
        'description',
        'description_user_id',
        'description_source',
        'description_source_link',
        'work_type',
        'work_level',
        'topic',
        'subject',
        'measurement',
        'dating',
        'date_earliest',
        'date_latest',
        'medium',
        'technique',
        'inscription',
        'place',
        'lat',
        'lng',
        'state_edition',
        'relationship_type',
        'related_work',
        'related_work_order',
        'related_work_total',
        'gallery',
        'item_type',
        'publish',
    );

    protected $dates = array(
        'created_at',
        'updated_at',
    );

    public static $rules = array(
        'author' => 'required',
        'sk.title'  => 'required',
        'sk.dating' => 'required',
    );

    // protected $appends = array('measurements');

    public $incrementing = false;

    protected $guarded = array('featured');

    protected $mappingProperties = array(
        'title' => [
          'type' => 'string',
          "analyzer" => "standard",
        ],
        'author' => [
          'type' => 'string',
          "analyzer" => "standard",
        ],
    );

    protected $casts = array(
        'color_descriptor' => 'json',
    );

    // ELASTIC SEARCH INDEX
    public static function boot()
    {
        parent::boot();

        static::created(function ($item) {
            $item->index();
        });

        static::updated(function ($item) {
            $item->index();
        });

        static::deleting(function ($item) {
            $item->removeImage();
            $item->collections()->detach();
        });

        static::deleted(function ($item) {
             $item->getElasticClient()->delete([
                'index' => Config::get('bouncy.index'),
                'type' => $item::ES_TYPE,
                'id' => $item->id,
             ]);
        });
    }

    public function descriptionUser()
    {
        return $this->belongsTo(\App\User::class, 'description_user_id');
    }

    public function authorities()
    {
        return $this->belongsToMany(\App\Authority::class, 'authority_item', 'item_id', 'authority_id')->withPivot('role');
    }

    public function collections()
    {
        return $this->belongsToMany(\App\Collection::class, 'collection_item', 'item_id', 'collection_id');
    }
<commit_msg>[fix] remove item from all localized es indexes<commit_after><?php



namespace App;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\URL;
use Intervention\Image\ImageManagerStatic;
use Illuminate\Support\Facades\Cache;
use Fadion\Bouncy\Facades\Elastic;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Fadion\Bouncy\BouncyTrait;
use Illuminate\Database\Eloquent\Model;

class Item extends Model
{
    use \Conner\Tagging\Taggable;
    use \Dimsav\Translatable\Translatable, BouncyTrait {
        BouncyTrait::save as saveBouncyTrait;
        \Dimsav\Translatable\Translatable::save insteadof BouncyTrait;
    }

    const ARTWORKS_DIR = '/images/diela/';
    const ES_TYPE = 'items';

    public $translatedAttributes = [
        'title',
        'description',
        'work_type',
        'work_level',
        'topic',
        'subject',
        'measurement',
        'dating',
        'medium',
        'technique',
        'inscription',
        'place',
        'state_edition',
        'gallery',
        'relationship_type',
        'related_work'
    ];

    // protected $indexName = 'webumenia';
    protected $typeName = self::ES_TYPE;

    public static $filterable = array(
        'autor' => 'author',
        'výtvarný druh' => 'work_type',
        'tagy' => 'tag',
        'galéria' => 'gallery',
        'žáner' => 'topic',
        'materiál' => 'medium',
        'technika' => 'technique',
        'len s obrázkom' => 'has_image',
        'len so zoom' => 'has_iip',
        'len voľné' => 'is_free',
        'zo súboru' => 'related_work'
    );

    public static $sortable = array(
        'updated_at'    => 'sortable.updated_at',
        'created_at'    => 'sortable.created_at',
        'title'         => 'sortable.title',
        'author'        => 'sortable.author',
        'date_earliest' => 'sortable.date_earliest',
        'view_count'    => 'sortable.view_count',
        'random'        => 'sortable.random',
    );

    protected $fillable = array(
        'id',
        'identifier',
        'author',
        'title',
        'description',
        'description_user_id',
        'description_source',
        'description_source_link',
        'work_type',
        'work_level',
        'topic',
        'subject',
        'measurement',
        'dating',
        'date_earliest',
        'date_latest',
        'medium',
        'technique',
        'inscription',
        'place',
        'lat',
        'lng',
        'state_edition',
        'relationship_type',
        'related_work',
        'related_work_order',
        'related_work_total',
        'gallery',
        'item_type',
        'publish',
    );

    protected $dates = array(
        'created_at',
        'updated_at',
    );

    public static $rules = array(
        'author' => 'required',
        'sk.title'  => 'required',
        'sk.dating' => 'required',
    );

    // protected $appends = array('measurements');

    public $incrementing = false;

    protected $guarded = array('featured');

    protected $mappingProperties = array(
        'title' => [
          'type' => 'string',
          "analyzer" => "standard",
        ],
        'author' => [
          'type' => 'string',
          "analyzer" => "standard",
        ],
    );

    protected $casts = array(
        'color_descriptor' => 'json',
    );

    // ELASTIC SEARCH INDEX
    public static function boot()
    {
        parent::boot();

        static::created(function ($item) {
            $item->index();
        });

        static::updated(function ($item) {
            $item->index();
        });

        static::deleting(function ($item) {
            $item->removeImage();
            $item->collections()->detach();
        });

        static::deleted(function ($item) {

            $elastic_translatable = \App::make('ElasticTranslatableService');

            foreach (config('translatable.locales') as $locale) {
                $item->getElasticClient()->delete([
                   'index' => $elastic_translatable->getIndexForLocale($locale),
                   'type' => $item::ES_TYPE,
                   'id' => $item->id,
                ]);
            }
        });
    }

    public function descriptionUser()
    {
        return $this->belongsTo(\App\User::class, 'description_user_id');
    }

    public function authorities()
    {
        return $this->belongsToMany(\App\Authority::class, 'authority_item', 'item_id', 'authority_id')->withPivot('role');
    }

    public function collections()
    {
        return $this->belongsToMany(\App\Collection::class, 'collection_item', 'item_id', 'collection_id');
    }

{'fraction_non_alphanumeric': 0.14982125446863828, 'fraction_numerical': 0.0, 'mean_word_length': 2.046864686468647, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 90, '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': '1243264', 'n_tokens_mistral': 2861, 'n_tokens_neox': 2854, 'n_words': 499}