Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add way to get fulltext from media #2117

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
}
}