From 0407913e9df17b8c7472bb95fb2d0adf2f5ccc96 Mon Sep 17 00:00:00 2001
From: mshroom <32199029+mshroom@users.noreply.github.com>
Date: Mon, 25 May 2026 10:42:17 +0300
Subject: [PATCH] LIDO, FORWARD: Index colours
---
src/RecordManager/Finna/Record/Forward.php | 12 +++
src/RecordManager/Finna/Record/Lido.php | 76 ++++++++++++++-----
.../Finna/Record/ForwardTest.php | 3 +
.../Finna/Record/LidoTest.php | 10 +++
tests/fixtures/Finna/record/musketti2.xml | 16 ++++
5 files changed, 99 insertions(+), 18 deletions(-)
diff --git a/src/RecordManager/Finna/Record/Forward.php b/src/RecordManager/Finna/Record/Forward.php
index c5b3324d..7d80b90f 100644
--- a/src/RecordManager/Finna/Record/Forward.php
+++ b/src/RecordManager/Finna/Record/Forward.php
@@ -193,6 +193,8 @@ public function toSolrArray(?Database $db = null)
$data['subtitle_lng_str_mv']
= $this->metadataUtils->normalizeLanguageStrings($subtitles);
+ $data['color_str_mv'] = $this->getColors();
+
return $data;
}
@@ -284,6 +286,16 @@ public function getSubtitleLanguages()
return $result;
}
+ /**
+ * Return colors.
+ *
+ * @return array
+ */
+ protected function getColors(): array
+ {
+ return $this->getProductionEventAttribute('elokuva-alkupvari');
+ }
+
/**
* Get all authors or authors by relator codes.
*
diff --git a/src/RecordManager/Finna/Record/Lido.php b/src/RecordManager/Finna/Record/Lido.php
index 610dfa38..3e1a9bd5 100644
--- a/src/RecordManager/Finna/Record/Lido.php
+++ b/src/RecordManager/Finna/Record/Lido.php
@@ -165,6 +165,23 @@ class Lido extends \RecordManager\Base\Record\Lido
'kiinteistörekisteri' => 'kiinteistötunnus',
];
+ /**
+ * Classification types which should be excluded from classifications.
+ *
+ * @var array
+ */
+ protected $excludedClassifications = ['language', 'colour content', 'color content'];
+
+ /**
+ * Materials/techniques types which should be included in colors
+ *
+ * @var array
+ */
+ protected $colorTypes = [
+ 'colour name', 'color name', 'väri',
+ 'http://terminology.lido-schema.org/lido00479',
+ ];
+
/**
* Hierarchy fields included in allfields.
*
@@ -256,6 +273,7 @@ public function toSolrArray(?Database $db = null)
// Keep classification_str_mv for backward-compatibility for now
$data['classification_txt_mv'] = $data['classification_str_mv']
= $this->getClassifications();
+ $data['color_str_mv'] = $this->getColors();
$data['exhibition_str_mv'] = $this->getEventNames('näyttely');
$data['category_str_mv'] = $this->getCategories();
@@ -1930,21 +1948,56 @@ protected function parseLidoDateRange($input)
/**
* Return the classifications.
*
+ * @param array $include Classification types to include.
+ *
* @link http://www.lido-schema.org/schema/v1.0/lido-v1.0-schema-listing.html
* #objectClassificationWrap
* @return array
*/
- protected function getClassifications()
+ protected function getClassifications(array $include = []): array
{
$results = [];
foreach (
$this->doc->lido->descriptiveMetadata->objectClassificationWrap
->classificationWrap->classification ?? [] as $classification
) {
- $type = trim((string)$classification->attributes()->type);
- if ('language' !== $type && !empty($classification->term)) {
+ $type = mb_strtolower(trim((string)($classification->attributes()->type ?? '')), 'UTF-8');
+ $accepted = $include ? in_array($type, $include) : !in_array($type, $this->excludedClassifications);
+ if ($accepted) {
foreach ($classification->term as $term) {
- $results[] = (string)$term;
+ if ($trimmed = trim((string)$term)) {
+ $results[] = $trimmed;
+ }
+ }
+ }
+ }
+ return $results;
+ }
+
+ /**
+ * Return colors.
+ *
+ * @return array
+ */
+ protected function getColors(): array
+ {
+ // For backward compatibility: Include color content classifications
+ $results = $this->getClassifications(['colour content', 'color content']);
+ foreach (
+ $this->doc->lido->descriptiveMetadata->objectIdentificationWrap->objectMaterialsTechWrap
+ ->objectMaterialsTechSet ?? [] as $set
+ ) {
+ foreach ($set->materialsTech as $materialsTech) {
+ foreach ($materialsTech->termMaterialsTech as $termMaterialsTech) {
+ $type = mb_strtolower(trim((string)($termMaterialsTech->attributes()->type ?? '')), 'UTF-8');
+ if (!in_array($type, $this->colorTypes)) {
+ continue;
+ }
+ foreach ($termMaterialsTech->term as $term) {
+ if ($trimmed = trim((string)$term)) {
+ $results[] = $trimmed;
+ }
+ }
}
}
}
@@ -2341,20 +2394,7 @@ protected function isFreeOnline(): bool
*/
protected function getLanguages(): array
{
- $classifications = $this->doc->lido->descriptiveMetadata
- ->objectClassificationWrap->classificationWrap->classification ?? [];
- $result = [];
- foreach ($classifications as $classification) {
- $type = trim((string)$classification->attributes()->type);
- if ('language' === $type) {
- foreach ($classification->term as $lang) {
- if ($trimmed = trim((string)$lang)) {
- $result[] = $trimmed;
- }
- }
- }
- }
- return array_unique($result);
+ return array_unique($this->getClassifications(['language']));
}
/**
diff --git a/tests/RecordManagerTest/Finna/Record/ForwardTest.php b/tests/RecordManagerTest/Finna/Record/ForwardTest.php
index 83371159..8347d232 100644
--- a/tests/RecordManagerTest/Finna/Record/ForwardTest.php
+++ b/tests/RecordManagerTest/Finna/Record/ForwardTest.php
@@ -1444,6 +1444,9 @@ public function testForward1()
2 => 'Asuintalot, omakotitalot, villat ja kartanot',
3 => 'Maatilat, pientilat, mökit, torpat, maatalousrakennukset ja aitat',
],
+ 'color_str_mv' => [
+ 'väri',
+ ],
];
$this->compareArray($expected, $fields, 'toSolrArray');
diff --git a/tests/RecordManagerTest/Finna/Record/LidoTest.php b/tests/RecordManagerTest/Finna/Record/LidoTest.php
index d258df46..72f310b3 100644
--- a/tests/RecordManagerTest/Finna/Record/LidoTest.php
+++ b/tests/RecordManagerTest/Finna/Record/LidoTest.php
@@ -221,6 +221,7 @@ public function testMusketti2()
'fi',
'sv',
'en',
+ 'mustavalkoinen',
'Imatrankoski',
'Imatra fors',
'33,1.',
@@ -240,6 +241,9 @@ public function testMusketti2()
'Kalasatama',
'Capellanranta 1 ja 3 välillä',
'Helsinki',
+ 'keltainen',
+ 'yellow',
+ 'punainen',
'valmistus',
'http://urn.fi/URN:NBN:fi:au:finaf:000173713',
'https://isni.org/isni/0000000073500621',
@@ -290,6 +294,12 @@ public function testMusketti2()
'classification_txt_mv' => [
'valokuva',
],
+ 'color_str_mv' => [
+ 'mustavalkoinen',
+ 'keltainen',
+ 'yellow',
+ 'punainen',
+ ],
'exhibition_str_mv' => [],
'main_date_str' => '1897',
'main_date' => '1897-01-01T00:00:00Z',
diff --git a/tests/fixtures/Finna/record/musketti2.xml b/tests/fixtures/Finna/record/musketti2.xml
index 72ac8654..365a3525 100644
--- a/tests/fixtures/Finna/record/musketti2.xml
+++ b/tests/fixtures/Finna/record/musketti2.xml
@@ -23,6 +23,9 @@
en
+
+ mustavalkoinen
+
@@ -113,6 +116,19 @@
+
+
+
+
+ keltainen
+ yellow
+
+
+ punainen
+
+
+
+