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

Fixes Extracted Text not indexing in solr #767

Merged
merged 1 commit into from
Apr 1, 2020
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
22 changes: 22 additions & 0 deletions modules/islandora_text_extraction/islandora_text_extraction.module
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ function islandora_text_extraction_media_presave(MediaInterface $media) {
}
}

/**
* Implements hook_media_insert().
*/
function islandora_text_extraction_media_insert(MediaInterface $media) {
if ($media->bundle() != 'extracted_text') {
return;
}

\Drupal::service('islandora_text_extraction.search_reindexer')->reindexParent($media);
}

/**
* Implements hook_media_update().
*/
function islandora_text_extraction_media_update(MediaInterface $media) {
if ($media->bundle() != 'extracted_text') {
return;
}

\Drupal::service('islandora_text_extraction.search_reindexer')->reindexParent($media);
}

/**
* Implements hook_form_form_id_alter().
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
logger.channel.islandora_text_extraction:
parent: logger.channel_base
arguments: ['islandora_text_extraction']
islandora_text_extraction.search_reindexer:
class: Drupal\islandora_text_extraction\SearchReindexer
arguments: ['@islandora.utils', '@logger.channel.islandora_text_extraction']

65 changes: 65 additions & 0 deletions modules/islandora_text_extraction/src/SearchReindexer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Drupal\islandora_text_extraction;

use Drupal\islandora\IslandoraUtils;
use Drupal\media\MediaInterface;
use Psr\Log\LoggerInterface;

/**
* Creates a GeminiClient as a Drupal service.
*
* @package Drupal\islandora
*/
class SearchReindexer {

/**
* Islandora Utils.
*
* @var \Drupal\islandora\IslandoraUtils
*/
protected $utils;

/**
* Logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;

/**
* Constructor.
*
* @param \Drupal\islandora\IslandoraUtils $utils
* Islandora utils.
* @param \Psr\Log\LoggerInterface $logger
* The logger channel.
*/
public function __construct(IslandoraUtils $utils, LoggerInterface $logger) {
$this->utils = $utils;
$this->logger = $logger;
}

/**
* Reindexes parent node for a media. No-op if parent does not exist.
*
* @param Drupal\media\MediaInterface $media
* Media whose parent you want to reindex.
*/
public function reindexParent(MediaInterface $media) {
$parent = $this->utils->getParentNode($media);

if ($parent === NULL) {
return;
}

$this->logger->debug(
"Re-indexing parent node @nid for extracted text @mid using the search_api",
['@nid' => $parent->id(), '@mid' => $media->id()]
);

$parent->original = $parent;
search_api_entity_update($parent);
}

}