Skip to content

Commit

Permalink
Add way to get fulltext from media (#2117)
Browse files Browse the repository at this point in the history
(fix #2116)
  • Loading branch information
jimsafley authored Nov 30, 2023
1 parent 5526e66 commit 18fdc91
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
13 changes: 13 additions & 0 deletions application/src/Api/Adapter/MediaAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Doctrine\ORM\QueryBuilder;
use Omeka\Api\Request;
use Omeka\Media\Ingester\MutableIngesterInterface;
use Omeka\Media\Renderer\FulltextSearchableInterface;
use Omeka\Entity\EntityInterface;
use Omeka\Entity\Item;
use Omeka\Media\Ingester\Fallback;
Expand Down Expand Up @@ -200,4 +201,16 @@ public function preprocessBatchUpdate(array $data, Request $request)

return $data;
}

public function getFulltextText($resource)
{
$renderer = $this->getServiceLocator()
->get('Omeka\Media\Renderer\Manager')
->get($resource->getRenderer());
$fulltextText = parent::getFulltextText($resource);
if ($renderer instanceof FulltextSearchableInterface) {
$fulltextText .= ' ' . $renderer->getFulltextText($this->getRepresentation($resource));
}
return $fulltextText;
}
}
15 changes: 15 additions & 0 deletions application/src/Media/Renderer/FulltextSearchableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace Omeka\Media\Renderer;

use Omeka\Api\Representation\MediaRepresentation;

interface FulltextSearchableInterface
{
/**
* Get the the text of the passed media.
*
* @param Media $media
* @return string
*/
public function getFulltextText(MediaRepresentation $media);
}
8 changes: 7 additions & 1 deletion application/src/Media/Renderer/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
use Omeka\Api\Representation\MediaRepresentation;
use Laminas\View\Renderer\PhpRenderer;

class Html implements RendererInterface
class Html implements RendererInterface, FulltextSearchableInterface
{
public function render(PhpRenderer $view, MediaRepresentation $media,
array $options = []
) {
$data = $media->mediaData();
return $data['html'];
}

public function getFulltextText(MediaRepresentation $media)
{
$data = $media->mediaData();
return strip_tags($data['html']);
}
}

0 comments on commit 18fdc91

Please sign in to comment.