Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function reindex($class = null, $offset = null, $limit = null)
 {
     if (null === $class) {
         $this->clearAllSearchIndexes();
         $entityNames = $this->mapper->getEntities([Mode::NORMAL, Mode::WITH_DESCENDANTS]);
     } else {
         $entityNames = [$class];
         $mode = $this->mapper->getEntityModeConfig($class);
         if ($mode === Mode::WITH_DESCENDANTS) {
             $entityNames = array_merge($entityNames, $this->mapper->getRegisteredDescendants($class));
         } elseif ($mode === Mode::ONLY_DESCENDANTS) {
             $entityNames = $this->mapper->getRegisteredDescendants($class);
         }
         if (null === $offset && null === $limit || $offset === 0 && $limit) {
             foreach ($entityNames as $class) {
                 $this->clearSearchIndexForEntity($class);
             }
         }
     }
     // index data by mapping config
     $recordsCount = 0;
     while ($class = array_shift($entityNames)) {
         $itemsCount = $this->reindexSingleEntity($class, $offset, $limit);
         $recordsCount += $itemsCount;
     }
     return $recordsCount;
 }
Beispiel #2
0
 /**
  * Apply special behavior of class inheritance processing
  *
  * @param Query $query
  */
 protected function applyModesBehavior(Query $query)
 {
     // process abstract indexes
     // make hashes increasing performance
     $fromParts = (array) $query->getFrom();
     $fromHash = array_combine($fromParts, $fromParts);
     $aliases = $this->mapper->getEntitiesListAliases();
     $aliasesHash = array_flip($aliases);
     if (!isset($fromHash['*'])) {
         foreach ($fromParts as $part) {
             $entityName = $part;
             $isAlias = false;
             if (isset($aliasesHash[$part])) {
                 // find real name by alias
                 $entityName = $aliasesHash[$part];
                 $isAlias = true;
             }
             $mode = $this->mapper->getEntityModeConfig($entityName);
             $descendants = $this->mapper->getRegisteredDescendants($entityName);
             if (false !== $descendants) {
                 // add descendants to from clause
                 foreach ($descendants as $fromPart) {
                     if ($isAlias) {
                         $fromPart = $aliases[$fromPart];
                     }
                     if (!isset($fromHash[$fromPart])) {
                         $fromHash[$fromPart] = $fromPart;
                     }
                 }
             }
             if ($mode === Mode::ONLY_DESCENDANTS) {
                 unset($fromHash[$part]);
             }
         }
     }
     $collectedParts = array_values($fromHash);
     if ($collectedParts !== $fromParts) {
         $query->from($collectedParts);
     }
 }