Exemplo n.º 1
0
 /**
  * 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];
 }
Exemplo n.º 2
0
 /**
  * get keys for (a set of) selected document types
  */
 public function postKeys()
 {
     // get the document types
     $documents = explode("|", Input::get('documents'));
     $searchComponent = new MediaSearchComponent();
     // store all keys in this array
     $docKeys = [];
     // go through each selected document type and get the keys
     foreach ($documents as $type) {
         // skip if value is empty
         if ($type == "") {
             continue;
         } elseif ($type == "all") {
             $units = Unit::select('content')->get();
         } else {
             // split the document type string so that we can get the project name from it.
             $type = explode('__', $type);
             // get the content of the units for this document type in this project
             // if the load on the system is too high limit this to e.g. 100 random units.
             $units = Unit::select('content')->where('project', $type[0])->where('documentType', $type[1])->get();
         }
         // get the keys for the units in this document type
         foreach ($units as $unit) {
             $unit->attributesToArray();
             $keys = $searchComponent->getKeys($unit['attributes']);
             $docKeys = array_unique(array_merge($docKeys, $keys));
         }
     }
     //		asort($keys);
     return $docKeys;
 }