![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/ts.corals.io/corals-api/Corals/core/Foundation/Search/ |
<?php namespace Corals\Foundation\Search; use Illuminate\Database\Eloquent\Model; class Indexer { /** * @param \Illuminate\Database\Eloquent\Model $model */ public function indexModel(Model $model) { $model->indexRecord(); } public function unIndexOneByClass($class, $id) { $record = IndexedRecord::where('indexable_id', $id)->where('indexable_type', $class); if ($record->exists) { $record->delete(); } } public function indexOneByClass($class, $id) { $model = call_user_func(array($class, 'find'), $id); if (in_array(Indexable::class, class_uses($model), true)) { $this->indexModel($model); } } public function indexAllByClass($class) { $model = new $class; $self = $this; if (in_array(Indexable::class, class_uses($model), true)) { $model->chunk(100, function ($chunk) use ($self) { foreach ($chunk as $modelRecord) { $self->indexModel($modelRecord); } }); } } }