/** * Map the creator and changer to the document. * * @param Document $document * @param UserInterface $creator * @param UserInterface $changer */ private function mapCreatorAndChanger(Document $document, UserInterface $creator = null, UserInterface $changer = null) { $document->addField($this->factory->createField('changer', $changer ? $changer->getUsername() : null, 'string')); $document->addField($this->factory->createField('changer_id', $changer ? $changer->getId() : null, 'string')); $document->addField($this->factory->createField('creator', $creator ? $creator->getUsername() : null, 'string')); $document->addField($this->factory->createField('creator_id', $creator ? $creator->getId() : null, 'string')); }
/** * Adds the image to the search document. * * @param PreIndexEvent $event */ public function handlePreIndex(PreIndexEvent $event) { $metadata = $event->getMetadata(); $reflection = $metadata->getClassMetadata()->reflection; if (false === $reflection->isSubclassOf(FileVersionMeta::class) && $metadata->getName() !== FileVersionMeta::class) { return; } $document = $event->getDocument(); $subject = $event->getSubject(); $locale = $subject->getLocale(); $fileVersion = $subject->getFileVersion(); $file = $fileVersion->getFile(); $media = $file->getMedia(); // Do not try and get the image URL if the mime type is not in the // list of mime types for which thumbnails are generated. foreach ($this->thumbnailMimeTypes as $type) { if (fnmatch($type, $fileVersion->getMimeType())) { $document->setImageUrl($this->getImageUrl($media, $locale)); break; } } $document->addField($this->factory->createField('media_id', $media->getId())); $document->addField($this->factory->createField('media_mime', $fileVersion->getMimeType())); if ($collection = $media->getCollection()) { $document->addField($this->factory->createField('collection_id', $collection->getId())); } }
private function getContentField(PropertyMetadata $property) { $field = $this->factory->createMetadataExpression(sprintf('object.getStructure().%s.getValue()', $property->getName())); return $field; }