Skip to content

Commit

Permalink
Merge pull request #2069 from biblibre/fulltext-search-new-events
Browse files Browse the repository at this point in the history
Add events to allow modules to select values used in fulltext search
  • Loading branch information
zerocrates authored Dec 14, 2023
2 parents 68b637c + c21ee43 commit 8390be4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion application/src/Api/Adapter/AbstractResourceEntityAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,15 +720,32 @@ public function getFulltextText($resource)
$services = $this->getServiceLocator();
$dataTypes = $services->get('Omeka\DataTypeManager');
$view = $services->get('ViewRenderer');
$eventManager = $this->getEventManager();

$criteria = Criteria::create()->where(Criteria::expr()->eq('isPublic', true));
$args = $eventManager->prepareArgs(['resource' => $resource, 'criteria' => $criteria]);
$event = new Event('api.get_fulltext_text.value_criteria', $this, $args);
$eventManager->triggerEvent($event);
$criteria = $args['criteria'];

$texts = [];
foreach ($resource->getValues()->matching($criteria) as $value) {
$valueRepresentation = new ValueRepresentation($value, $services);
$texts[] = $dataTypes->getForExtract($value)->getFulltextText($view, $valueRepresentation);
// Add value annotation text, if any.
$valueAnnotation = $value->getValueAnnotation();
if ($valueAnnotation) {
foreach ($valueAnnotation->getValues()->matching($criteria) as $value) {
$valueAnnotationCriteria = Criteria::create()->where(Criteria::expr()->eq('isPublic', true));
$args = $eventManager->prepareArgs([
'resource' => $resource,
'value' => $value,
'criteria' => $valueAnnotationCriteria,
]);
$event = new Event('api.get_fulltext_text.value_annotation_criteria', $this, $args);
$eventManager->triggerEvent($event);
$valueAnnotationCriteria = $args['criteria'];

foreach ($valueAnnotation->getValues()->matching($valueAnnotationCriteria) as $value) {
$valueRepresentation = new ValueRepresentation($value, $services);
$texts[] = $dataTypes->getForExtract($value)->getFulltextText($view, $valueRepresentation);
}
Expand Down

0 comments on commit 8390be4

Please sign in to comment.