The basic idea of this class is to do the following: 1) The find methods retrieve a recursive set of filters, which define which content objects to retrieve from the database. Those may be combined using boolean operators. 2) This recursive criterion definition is visited into a query, which limits the content retrieved from the database. We might not be able to create sensible queries from all criterion definitions. 3) The query might be possible to optimize (remove empty statements), reduce singular and and or constructs… 4) Additionally we might need a post-query filtering step, which filters content objects based on criteria, which could not be converted in to database statements.
Inheritance: implements eZ\Publish\SPI\Search\Handler
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $bulkCount = $input->getArgument('bulk_count');
     // Indexing Content
     $totalCount = $this->getContentObjectsTotalCount($this->databaseHandler, ContentInfo::STATUS_PUBLISHED);
     $query = $this->databaseHandler->createSelectQuery();
     $query->select('id', 'current_version')->from('ezcontentobject')->where($query->expr->eq('status', ContentInfo::STATUS_PUBLISHED));
     $stmt = $query->prepare();
     $stmt->execute();
     $this->searchHandler->purgeIndex();
     $output->writeln('Indexing Content...');
     /* @var \Symfony\Component\Console\Helper\ProgressHelper $progress */
     $progress = $this->getHelperSet()->get('progress');
     $progress->start($output, $totalCount);
     $i = 0;
     do {
         $contentObjects = [];
         for ($k = 0; $k <= $bulkCount; ++$k) {
             if (!($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
                 break;
             }
             try {
                 $contentObjects[] = $this->persistenceHandler->contentHandler()->load($row['id'], $row['current_version']);
             } catch (NotFoundException $e) {
                 $this->logWarning($output, $progress, "Could not load current version of Content with id {$row['id']}, so skipped for indexing. Full exception: " . $e->getMessage());
             }
         }
         $this->searchHandler->bulkIndex($contentObjects, function (Content $content, NotFoundException $e) use($output, $progress) {
             $this->logWarning($output, $progress, 'Content with id ' . $content->versionInfo->id . ' has missing data, so skipped for indexing. Full exception: ' . $e->getMessage());
         });
         $progress->advance($k);
     } while (($i += $bulkCount) < $totalCount);
     $progress->finish();
 }
Ejemplo n.º 2
0
 /**
  * Returns all content objects of $contentTypeId
  *
  * @param mixed $contentTypeId
  *
  * @return \eZ\Publish\SPI\Persistence\Content\ContentInfo[]
  */
 protected function loadContentObjects($contentTypeId)
 {
     $result = $this->searchHandler->findContent(new Query(array('filter' => new Criterion\ContentTypeId($contentTypeId))));
     $contentInfo = array();
     foreach ($result->searchHits as $hit) {
         $contentInfo[] = $hit->valueObject;
     }
     return $contentInfo;
 }
Ejemplo n.º 3
0
 /**
  * Create search engine index.
  *
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param int $iterationCount
  * @param bool $commit commit changes after each iteration
  */
 public function createSearchIndex(OutputInterface $output, $iterationCount, $commit)
 {
     $output->writeln('Creating Legacy Search Engine Index...');
     if (!$this->searchHandler instanceof SearchHandler) {
         throw new RuntimeException(sprintf('Expected to find an instance of %s, but found %s', SearchHandler::class, get_class($this->searchHandler)));
     }
     $stmt = $this->getContentDbFieldsStmt(['count(id)']);
     $totalCount = intval($stmt->fetchColumn());
     $stmt = $this->getContentDbFieldsStmt(['id', 'current_version']);
     $this->searchHandler->purgeIndex();
     $progress = new ProgressBar($output);
     $progress->start($totalCount);
     $i = 0;
     do {
         $contentObjects = [];
         for ($k = 0; $k <= $iterationCount; ++$k) {
             if (!($row = $stmt->fetch(PDO::FETCH_ASSOC))) {
                 break;
             }
             try {
                 $contentObjects[] = $this->persistenceHandler->contentHandler()->load($row['id'], $row['current_version']);
             } catch (NotFoundException $e) {
                 $this->logWarning($progress, "Could not load current version of Content with id {$row['id']}, so skipped for indexing. Full exception: " . $e->getMessage());
             }
         }
         foreach ($contentObjects as $content) {
             try {
                 $this->searchHandler->indexContent($content);
             } catch (NotFoundException $e) {
                 // Ignore content objects that have some sort of missing data on it
                 $this->logWarning($progress, 'Content with id ' . $content->versionInfo->id . ' has missing data, so skipped for indexing. Full exception: ' . $e->getMessage());
             }
         }
         $progress->advance($k);
     } while (($i += $iterationCount) < $totalCount);
     $progress->finish();
     $output->writeln('');
     $output->writeln('Finished creating Legacy Search Engine Index');
 }