public function getSearchFieldsAndValues($format, $domain) { $fields = array(); $fields['formats'] = array("text", "image", "video"); if (is_null($format)) { $domains = Entity::distinct('domain')->get(); $usersInvolvedInEntities = array_flatten(Entity::distinct('user_id')->get()->toArray()); } else { $domains = Entity::where('format', $format)->distinct('domain')->get(); $usersInvolvedInEntities = array_flatten(Entity::where('format', $format)->distinct('user_id')->get()->toArray()); if ($key = array_search($format, $fields['formats'])) { $value = $fields['formats'][$key]; unset($fields['formats'][$key]); array_unshift($fields['formats'], $value); } } if (is_null($domain)) { $documentTypes = Entity::where('format', $format)->distinct('documentType')->get(); } else { $documentTypes = Entity::where('format', $format)->where('domain', $domain)->distinct('documentType')->get(); $usersInvolvedInEntities = array_flatten(Entity::where('format', $format)->where('domain', $domain)->distinct('user_id')->get()->toArray()); } foreach ($usersInvolvedInEntities as $key => $user_id) { $fields['userAgents'][$key] = User::find($user_id); } $fields['domains'] = array_flatten($domains->toArray()); $fields['documentTypes'] = array_flatten($documentTypes->toArray()); return $fields; }
/** * Run the database counter seeds. * * @return void */ public function run() { Eloquent::unguard(); $this->command->info('Seeding all activities...'); $seeds = $this->getSeeds(Activity::distinct('_id')->get()); foreach ($seeds as $name => $seed) { $this->command->info('Seed: ' . $name . ' = ' . $seed); $counter = new Counter(); $counter['_id'] = $name; $counter['seq'] = $seed; $counter->save(); } $this->command->info('Seeding all entities...'); $seeds = $this->getSeeds(Entity::distinct('_id')->get()); foreach ($seeds as $name => $seed) { $this->command->info('Seed: ' . $name . ' = ' . $seed); $counter = new Counter(); $counter['_id'] = $name; $counter['seq'] = $seed; $counter->save(); } }
/** * refresh search index */ public function postRefreshindex() { $searchComponent = new MediaSearchComponent(); // amount of units to index per iteration $batchsize = 500; $from = Input::get('next'); $unitCount = Entity::whereIn('tags', ['unit'])->count(); // reset index on start if ($from == 0) { $searchComponent->clear(); } // reduce last batch to remaining units if ($from + $batchsize > $unitCount) { $batchsize = $unitCount - $from; } // all units in this range $units = Entity::distinct('_id')->where('tags', ['unit'])->skip($from)->take($batchsize)->get(); // get keys for each unit in this batch $allKeys = []; for ($i = $from; $i < $from + $batchsize; $i++) { // get data of unit $unit = Entity::where('_id', $units[$i][0])->first(); // map all properties into keys with formats $keys = $this->getKeys($unit->attributesToArray()); // merge keys with set of keys and get the right format (e.g. if it occurs both at string and int we treat all of them as a string foreach ($keys as $k => $v) { if (!array_key_exists($k, $allKeys)) { $allKeys[$k] = ['key' => $keys[$k]['key'], 'label' => $keys[$k]['label'], 'format' => $keys[$k]['format'], 'documents' => [$keys[$k]['document']]]; } else { $allKeys[$k]['format'] = $searchComponent->prioritizeFormat([$allKeys[$k]['format'], $keys[$k]['format']]); // add document type if its not in the list yet if (!in_array($keys[$k]['document'], $allKeys[$k]['documents'])) { array_push($allKeys[$k]['documents'], $keys[$k]['document']); } } } } $searchComponent->store($allKeys); return ['log' => $from . ' to ' . ($from + $batchsize) . ' of ' . $unitCount, 'next' => $from + $batchsize, 'last' => $unitCount]; }