From 6c7034a0902306bb30d7a44acd1d68db3d21d69c Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Tue, 12 May 2026 15:52:37 +0300 Subject: [PATCH 01/14] Add facet field for container-title --- conf/datasources.ini.sample.finna | 6 + src/RecordManager/Base/Solr/SolrUpdater.php | 2 +- src/RecordManager/Finna/Record/Ead.php | 17 + src/RecordManager/Finna/Record/Ead3.php | 17 + src/RecordManager/Finna/Solr/SolrUpdater.php | 70 ++++ .../Finna/Record/Ead3Test.php | 1 + .../Finna/Solr/SolrUpdaterTest.php | 349 +++++++++++++++++- tests/fixtures/Finna/record/ead.xml | 101 +++++ .../fixtures/Finna/record/lido_hierarchy.xml | 37 ++ tests/fixtures/Finna/record/marc4.xml | 6 +- tests/fixtures/Finna/record/marc5.xml | 3 + tests/fixtures/Finna/record/marc6.xml | 3 + tests/fixtures/Finna/record/musketti2.xml | 5 + tests/fixtures/Finna/record/musketti3.xml | 314 ++++++++++++++++ 14 files changed, 907 insertions(+), 24 deletions(-) create mode 100644 tests/fixtures/Finna/record/ead.xml create mode 100644 tests/fixtures/Finna/record/lido_hierarchy.xml create mode 100644 tests/fixtures/Finna/record/musketti3.xml diff --git a/conf/datasources.ini.sample.finna b/conf/datasources.ini.sample.finna index 2770221a..ea6fe831 100644 --- a/conf/datasources.ini.sample.finna +++ b/conf/datasources.ini.sample.finna @@ -7,3 +7,9 @@ ; prepend = whether to prepend 003 to the field. 0 = no (default), 1 = yes. ; Example: ;driverParams[] = "recordLinkingIdFields=\"001,1:035a,0:999c,0\"" + +;[examples] +; Option to override default field used to populate container_title_str_mv field. +; Other formats populates the container_title_str_mv from hierarchy_parent_title field +; and EAD3 populates it from hierarchy_top_title field. +;driverParams[] = "containerTitleField=hierarchy_top_title" diff --git a/src/RecordManager/Base/Solr/SolrUpdater.php b/src/RecordManager/Base/Solr/SolrUpdater.php index 81c53b00..96bc05f2 100644 --- a/src/RecordManager/Base/Solr/SolrUpdater.php +++ b/src/RecordManager/Base/Solr/SolrUpdater.php @@ -332,7 +332,7 @@ class SolrUpdater 'dewey-sort', 'illustrated', 'first_indexed', 'last-indexed', - 'container_title', 'container_volume', 'container_issue', + 'container_title', 'container_title_str_mv', 'container_volume', 'container_issue', 'container_start_page', 'container_reference', ]; diff --git a/src/RecordManager/Finna/Record/Ead.php b/src/RecordManager/Finna/Record/Ead.php index cb3e88d4..25d820ac 100644 --- a/src/RecordManager/Finna/Record/Ead.php +++ b/src/RecordManager/Finna/Record/Ead.php @@ -443,4 +443,21 @@ protected function getTopicIDs(): array $result = parent::getTopicIDs(); return $this->addNamespaceToAuthorityIds($result, 'topic'); } + + /** + * Add hierarchy fields. Must be called after title is present in the array. + * + * @param array $data Reference to the target array + * + * @return void + */ + protected function addHierarchyFields(&$data): void + { + parent::addHierarchyFields($data); + $containerTitleFacetField = $this->config['Solr Fields']['container_title_str_mv'] ?? 'container_title_str_mv'; + $hierarchyTopTitleField = $this->config['Solr Fields']['hierarchy_top_title'] ?? 'hierarchy_top_title'; + if (isset($data[$hierarchyTopTitleField])) { + $data[$containerTitleFacetField] = (array)$data[$hierarchyTopTitleField]; + } + } } diff --git a/src/RecordManager/Finna/Record/Ead3.php b/src/RecordManager/Finna/Record/Ead3.php index ec13e9f3..9fda1203 100644 --- a/src/RecordManager/Finna/Record/Ead3.php +++ b/src/RecordManager/Finna/Record/Ead3.php @@ -1387,4 +1387,21 @@ protected function getResourceIdentifiers(): array $fileIds = [...$ids, ...$fileIds]; return $this->resultCache[$cacheKey] = compact('ids', 'fileIds'); } + + /** + * Add hierarchy fields. Must be called after title is present in the array. + * + * @param array $data Reference to the target array + * + * @return void + */ + protected function addHierarchyFields(&$data): void + { + parent::addHierarchyFields($data); + $containerTitleFacetField = $this->config['Solr Fields']['container_title_str_mv'] ?? 'container_title_str_mv'; + $hierarchyTopTitleField = $this->config['Solr Fields']['hierarchy_top_title'] ?? 'hierarchy_top_title'; + if (isset($data[$hierarchyTopTitleField])) { + $data[$containerTitleFacetField] = (array)$data[$hierarchyTopTitleField]; + } + } } diff --git a/src/RecordManager/Finna/Solr/SolrUpdater.php b/src/RecordManager/Finna/Solr/SolrUpdater.php index 85b501f1..6a3946c7 100644 --- a/src/RecordManager/Finna/Solr/SolrUpdater.php +++ b/src/RecordManager/Finna/Solr/SolrUpdater.php @@ -29,7 +29,16 @@ namespace RecordManager\Finna\Solr; +use RecordManager\Base\Database\DatabaseInterface as Database; +use RecordManager\Base\Enrichment\PluginManager as EnrichmentPluginManager; +use RecordManager\Base\Http\HttpService as HttpService; use RecordManager\Base\Record\AbstractRecord; +use RecordManager\Base\Record\PluginManager as RecordPluginManager; +use RecordManager\Base\Settings\Ini; +use RecordManager\Base\Utils\FieldMapper; +use RecordManager\Base\Utils\Logger; +use RecordManager\Base\Utils\MetadataUtils; +use RecordManager\Base\Utils\WorkerPoolManager; use function is_callable; @@ -46,6 +55,64 @@ */ class SolrUpdater extends \RecordManager\Base\Solr\SolrUpdater { + /** + * Container title facet field + * + * @var string + */ + protected string $containerTitleFacetField = 'container_title_str_mv'; + + /** + * Constructor + * + * @param array $config Main configuration + * @param array $dataSourceConfig Data source settings + * @param ?Database $db Database connection + * @param Logger $log Logger + * @param RecordPluginManager $recordPM Record plugin manager + * @param EnrichmentPluginManager $enrichmentPM Enrichment plugin manager + * @param HttpService $httpService HTTP service + * @param Ini $configReader Configuration reader + * @param FieldMapper $fieldMapper Field mapper + * @param MetadataUtils $metadataUtils Metadata utilities + * @param WorkerPoolManager $workerPoolManager Worker pool manager + * + * @throws \Exception + * + * @psalm-suppress DuplicateArrayKey + */ + public function __construct( + array $config, + array $dataSourceConfig, + ?Database $db, + Logger $log, + RecordPluginManager $recordPM, + EnrichmentPluginManager $enrichmentPM, + HttpService $httpService, + Ini $configReader, + FieldMapper $fieldMapper, + MetadataUtils $metadataUtils, + WorkerPoolManager $workerPoolManager + ) { + parent::__construct( + $config, + $dataSourceConfig, + $db, + $log, + $recordPM, + $enrichmentPM, + $httpService, + $configReader, + $fieldMapper, + $metadataUtils, + $workerPoolManager + ); + $fields = $config['Solr Fields'] ?? []; + if (isset($fields['container_title_str_mv'])) { + $this->containerTitleFacetField = $fields['container_title_str_mv']; + } + } + /** * Add extra fields from settings etc. and map the values * @@ -71,6 +138,9 @@ protected function augmentAndProcessFields( $data['catalog_date'] = $date; } } + if (!isset($data[$this->containerTitleFacetField]) && isset($data[$this->hierarchyParentTitleField])) { + $data[$this->containerTitleFacetField] = $data[$this->hierarchyParentTitleField]; + } } /** diff --git a/tests/RecordManagerTest/Finna/Record/Ead3Test.php b/tests/RecordManagerTest/Finna/Record/Ead3Test.php index 187896bf..59ed4194 100644 --- a/tests/RecordManagerTest/Finna/Record/Ead3Test.php +++ b/tests/RecordManagerTest/Finna/Record/Ead3Test.php @@ -744,6 +744,7 @@ public function testSKS(string $addIdToHierarchyTitle, ?string $expectedTitleInH 'hierarchy_sequence' => '0000003', 'hierarchy_parent_id' => '237990354_238008149', 'hierarchy_parent_title' => 'Tekstit/Gustaf Edvard Sundvallin kokoelma', + 'container_title_str_mv' => ['Gustaf Edvard Sundvallin kokoelma'], 'unit_daterange' => '[1881-01-01 TO 1881-12-31]', 'search_daterange_mv' => [ '[1881-01-01 TO 1881-12-31]', diff --git a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php index 37f6b4ef..b34ed983 100644 --- a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php +++ b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php @@ -31,6 +31,8 @@ namespace RecordManagerTest\Finna\Solr; use ArrayIterator; +use Generator; +use PHPUnit\Framework\MockObject\MockObject; use RecordManager\Base\Database\DatabaseInterface; use RecordManager\Base\Database\MongoDatabase; use RecordManager\Base\Enrichment\PluginManager as EnrichmentPluginManager; @@ -42,6 +44,7 @@ use RecordManager\Base\Utils\Logger; use RecordManager\Base\Utils\MetadataUtils; use RecordManager\Base\Utils\WorkerPoolManager; +use RecordManager\Finna\Record\Ead; use RecordManager\Finna\Record\Marc; use RecordManager\Finna\Solr\SolrUpdater; use RecordManager\Finna\Utils\FieldMapper; @@ -95,6 +98,10 @@ class SolrUpdaterTest extends \PHPUnit\Framework\TestCase 'marc_format_sub.map,regexp', ], ], + 'tost' => [ + 'institution' => 'tost', + 'format' => 'ead', + ], ]; /** @@ -140,7 +147,6 @@ function ($format, $data, $oaiID, $source, $extraData = []) use ($record) { 'normalized_data' => null, 'host_record_id' => 'test.1', ]; - $params = [ 'host_record_id' => [ '$in' => array_values($dbRecord['linking_id']), @@ -169,18 +175,13 @@ function ($format, $data, $oaiID, $source, $extraData = []) use ($record) { 'date' => '2025-01-01', ], ]); - $recordMap = [ - [$params, [], $records[0]], - ]; + $database = $this->getDatabase($records, $params); $dsOverride = [ 'test' => [ 'mergeMultiLevelParts' => true, 'componentParts' => 'merge_all', ], ]; - $database = $this->getMockBuilder(MongoDatabase::class)->disableOriginalConstructor()->getMock(); - $database->expects($this->any())->method('findRecord')->willReturnMap($recordMap); - $database->expects($this->any())->method('findRecords')->willReturn($records); $solrUpdater = $this->getSolrUpdater( dsConfigOverrides: $dsOverride, database: $database @@ -200,6 +201,10 @@ function ($format, $data, $oaiID, $source, $extraData = []) use ($record) { 'code' => 'a', 'data' => 'part_1', ], + [ + 'code' => 'e', + 'data' => 'Component part title 1', + ], [ 'code' => 'h', 'data' => 'fin', @@ -215,6 +220,10 @@ function ($format, $data, $oaiID, $source, $extraData = []) use ($record) { 'code' => 'a', 'data' => 'part_2', ], + [ + 'code' => 'e', + 'data' => 'Component part title 2', + ], [ 'code' => 'h', 'data' => 'fin', @@ -227,16 +236,297 @@ function ($format, $data, $oaiID, $source, $extraData = []) use ($record) { $this->assertEquals($expected, $fields); } + /** + * Test single record processing data provider + * + * @return Generator + */ + public static function getTestProcessSingleRecordData(): Generator + { + $date = strtotime('2020-10-20 13:01:00'); + yield 'Test single marc record with container title field' => [ + [ + '_id' => '123', + 'oai_id' => '', + 'linking_id' => [ + '010101', + ], + 'host_record_id' => 'test123', + 'source_id' => 'test', + 'deleted' => false, + 'created' => $date, + 'updated' => $date, + 'date' => $date, + 'format' => 'marc', + 'original_data' => 'record/marc5.xml', + 'normalized_data' => null, + ], + [ + 'record_format' => 'marc', + 'allfields' => [ + 'Component part title 1', + 'Test string', + 'Test parent string', + ], + 'format' => 'Book/Book', + 'illustrated' => 'Not Illustrated', + 'language' => [ + 'fin', + ], + 'publishDate' => [ + '2013', + ], + 'publishDateRange' => [ + '[2013-01-01 TO 2013-12-31]', + ], + 'publishDateSort' => '2013', + 'title_alt' => [ + 'Component part title 1', + ], + 'title_full' => 'Component part title 1', + 'title_short' => 'Component part title 1', + 'title_sort' => 'component part title 1', + 'title' => 'Component part title 1', + 'main_date_str' => '2013', + 'main_date' => '2013-01-01T00:00:00Z', + 'search_daterange_mv' => [ + '[2013-01-01 TO 2013-12-31]', + ], + 'publication_daterange' => '[2013-01-01 TO 2013-12-31]', + 'major_genre_str_mv' => 'nonfiction', + 'source_str_mv' => 'test', + 'datasource_str_mv' => [ + 'test', + ], + 'format_ext_str_mv' => 'Book/Book', + 'linking_id_str_mv' => [ + '010101', + ], + 'id' => '123', + 'institution' => 'test', + 'first_indexed' => '1970-01-01T00:00:00Z', + 'last_indexed' => '1970-01-01T00:00:00Z', + 'catalog_date' => '1970-01-01T00:00:00Z', + 'hierarchy_parent_id' => [ + 'test123', + ], + 'hierarchy_parent_title' => [ + 'Host record title 1', + ], + 'container_title' => 'Host record title 1', + 'container_title_str_mv' => [ + 'Host record title 1', + ], + ], + ]; + + yield 'Test single ead record with container title field' => [ + [ + '_id' => 'test456', + 'oai_id' => '', + 'linking_id' => [], + 'source_id' => 'tost', + 'deleted' => false, + 'created' => $date, + 'updated' => $date, + 'date' => $date, + 'format' => 'ead', + 'original_data' => 'record/ead.xml', + 'normalized_data' => null, + ], + [ + 'record_format' => 'ead', + 'allfields' => [ + 'blorf mipmip zaarl frrrp tikka meowzorp flibbin 1977 glarp', + 'mrrrp-blib-zoink', + 'zz-ploof-9911', + 'fiftypurr snorfle meep', + 'gribble snarrk floomtar wubbadee', + 'grk', + 'fnrr', + 'Kralloo Mipsten', + 'Snerpaloosi Instiploop', + 'flarpo 1', + 'glimfadoo 15 snarr Väinö Talas blorptik Floridana snooflepuff 5+5 min floof cutoff', + 'blip/intervuu', + 'Yhdysblat', + '11.11111, 22.22222', + 'Asikblar', + '33.33333, 44.44444', + 'Päijät-Hömp', + '55.55555, 66.66666', + 'Helsinkloof', + '77.77777, 88.88888', + 'Uusimrr', + '99.99999, -11.11111', + 'Clevorland', + '-22.22222, 33.33333', + 'Detroink', + '-44.44444, 55.55555', + 'Montablaa', + '-66.66666, 77.77777', + 'Duluthnoo', + '-88.88888, 99.99999', + 'Fort Loodle', + '12.34567, -76.54321', + 'Lake Worf', + 'mootlik', + 'sirtooz', + 'sirtiloot', + 'ulkosnarf', + 'amerisnarf', + 'floridansnarf', + 'eläkeblorp', + 'työbloop', + 'työnteek', + 'työväää', + 'talonrakblip', + 'järjestööf', + 'CC BY 4.0', + 'blorptik snoofle 1977-1978', + 'snarfloota kokoelma', + ], + 'author2' => [ + 'Kralloo Mipsten', + ], + 'description' => 'glimfadoo 15 snarr Väinö Talas blorptik Floridana snooflepuff 5+5 min floof cutoff', + 'format' => 'blip/intervuu', + 'institution' => 'Snerpaloosi Instiploop', + 'language' => ['grk', 'fnrr'], + 'physical' => ['fiftypurr snorfle meep'], + 'title_full' => 'mrrrp-blib-zoink blorf mipmip zaarl frrrp tikka meowzorp flibbin 1977 glarp (9911)', + 'title_short' => 'blorf mipmip zaarl frrrp tikka', + 'title_sort' => 'blorf mipmip zaarl frrrp tikka meowzorp ', + 'title_sub' => 'mrrrp-blib-zoink', + 'title' => 'mrrrp-blib-zoink blorf mipmip zaarl frrrp tikka meowzorp flibbin 1977 glarp (9911)', + 'topic_facet' => [ + 'mootlik','sirtooz','sirtiloot','ulkosnarf','amerisnarf','floridansnarf', + 'eläkeblorp','työbloop','työnteek','työväää','talonrakblip','järjestööf', + ], + 'topic' => [ + 'mootlik','sirtooz','sirtiloot','ulkosnarf','amerisnarf','floridansnarf', + 'eläkeblorp','työbloop','työnteek','työväää','talonrakblip','järjestööf', + ], + 'location_geo' => 'POINT(-76.54321 12.34567)', + 'center_coords' => '-76.54321 12.34567', + 'geographic_facet' => [ + 'Yhdysblat','Asikblar','Päijät-Hömp','Helsinkloof','Uusimrr','Clevorland', + 'Detroink','Montablaa','Duluthnoo','Fort Loodle','Lake Worf', + ], + 'geographic' => [ + 'Yhdysblat','Asikblar','Päijät-Hömp','Helsinkloof','Uusimrr','Clevorland', + 'Detroink','Montablaa','Duluthnoo','Fort Loodle','Lake Worf', + ], + 'hierarchytype' => 'Default', + 'hierarchy_top_id' => 'tost.272', + 'hierarchy_top_title' => 'blorptik snoofle 1977-1978', + 'hierarchy_sequence' => '0000020', + 'hierarchy_parent_id' => 'tost.272', + 'hierarchy_parent_title' => 'snarfloota kokoelma', + 'title_in_hierarchy' => 'mrrrp-blib-zoink mrrrp-blib-zoink' + . ' blorf mipmip zaarl frrrp tikka meowzorp flibbin 1977 glarp', + 'container_title_str_mv' => ['blorptik snoofle 1977-1978'], + 'unit_daterange' => '[9911-01-01 TO 9911-12-31]', + 'search_daterange_mv' => '[9911-01-01 TO 9911-12-31]', + 'main_date_str' => '9911', + 'main_date' => '9911-01-01T00:00:00Z', + 'hierarchy_sequence_str' => '0000020', + 'source_str_mv' => 'Snerpaloosi Instiploop', + 'datasource_str_mv' => 'tost', + 'online_boolean' => '1', + 'online_str_mv' => 'Snerpaloosi Instiploop', + 'free_online_boolean' => '1', + 'free_online_str_mv' => 'Snerpaloosi Instiploop', + 'identifier' => 'mrrrp-blib-zoink', + 'material' => "\n \n ", + 'usage_rights_str_mv' => ['CC BY 4.0'], + 'usage_rights_ext_str_mv' => ['CC BY 4.0'], + 'author_facet' => ['Kralloo Mipsten'], + 'format_ext_str_mv' => ['blip/intervuu'], + 'media_type_str_mv' => ['audio/mpeg'], + 'id' => 'test456', + 'first_indexed' => '1970-01-01T00:00:00Z', + 'last_indexed' => '1970-01-01T00:00:00Z', + 'catalog_date' => '1970-01-01T00:00:00Z', + ], + ]; + } + + /** + * Test single record processing + * + * @param array $dbRecord Array presenting a record from database to be processed. + * @param array $expected Array for expected test results + * + * @return void + */ + #[\PHPUnit\Framework\Attributes\DataProvider('getTestProcessSingleRecordData')] + public function testProcessSingleRecord(array $dbRecord, array $expected): void + { + $dbRecord['original_data'] = $this->getFixture($dbRecord['original_data'], 'Finna'); + $database = $this->getDatabase(); + $solrUpdater = $this->getSolrUpdater(database: $database); + $result = $solrUpdater->processSingleRecord($dbRecord); + $testRecord = $result['records'][0]; + // Leave out testing full record but confirm that it exists + $this->assertTrue(!empty($testRecord['fullrecord'])); + unset($testRecord['fullrecord']); + $this->assertEquals($expected, $testRecord); + } + + /** + * Get database for storing test records found from database. + * + * @param ?ArrayIterator, array> $dbRecords Records found in the database + * @param ?array $params Params to use for searching records from database + * + * @return MockObject + */ + protected function getDatabase( + ?ArrayIterator $dbRecords = null, + ?array $params = null + ): MockObject&DatabaseInterface { + $dbRecords ??= new ArrayIterator([ + [ + 'original_data' => $this->getFixture('record/marc4.xml', 'Finna'), + 'normalized_data' => '', + '_id' => 'test123', + 'source_id' => 'test', + 'oai_id' => 'testoai1', + 'format' => 'marc', + 'date' => '2025-01-01', + ], + ]); + + $params ??= [ + 'host_record_id' => [ + '$in' => ['test12345'], + ], + 'deleted' => false, + 'suppressed' => ['$in' => [null, false]], + 'source_id' => 'test', + ]; + $recordMap = [ + [$params, [], $dbRecords[0]], + ]; + $database = $this->getMockBuilder(MongoDatabase::class)->disableOriginalConstructor()->getMock(); + $database->expects($this->any())->method('findRecord')->willReturnMap($recordMap); + $database->expects($this->any())->method('findRecords')->willReturn($dbRecords); + return $database; + } + /** * Create SolrUpdater * - * @param array $dsConfigOverrides Data source config overrides - * @param ?DatabaseInterface $database Database mock object + * @param array $dsConfigOverrides Data source config overrides + * @param array $dbRecord Database record + * @param MockObject|DatabaseInterface|null $database Database mock object * * @return SolrUpdater */ protected function getSolrUpdater( array $dsConfigOverrides = [], + array $dbRecord = [], ?DatabaseInterface $database = null ): SolrUpdater { $dsConfig = array_merge_recursive( @@ -256,7 +546,7 @@ protected function getSolrUpdater( $metaDataUtils = $this->getMockBuilder(MetadataUtils::class)->onlyMethods([]) ->disableOriginalConstructor()->getMock(); - $record = $this->getMockBuilder(Marc::class)->onlyMethods(['createRecord'])->setConstructorArgs([ + $marcRecord = $this->getMockBuilder(Marc::class)->onlyMethods(['createRecord'])->setConstructorArgs([ [], [], $this->createMock(Logger::class), @@ -265,18 +555,39 @@ protected function getSolrUpdater( $this->createMock(FormatCalculator::class), $recordPluginManager, ])->getMock(); - - $record->expects($this->any())->method('createRecord')->willReturnCallback( - function ($format, $data, $oaiID, $source, $extraData = []) use ($record) { - $cloneRecord = clone $record; - $cloneRecord->setData($source, $oaiID, $data, $extraData); - return $cloneRecord; + $marcRecord->expects($this->any())->method('createRecord')->willReturnCallback( + function ($format, $data, $oaiID, $source, $extraData = []) use ($marcRecord) { + var_dump(isset($marcRecord)); + $cloned = clone $marcRecord; + $cloned->setData($source, $oaiID, $data, $extraData); + return $cloned; } ); + $eadRecord = $this->getMockBuilder(Ead::class)->onlyMethods([])->setConstructorArgs([ + [], + [], + $this->createMock(Logger::class), + $metaDataUtils, + fn ($metadata) => new MarcMarc($metadata), + $this->createMock(FormatCalculator::class), + $recordPluginManager, + ])->getMock(); + + $recordMap = [ + [ + 'marc', + null, + clone $marcRecord, + ], + [ + 'ead', + null, + clone $eadRecord, + ], + ]; + + $recordPluginManager->expects($this->any())->method('get')->willReturnMap($recordMap); - $recordPluginManager->expects($this->any())->method('get')->willReturnCallback(function () use ($record) { - return clone $record; - }); $fieldMapper = new FieldMapper( $this->getFixtureDir('Finna') . 'config/basic', [], diff --git a/tests/fixtures/Finna/record/ead.xml b/tests/fixtures/Finna/record/ead.xml new file mode 100644 index 00000000..47c48953 --- /dev/null +++ b/tests/fixtures/Finna/record/ead.xml @@ -0,0 +1,101 @@ + + + + blorf mipmip zaarl frrrp tikka meowzorp flibbin 1977 glarp + mrrrp-blib-zoink + zz-ploof-9911 + + fiftypurr snorfle meep + + gribble snarrk floomtar wubbadee + + grk + fnrr + + + Kralloo Mipsten + + + Snerpaloosi Instiploop + + + +

flarpo 1

+
+ +
+
+ +

glimfadoo 15 snarr Väinö Talas blorptik Floridana snooflepuff 5+5 min floof cutoff

+
+ + + blip/intervuu + + + Yhdysblat + + + + 11.11111, 22.22222 + Asikblar + + + 33.33333, 44.44444 + Päijät-Hömp + + + 55.55555, 66.66666 + Helsinkloof + + + 77.77777, 88.88888 + Uusimrr + + + 99.99999, -11.11111 + Clevorland + + + -22.22222, 33.33333 + Detroink + + + -44.44444, 55.55555 + Montablaa + + + -66.66666, 77.77777 + Duluthnoo + + + -88.88888, 99.99999 + Fort Loodle + + + 12.34567, -76.54321 + Lake Worf + + + + mootlik + sirtooz + sirtiloot + ulkosnarf + amerisnarf + floridansnarf + eläkeblorp + työbloop + työnteek + työväää + talonrakblip + järjestööf + + +

CC BY 4.0

+
+ + + + +
\ No newline at end of file diff --git a/tests/fixtures/Finna/record/lido_hierarchy.xml b/tests/fixtures/Finna/record/lido_hierarchy.xml new file mode 100644 index 00000000..1199c4ad --- /dev/null +++ b/tests/fixtures/Finna/record/lido_hierarchy.xml @@ -0,0 +1,37 @@ + + + + 12345 + + + + + Maalaus + + + + + + + + + + + + + + + + + Maalaus + + + + + Maisema + + + + + + diff --git a/tests/fixtures/Finna/record/marc4.xml b/tests/fixtures/Finna/record/marc4.xml index 5d5374f6..8b5c3493 100644 --- a/tests/fixtures/Finna/record/marc4.xml +++ b/tests/fixtures/Finna/record/marc4.xml @@ -5,10 +5,8 @@ FI-MELINDA 20160322194428.0 140327s2013 fi 000 0 fin d - - Test string - 961827 - Test parent string + + Host record title 1 diff --git a/tests/fixtures/Finna/record/marc5.xml b/tests/fixtures/Finna/record/marc5.xml index 9130934f..29c04396 100644 --- a/tests/fixtures/Finna/record/marc5.xml +++ b/tests/fixtures/Finna/record/marc5.xml @@ -5,6 +5,9 @@ FI-MELINDA 20160322194428.0 140327s2013 fi 000 0 fin d + + Component part title 1 + Test string 961827 diff --git a/tests/fixtures/Finna/record/marc6.xml b/tests/fixtures/Finna/record/marc6.xml index 86f6ecea..0d6c458f 100644 --- a/tests/fixtures/Finna/record/marc6.xml +++ b/tests/fixtures/Finna/record/marc6.xml @@ -5,6 +5,9 @@ FI-MELINDA 20160322194428.0 140327s2013 fi 000 0 fin d + + Component part title 2 + Test string 961827 diff --git a/tests/fixtures/Finna/record/musketti2.xml b/tests/fixtures/Finna/record/musketti2.xml index 93880ff7..48f36852 100644 --- a/tests/fixtures/Finna/record/musketti2.xml +++ b/tests/fixtures/Finna/record/musketti2.xml @@ -214,6 +214,11 @@ + + + collection + + Kansatieteen kuvakokoelma diff --git a/tests/fixtures/Finna/record/musketti3.xml b/tests/fixtures/Finna/record/musketti3.xml new file mode 100644 index 00000000..f689beec --- /dev/null +++ b/tests/fixtures/Finna/record/musketti3.xml @@ -0,0 +1,314 @@ + + + + + Luonto + + musketti_www.M012:4878:1 + + + + + kuva + + + + + valokuva + + + fi + sv + + + en + + + + + + + Imatrankoski + + + + + + 33,1. + + + + + Imatra. val. H.Hintze 1897 Antr. + + + + + 33,1. + + + + + Imatra. 1897 + + + + + 33,1. Imatra. + + + + + + + + Museoviraston kuva-arkisto/ + + + 4878:1 + + + + + Repository Location 1 + + + Repository Location 2 + + + Prt + + Prt 2 + Kiinteistötunnus + + http://www.yso.fi/onto/yso/p94413 + + + + + + + Tarkempi paikka veden äärellä + + + Kalasatama + + + + Capellanranta 1 ja 3 välillä + + + + Helsinki + + + + + + + + + 12 x 17 cm, 12 cm + + + + + + + + + valmistus + + + valmistus + + + + + http://urn.fi/URN:NBN:fi:au:finaf:000173713 + https://isni.org/isni/0000000073500621 + + Hintze Harry + + + + kuvaaja + + + kehittäjä + + + + + 1897 + + 1897 + 1897 + + + + Ruokolahti + + + + + + + suunnittelu + + + suunnittelu + + + + + + Testaaja, Taavi + + + + suunnittelija + + + + + + + + + + Imatrankoski + + + 1897 + + + 1898 + + + Imatrankoski, Ruokolahti + + + + + Imatrankoski + + + luonnon paikka + + + + + + + Ruokolahti .. + + + kunta/kaupunki (Suomi) + + + + + + + + + + + 12345 + + collection + + + Top level title + + + wut is tis + + + is part of + + + + + Parent level title + + + Alakokoelma + + + + + + + + Erityiskokoelma + + + + + + + + + + + + Museovirasto + + + + valokuvaaja + + + + Hintze Harry + + + + + + 4878:1 + + 4878:1 + + + 4878:1 + + Museovirasto/MV + + + + + + + + + Museovirasto/MV + + + + + + + 111222 + mau.jpg + + http://muisti.nba.fi/m/4878_1/00013199.jpg + + + + + + + + Museovirasto/MV + + + Museovirasto + + + + + + From 8c9be71e379e1472866bd9c95c5d2d0775dadd13 Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Wed, 13 May 2026 11:25:08 +0300 Subject: [PATCH 02/14] Grouped xml fixtures related to solrupdatertest into a subfolder --- .../Base/Record/CreateRecordTrait.php | 1 + .../Finna/Solr/SolrUpdaterTest.php | 356 +++++++++++++++++- .../Finna/record/{ => hierarchy}/ead.xml | 0 .../fixtures/Finna/record/hierarchy/ead3.xml | 70 ++++ .../lido.xml} | 4 + .../fixtures/Finna/record/hierarchy/marc.xml | 20 + tests/fixtures/Finna/record/hierarchy/qdc.xml | 22 ++ 7 files changed, 469 insertions(+), 4 deletions(-) rename tests/fixtures/Finna/record/{ => hierarchy}/ead.xml (100%) create mode 100644 tests/fixtures/Finna/record/hierarchy/ead3.xml rename tests/fixtures/Finna/record/{lido_hierarchy.xml => hierarchy/lido.xml} (89%) create mode 100644 tests/fixtures/Finna/record/hierarchy/marc.xml create mode 100644 tests/fixtures/Finna/record/hierarchy/qdc.xml diff --git a/src/RecordManager/Base/Record/CreateRecordTrait.php b/src/RecordManager/Base/Record/CreateRecordTrait.php index a512aa98..5e40a2d2 100644 --- a/src/RecordManager/Base/Record/CreateRecordTrait.php +++ b/src/RecordManager/Base/Record/CreateRecordTrait.php @@ -63,6 +63,7 @@ trait CreateRecordTrait public function createRecord($format, $data, $oaiID, $source, $extraData = []) { $record = $this->recordPluginManager->get($format); + var_dump($format); $record->setData($source, $oaiID, $data, is_string($extraData) ? json_decode($extraData, true) : $extraData); return $record; } diff --git a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php index b34ed983..f9442374 100644 --- a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php +++ b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php @@ -45,7 +45,10 @@ use RecordManager\Base\Utils\MetadataUtils; use RecordManager\Base\Utils\WorkerPoolManager; use RecordManager\Finna\Record\Ead; +use RecordManager\Finna\Record\Ead3; +use RecordManager\Finna\Record\Lido; use RecordManager\Finna\Record\Marc; +use RecordManager\Finna\Record\Qdc; use RecordManager\Finna\Solr\SolrUpdater; use RecordManager\Finna\Utils\FieldMapper; use RecordManagerTest\Base\Feature\FixtureTrait; @@ -102,6 +105,18 @@ class SolrUpdaterTest extends \PHPUnit\Framework\TestCase 'institution' => 'tost', 'format' => 'ead', ], + 'tyst' => [ + 'institution' => 'tyst', + 'format' => 'lido', + ], + 'tast' => [ + 'institution' => 'tast', + 'format' => 'qdc', + ], + 'cat_archive' => [ + 'institution' => 'cat_archive', + 'format' => 'ead3', + ], ]; /** @@ -258,7 +273,7 @@ public static function getTestProcessSingleRecordData(): Generator 'updated' => $date, 'date' => $date, 'format' => 'marc', - 'original_data' => 'record/marc5.xml', + 'original_data' => 'record/hierarchy/marc.xml', 'normalized_data' => null, ], [ @@ -331,7 +346,7 @@ public static function getTestProcessSingleRecordData(): Generator 'updated' => $date, 'date' => $date, 'format' => 'ead', - 'original_data' => 'record/ead.xml', + 'original_data' => 'record/hierarchy/ead.xml', 'normalized_data' => null, ], [ @@ -450,6 +465,298 @@ public static function getTestProcessSingleRecordData(): Generator 'catalog_date' => '1970-01-01T00:00:00Z', ], ]; + + yield 'Test single lido record with hierarchy_parent_title' => [ + [ + '_id' => 'test223', + 'oai_id' => '', + 'linking_id' => [], + 'source_id' => 'tyst', + 'deleted' => false, + 'created' => $date, + 'updated' => $date, + 'date' => $date, + 'format' => 'lido', + 'original_data' => 'record/hierarchy/lido.xml', + 'normalized_data' => null, + ], + [ + 'record_format' => 'lido', + 'allfields' => [ + '12345', + 'Maalaus', + 'Maisema', + 'Joku kokoelma', + ], + 'collection' => 'Joku kokoelma', + 'format' => 'Maalaus', + 'title_full' => 'Maisema', + 'title_short' => 'Maisema', + 'title_sort' => 'maisema', + 'title' => 'Maisema', + 'hierarchy_parent_title' => [ + 'Joku kokoelma', + ], + 'source_str_mv' => 'tyst', + 'datasource_str_mv' => 'tyst', + 'format_ext_str_mv' => [ + 'Maalaus', + ], + 'id' => 'test223', + 'first_indexed' => '1970-01-01T00:00:00Z', + 'last_indexed' => '1970-01-01T00:00:00Z', + 'catalog_date' => '1970-01-01T00:00:00Z', + 'container_title_str_mv' => [ + 'Joku kokoelma', + ], + ], + ]; + + yield 'Test single qdc record with hierarchy_parent_title' => [ + [ + '_id' => 'test223', + 'oai_id' => '', + 'linking_id' => [], + 'source_id' => 'tast', + 'deleted' => false, + 'created' => $date, + 'updated' => $date, + 'date' => $date, + 'format' => 'qdc', + 'original_data' => 'record/hierarchy/qdc.xml', + 'normalized_data' => null, + ], + [ + 'record_format' => 'qdc', + 'allfields' => [ + 'Test qdc record', + 'Ukko, testi', + 'teest', + 'test', + '2021-06-16T06:31:44Z', + '2021', + 'Article', + 'okm_type', + 'okm_type_2', + 'other_type', + 'Citation', + '111111', + 'en', + 'Part of this', + 'Hierarchy parent title', + 'CC BY-NC-ND 4.0', + 'Publisher name, here', + 'http://dx.doi.org/https://doi.org/10.34416/svc.00029', + '10138_331330', + ], + 'author' => [ + 'Ukko, testi', + ], + 'author_sort' => 'Ukko, testi', + 'ctrlnum' => [ + '10138_331330', + ], + 'format' => 'Article', + 'issn' => [ + '111111', + ], + 'language' => [ + 'en', + ], + 'publishDate' => [ + '2021', + ], + 'publishDateRange' => [ + '[2021-01-01 TO 2021-12-31]', + ], + 'publishDateSort' => '2021', + 'publisher' => [ + 'Publisher name, here', + ], + 'series' => [ + 'Part of this', + ], + 'title_full' => 'Test qdc record', + 'title_short' => 'Test qdc record', + 'title_sort' => 'test qdc record', + 'title' => 'Test qdc record', + 'topic_facet' => [ + 'teest', + 'test', + ], + 'topic' => [ + 'teest', + 'test', + ], + 'url' => [ + 'http://dx.doi.org/https://doi.org/10.34416/svc.00029', + ], + 'main_date_str' => '2021', + 'main_date' => '2021-01-01T00:00:00Z', + 'publication_daterange' => '[2021-01-01 TO 2021-12-31]', + 'search_daterange_mv' => [ + '[2021-01-01 TO 2021-12-31]', + ], + 'usage_rights_str_mv' => [ + 'CC BY-NC-ND 4.0', + ], + 'usage_rights_ext_str_mv' => [ + 'CC BY-NC-ND 4.0', + ], + 'source_str_mv' => 'tast', + 'datasource_str_mv' => 'tast', + 'author_facet' => [ + 'Ukko, testi', + ], + 'format_ext_str_mv' => 'Article', + 'id' => 'test223', + 'work_keys_str_mv' => [ + 'AT ukkotesti testqdc', + ], + 'institution' => 'tast', + 'first_indexed' => '1970-01-01T00:00:00Z', + 'last_indexed' => '1970-01-01T00:00:00Z', + 'catalog_date' => '1970-01-01T00:00:00Z', + 'hierarchy_parent_title' => [ + 'Hierarchy parent title', + ], + 'container_title_str_mv' => [ + 'Hierarchy parent title', + ], + ], + ]; + + yield 'Test single ead3 record with hierarchy top title' => [ + [ + '_id' => 'ttt111', + 'oai_id' => '', + 'linking_id' => [], + 'source_id' => 'cat_archive', + 'deleted' => false, + 'created' => $date, + 'updated' => $date, + 'date' => $date, + 'format' => 'ead3', + 'original_data' => 'record/hierarchy/ead3.xml', + 'normalized_data' => null, + ], + [ + 'record_format' => 'ead3', + 'allfields' => [ + 'Mrr-fluff nyaff', + 'Mjaau skrelli prr-vump', + 'Nya-frobble prrr-chant', + 'Prrlax miau-ponkeli strav-mrr', + 'mrr-glimzor', + 'purr-238', + 'miau-floo 1880:85:311-85:311', + 'ffrrp-245348772', + '1880–mrr-grunk', + 'Miauska skreppa-prr', + 'Reinmrr, Agaprr', + 'Kattin kieli', + 'Ilmentymä: Prr-kuva (Digimiau)', + 'Tietosisältö', + 'Mrr-maalaus maisemasta, jossa on kallioita, metsää ja järvi-miau.' + . ' Aihe mahdollisesti Jaakkimasta, mutta kissa ei kerro.', + 'Käyttöehdot', + 'CC BY-NC-ND 4.0 (miau-miau)', + 'Asiasanat ja luokat', + 'Kuva-mrr', + 'Bild-mjaau', + 'Image-nya', + 'Maalaus-prr', + 'Målning-mjaau', + 'Painting-nyaff', + 'Etelä-Karjala-mrr', + 'Random collection title', + '173852008554500', + ], + 'author' => [ + 'Reinmrr, Agaprr', + ], + 'author_sort' => 'Reinmrr, Agaprr', + 'description' => 'Mrr-maalaus maisemasta, jossa on kallioita,' + . ' metsää ja järvi-miau. Aihe mahdollisesti Jaakkimasta, mutta kissa ei kerro.', + 'format' => 'Kuva-mrr/Maalaus-prr', + 'geographic_facet' => [ + 'Etelä-Karjala-mrr', + ], + 'geographic' => [ + 'Etelä-Karjala-mrr', + ], + 'institution' => 'SKS KRA', + 'language' => [ + 'fin', + ], + 'series' => 'Kansatieteellisiä piirroksia Etelä-Karjalasta', + 'thumbnail' => 'https://example.com/frobnar/thumb', + 'title_full' => 'mrr-glimzor Miauska skreppa-prr‎ (1880)', + 'title_short' => 'Miauska skreppa-prr‎ (1880)', + 'title_sort' => 'mrr glimzor miauska skreppa prr‎ (1880)', + 'title_sub' => 'mrr-glimzor', + 'title' => 'mrr-glimzor Miauska skreppa-prr‎ (1880)', + 'hierarchytype' => 'Default', + 'hierarchy_top_id' => 'cat_archive.173852005642800', + 'hierarchy_top_title' => 'Random collection title', + 'hierarchy_sequence' => '0000464', + 'hierarchy_parent_id' => 'cat_archive.173852005642800_173852006211600', + 'hierarchy_parent_title' => 'Kansatieteellisiä piirroksia Etelä-Karjalasta', + 'title_in_hierarchy' => 'mrr-glimzor mrr-glimzor Miauska skreppa-prr', + 'container_title_str_mv' => [ + 'Random collection title', + ], + 'unit_daterange' => '[1880-01-01 TO 1880-12-31]', + 'search_daterange_mv' => [ + '[1880-01-01 TO 1880-12-31]', + ], + 'era_facet' => '1880', + 'main_date_str' => '1880', + 'main_date' => '1880-01-01T00:00:00Z', + 'hierarchy_sequence_str' => '0000464', + 'source_str_mv' => 'SKS KRA', + 'datasource_str_mv' => 'cat_archive', + 'online_boolean' => '1', + 'online_str_mv' => 'SKS KRA', + 'free_online_boolean' => '1', + 'free_online_str_mv' => 'SKS KRA', + 'identifier' => '173852008554500', + 'media_type_str_mv' => [ + 'image/jpeg', + ], + 'usage_rights_str_mv' => [ + 'https://creativecommons.org/licenses/by-nc-nd/4.0/deed.fi', + ], + 'usage_rights_ext_str_mv' => [ + 'https://creativecommons.org/licenses/by-nc-nd/4.0/deed.fi', + ], + 'author_facet' => [ + 'Reinmrr, Agaprr', + ], + 'author2_id_str_mv' => [ + 'EAC_228481117', + ], + 'author2_id_role_str_mv' => [ + 'EAC_228481117###Arkistonmuodostaja', + 'EAC_228481117###Kuvataiteilija', + ], + 'format_ext_str_mv' => 'Kuva-mrr/Maalaus-prr', + 'geographic_id_str_mv' => [ + 'http://www.yso.fi/onto/yso/p94106', + ], + 'file_identifier_str_mv' => [ + 'mrr_full.tif', + 'mrr_thumb.tif', + ], + 'id' => 'ttt111', + 'work_keys_str_mv' => [ + 'AT reinmrragaprr mrr', + ], + 'first_indexed' => '1970-01-01T00:00:00Z', + 'last_indexed' => '1970-01-01T00:00:00Z', + 'catalog_date' => '1970-01-01T00:00:00Z', + ], + ]; } /** @@ -527,7 +834,7 @@ protected function getDatabase( protected function getSolrUpdater( array $dsConfigOverrides = [], array $dbRecord = [], - ?DatabaseInterface $database = null + MockObject|DatabaseInterface|null $database = null ): SolrUpdater { $dsConfig = array_merge_recursive( $this->dataSourceConfig, @@ -557,7 +864,6 @@ protected function getSolrUpdater( ])->getMock(); $marcRecord->expects($this->any())->method('createRecord')->willReturnCallback( function ($format, $data, $oaiID, $source, $extraData = []) use ($marcRecord) { - var_dump(isset($marcRecord)); $cloned = clone $marcRecord; $cloned->setData($source, $oaiID, $data, $extraData); return $cloned; @@ -572,6 +878,33 @@ function ($format, $data, $oaiID, $source, $extraData = []) use ($marcRecord) { $this->createMock(FormatCalculator::class), $recordPluginManager, ])->getMock(); + $lidoRecord = $this->getMockBuilder(Lido::class)->onlyMethods([])->setConstructorArgs([ + [], + [], + $this->createMock(Logger::class), + $metaDataUtils, + fn ($metadata) => new MarcMarc($metadata), + $this->createMock(FormatCalculator::class), + $recordPluginManager, + ])->getMock(); + + $qdcRecord = $this->getMockBuilder(Qdc::class)->onlyMethods([])->setConstructorArgs([ + [], + [], + $this->createMock(Logger::class), + $metaDataUtils, + $this->createMock(HttpService::class), + $database, + ])->getMock(); + + $ead3Record = $this->getMockBuilder(Ead3::class)->onlyMethods([])->setConstructorArgs([ + [], + [], + $this->createMock(Logger::class), + $metaDataUtils, + $this->createMock(HttpService::class), + $database, + ])->getMock(); $recordMap = [ [ @@ -584,6 +917,21 @@ function ($format, $data, $oaiID, $source, $extraData = []) use ($marcRecord) { null, clone $eadRecord, ], + [ + 'lido', + null, + clone $lidoRecord, + ], + [ + 'qdc', + null, + clone $qdcRecord, + ], + [ + 'ead3', + null, + clone $ead3Record, + ], ]; $recordPluginManager->expects($this->any())->method('get')->willReturnMap($recordMap); diff --git a/tests/fixtures/Finna/record/ead.xml b/tests/fixtures/Finna/record/hierarchy/ead.xml similarity index 100% rename from tests/fixtures/Finna/record/ead.xml rename to tests/fixtures/Finna/record/hierarchy/ead.xml diff --git a/tests/fixtures/Finna/record/hierarchy/ead3.xml b/tests/fixtures/Finna/record/hierarchy/ead3.xml new file mode 100644 index 00000000..14799b7c --- /dev/null +++ b/tests/fixtures/Finna/record/hierarchy/ead3.xml @@ -0,0 +1,70 @@ + + + + Mrr-fluff nyaff + + + Mjaau skrelli prr-vump + Nya-frobble prrr-chant + Prrlax miau-ponkeli strav-mrr + + + mrr-glimzor + purr-238 + miau-floo 1880:85:311-85:311 + ffrrp-245348772 + 1880–mrr-grunk + Miauska skreppa-prr + + + Reinmrr, Agaprr + + + + Kattin kieli + + + + + +

Ilmentymä: Prr-kuva (Digimiau)

+
+
+
+ + Tietosisältö +

Mrr-maalaus maisemasta, jossa on kallioita, metsää ja järvi-miau. Aihe mahdollisesti Jaakkimasta, mutta kissa ei kerro.

+
+ + Käyttöehdot +

+ CC BY-NC-ND 4.0 (miau-miau) +

+
+ + + Reinmrr, Agaprr + + + + Asiasanat ja luokat + + Kuva-mrr + Bild-mjaau + Image-nya + + + Maalaus-prr + Målning-mjaau + Painting-nyaff + + + Etelä-Karjala-mrr + + + + + + + +
\ No newline at end of file diff --git a/tests/fixtures/Finna/record/lido_hierarchy.xml b/tests/fixtures/Finna/record/hierarchy/lido.xml similarity index 89% rename from tests/fixtures/Finna/record/lido_hierarchy.xml rename to tests/fixtures/Finna/record/hierarchy/lido.xml index 1199c4ad..35532774 100644 --- a/tests/fixtures/Finna/record/lido_hierarchy.xml +++ b/tests/fixtures/Finna/record/hierarchy/lido.xml @@ -13,8 +13,12 @@ + + Joku kokoelma + + Kokoelma diff --git a/tests/fixtures/Finna/record/hierarchy/marc.xml b/tests/fixtures/Finna/record/hierarchy/marc.xml new file mode 100644 index 00000000..29c04396 --- /dev/null +++ b/tests/fixtures/Finna/record/hierarchy/marc.xml @@ -0,0 +1,20 @@ + + + 01195cam a22004094i 4500 + + FI-MELINDA + 20160322194428.0 + 140327s2013 fi 000 0 fin d + + Component part title 1 + + + Test string + 961827 + Test parent string + + + 010101 + + + diff --git a/tests/fixtures/Finna/record/hierarchy/qdc.xml b/tests/fixtures/Finna/record/hierarchy/qdc.xml new file mode 100644 index 00000000..dc152490 --- /dev/null +++ b/tests/fixtures/Finna/record/hierarchy/qdc.xml @@ -0,0 +1,22 @@ + + + Test qdc record + Ukko, testi + teest + test + 2021-06-16T06:31:44Z + 2021 + Article + okm_type + okm_type_2 + other_type + Citation + 111111 + en + Part of this + Hierarchy parent title + CC BY-NC-ND 4.0 + Publisher name, here + http://dx.doi.org/https://doi.org/10.34416/svc.00029 + 10138_331330 + From ab69695d3845cb7ddf7168ce4765db8d89426ade Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Wed, 13 May 2026 11:45:48 +0300 Subject: [PATCH 03/14] Adjusted tests --- src/RecordManager/Base/Record/CreateRecordTrait.php | 1 - .../RecordManagerTest/Finna/Solr/SolrUpdaterTest.php | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/RecordManager/Base/Record/CreateRecordTrait.php b/src/RecordManager/Base/Record/CreateRecordTrait.php index 5e40a2d2..a512aa98 100644 --- a/src/RecordManager/Base/Record/CreateRecordTrait.php +++ b/src/RecordManager/Base/Record/CreateRecordTrait.php @@ -63,7 +63,6 @@ trait CreateRecordTrait public function createRecord($format, $data, $oaiID, $source, $extraData = []) { $record = $this->recordPluginManager->get($format); - var_dump($format); $record->setData($source, $oaiID, $data, is_string($extraData) ? json_decode($extraData, true) : $extraData); return $record; } diff --git a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php index f9442374..575faa93 100644 --- a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php +++ b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php @@ -335,7 +335,7 @@ public static function getTestProcessSingleRecordData(): Generator ], ]; - yield 'Test single ead record with container title field' => [ + yield 'Test single ead record with hierarchy_top_title' => [ [ '_id' => 'test456', 'oai_id' => '', @@ -438,8 +438,10 @@ public static function getTestProcessSingleRecordData(): Generator 'hierarchy_sequence' => '0000020', 'hierarchy_parent_id' => 'tost.272', 'hierarchy_parent_title' => 'snarfloota kokoelma', - 'title_in_hierarchy' => 'mrrrp-blib-zoink mrrrp-blib-zoink' + 'title_in_hierarchy' => [ + 'mrrrp-blib-zoink mrrrp-blib-zoink' . ' blorf mipmip zaarl frrrp tikka meowzorp flibbin 1977 glarp', + ], 'container_title_str_mv' => ['blorptik snoofle 1977-1978'], 'unit_daterange' => '[9911-01-01 TO 9911-12-31]', 'search_daterange_mv' => '[9911-01-01 TO 9911-12-31]', @@ -509,6 +511,7 @@ public static function getTestProcessSingleRecordData(): Generator 'container_title_str_mv' => [ 'Joku kokoelma', ], + 'title_en_txt' => 'Maalaus', ], ]; @@ -623,6 +626,7 @@ public static function getTestProcessSingleRecordData(): Generator 'container_title_str_mv' => [ 'Hierarchy parent title', ], + 'title_fi_txt' => 'Test qdc record', ], ]; @@ -702,7 +706,9 @@ public static function getTestProcessSingleRecordData(): Generator 'hierarchy_sequence' => '0000464', 'hierarchy_parent_id' => 'cat_archive.173852005642800_173852006211600', 'hierarchy_parent_title' => 'Kansatieteellisiä piirroksia Etelä-Karjalasta', - 'title_in_hierarchy' => 'mrr-glimzor mrr-glimzor Miauska skreppa-prr', + 'title_in_hierarchy' => [ + 'mrr-glimzor mrr-glimzor Miauska skreppa-prr', + ], 'container_title_str_mv' => [ 'Random collection title', ], From ac69cf900faa0acaba3490e04829dd65f0274b44 Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Wed, 13 May 2026 11:46:40 +0300 Subject: [PATCH 04/14] Removed unused configuration from sample file --- conf/datasources.ini.sample.finna | 6 ------ 1 file changed, 6 deletions(-) diff --git a/conf/datasources.ini.sample.finna b/conf/datasources.ini.sample.finna index ea6fe831..2770221a 100644 --- a/conf/datasources.ini.sample.finna +++ b/conf/datasources.ini.sample.finna @@ -7,9 +7,3 @@ ; prepend = whether to prepend 003 to the field. 0 = no (default), 1 = yes. ; Example: ;driverParams[] = "recordLinkingIdFields=\"001,1:035a,0:999c,0\"" - -;[examples] -; Option to override default field used to populate container_title_str_mv field. -; Other formats populates the container_title_str_mv from hierarchy_parent_title field -; and EAD3 populates it from hierarchy_top_title field. -;driverParams[] = "containerTitleField=hierarchy_top_title" From a6c4b3fec530d1d6e0337e4096dda46556638082 Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Wed, 13 May 2026 12:45:18 +0300 Subject: [PATCH 05/14] Added nl --- src/RecordManager/Finna/Solr/SolrUpdater.php | 2 ++ tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php | 2 +- tests/fixtures/Finna/record/hierarchy/ead.xml | 2 +- tests/fixtures/Finna/record/hierarchy/ead3.xml | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/RecordManager/Finna/Solr/SolrUpdater.php b/src/RecordManager/Finna/Solr/SolrUpdater.php index ca7d9c88..ce45e8b7 100644 --- a/src/RecordManager/Finna/Solr/SolrUpdater.php +++ b/src/RecordManager/Finna/Solr/SolrUpdater.php @@ -140,6 +140,8 @@ protected function augmentAndProcessFields( $data['catalog_date'] = $date; } } + // Add container title facet field only if it has not been set previously + // and hierarchy parent title field is present. if (!isset($data[$this->containerTitleFacetField]) && isset($data[$this->hierarchyParentTitleField])) { $data[$this->containerTitleFacetField] = $data[$this->hierarchyParentTitleField]; } diff --git a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php index 575faa93..e45b127a 100644 --- a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php +++ b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php @@ -781,7 +781,7 @@ public function testProcessSingleRecord(array $dbRecord, array $expected): void $solrUpdater = $this->getSolrUpdater(database: $database); $result = $solrUpdater->processSingleRecord($dbRecord); $testRecord = $result['records'][0]; - // Leave out testing full record but confirm that it exists + // Leave out testing full record but confirm that it exists. $this->assertTrue(!empty($testRecord['fullrecord'])); unset($testRecord['fullrecord']); $this->assertEquals($expected, $testRecord); diff --git a/tests/fixtures/Finna/record/hierarchy/ead.xml b/tests/fixtures/Finna/record/hierarchy/ead.xml index 47c48953..d6b981b9 100644 --- a/tests/fixtures/Finna/record/hierarchy/ead.xml +++ b/tests/fixtures/Finna/record/hierarchy/ead.xml @@ -98,4 +98,4 @@ - \ No newline at end of file + diff --git a/tests/fixtures/Finna/record/hierarchy/ead3.xml b/tests/fixtures/Finna/record/hierarchy/ead3.xml index 14799b7c..751dcf6b 100644 --- a/tests/fixtures/Finna/record/hierarchy/ead3.xml +++ b/tests/fixtures/Finna/record/hierarchy/ead3.xml @@ -67,4 +67,4 @@ - \ No newline at end of file + From f5693f383f14518faae70471e168bd191ea4c4b4 Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Wed, 13 May 2026 12:46:50 +0300 Subject: [PATCH 06/14] Removed unused fixture --- tests/fixtures/Finna/record/musketti3.xml | 314 ---------------------- 1 file changed, 314 deletions(-) delete mode 100644 tests/fixtures/Finna/record/musketti3.xml diff --git a/tests/fixtures/Finna/record/musketti3.xml b/tests/fixtures/Finna/record/musketti3.xml deleted file mode 100644 index f689beec..00000000 --- a/tests/fixtures/Finna/record/musketti3.xml +++ /dev/null @@ -1,314 +0,0 @@ - - - - - Luonto - - musketti_www.M012:4878:1 - - - - - kuva - - - - - valokuva - - - fi - sv - - - en - - - - - - - Imatrankoski - - - - - - 33,1. - - - - - Imatra. val. H.Hintze 1897 Antr. - - - - - 33,1. - - - - - Imatra. 1897 - - - - - 33,1. Imatra. - - - - - - - - Museoviraston kuva-arkisto/ - - - 4878:1 - - - - - Repository Location 1 - - - Repository Location 2 - - - Prt - - Prt 2 - Kiinteistötunnus - - http://www.yso.fi/onto/yso/p94413 - - - - - - - Tarkempi paikka veden äärellä - - - Kalasatama - - - - Capellanranta 1 ja 3 välillä - - - - Helsinki - - - - - - - - - 12 x 17 cm, 12 cm - - - - - - - - - valmistus - - - valmistus - - - - - http://urn.fi/URN:NBN:fi:au:finaf:000173713 - https://isni.org/isni/0000000073500621 - - Hintze Harry - - - - kuvaaja - - - kehittäjä - - - - - 1897 - - 1897 - 1897 - - - - Ruokolahti - - - - - - - suunnittelu - - - suunnittelu - - - - - - Testaaja, Taavi - - - - suunnittelija - - - - - - - - - - Imatrankoski - - - 1897 - - - 1898 - - - Imatrankoski, Ruokolahti - - - - - Imatrankoski - - - luonnon paikka - - - - - - - Ruokolahti .. - - - kunta/kaupunki (Suomi) - - - - - - - - - - - 12345 - - collection - - - Top level title - - - wut is tis - - - is part of - - - - - Parent level title - - - Alakokoelma - - - - - - - - Erityiskokoelma - - - - - - - - - - - - Museovirasto - - - - valokuvaaja - - - - Hintze Harry - - - - - - 4878:1 - - 4878:1 - - - 4878:1 - - Museovirasto/MV - - - - - - - - - Museovirasto/MV - - - - - - - 111222 - mau.jpg - - http://muisti.nba.fi/m/4878_1/00013199.jpg - - - - - - - - Museovirasto/MV - - - Museovirasto - - - - - - From 91bb3717d5694c8f2fa751c901f5ee9adfd655bd Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Wed, 13 May 2026 12:47:42 +0300 Subject: [PATCH 07/14] Remove unused modifier --- tests/fixtures/Finna/record/musketti2.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/fixtures/Finna/record/musketti2.xml b/tests/fixtures/Finna/record/musketti2.xml index 8daf2bd3..72ac8654 100644 --- a/tests/fixtures/Finna/record/musketti2.xml +++ b/tests/fixtures/Finna/record/musketti2.xml @@ -215,11 +215,6 @@ - - - collection - - Kansatieteen kuvakokoelma From 159a7ebc6ab680e064157ef4eedaf9316e117d15 Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Wed, 13 May 2026 13:31:37 +0300 Subject: [PATCH 08/14] Move fixtures related to solrupdatertest to its own folder --- .../Finna/Solr/SolrUpdaterTest.php | 16 +++++++-------- .../hierarchy => SolrUpdaterTest}/ead.xml | 0 .../hierarchy => SolrUpdaterTest}/ead3.xml | 0 .../hierarchy => SolrUpdaterTest}/lido.xml | 0 .../marc_component_part.xml} | 0 .../SolrUpdaterTest/marc_component_part_2.xml | 20 +++++++++++++++++++ .../SolrUpdaterTest/marc_host_record.xml | 12 +++++++++++ .../hierarchy => SolrUpdaterTest}/qdc.xml | 0 8 files changed, 40 insertions(+), 8 deletions(-) rename tests/fixtures/Finna/{record/hierarchy => SolrUpdaterTest}/ead.xml (100%) rename tests/fixtures/Finna/{record/hierarchy => SolrUpdaterTest}/ead3.xml (100%) rename tests/fixtures/Finna/{record/hierarchy => SolrUpdaterTest}/lido.xml (100%) rename tests/fixtures/Finna/{record/hierarchy/marc.xml => SolrUpdaterTest/marc_component_part.xml} (100%) create mode 100644 tests/fixtures/Finna/SolrUpdaterTest/marc_component_part_2.xml create mode 100644 tests/fixtures/Finna/SolrUpdaterTest/marc_host_record.xml rename tests/fixtures/Finna/{record/hierarchy => SolrUpdaterTest}/qdc.xml (100%) diff --git a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php index e45b127a..9473b12c 100644 --- a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php +++ b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php @@ -143,7 +143,7 @@ function ($format, $data, $oaiID, $source, $extraData = []) use ($record) { return $cloneRecord; } ); - $fixture = $this->getFixture('record/marc4.xml', 'Finna'); + $fixture = $this->getFixture('SolrUpdaterTest/marc_host_record.xml', 'Finna'); $record->setData('test', 'oaitest', $fixture, []); $date = strtotime('2020-10-20 13:01:00'); $dbRecord = [ @@ -172,7 +172,7 @@ function ($format, $data, $oaiID, $source, $extraData = []) use ($record) { ]; $records = new ArrayIterator([ [ - 'original_data' => $this->getFixture('record/marc5.xml', 'Finna'), + 'original_data' => $this->getFixture('SolrUpdaterTest/marc_component_part.xml', 'Finna'), 'normalized_data' => '', '_id' => 'part_1', 'source_id' => 'test', @@ -181,7 +181,7 @@ function ($format, $data, $oaiID, $source, $extraData = []) use ($record) { 'date' => '2025-01-01', ], [ - 'original_data' => $this->getFixture('record/marc6.xml', 'Finna'), + 'original_data' => $this->getFixture('SolrUpdaterTest/marc_component_part_2.xml', 'Finna'), '_id' => 'part_2', 'normalized_data' => '', 'source_id' => 'test', @@ -273,7 +273,7 @@ public static function getTestProcessSingleRecordData(): Generator 'updated' => $date, 'date' => $date, 'format' => 'marc', - 'original_data' => 'record/hierarchy/marc.xml', + 'original_data' => 'SolrUpdaterTest/marc_component_part.xml', 'normalized_data' => null, ], [ @@ -346,7 +346,7 @@ public static function getTestProcessSingleRecordData(): Generator 'updated' => $date, 'date' => $date, 'format' => 'ead', - 'original_data' => 'record/hierarchy/ead.xml', + 'original_data' => 'SolrUpdaterTest/ead.xml', 'normalized_data' => null, ], [ @@ -479,7 +479,7 @@ public static function getTestProcessSingleRecordData(): Generator 'updated' => $date, 'date' => $date, 'format' => 'lido', - 'original_data' => 'record/hierarchy/lido.xml', + 'original_data' => 'SolrUpdaterTest/lido.xml', 'normalized_data' => null, ], [ @@ -526,7 +526,7 @@ public static function getTestProcessSingleRecordData(): Generator 'updated' => $date, 'date' => $date, 'format' => 'qdc', - 'original_data' => 'record/hierarchy/qdc.xml', + 'original_data' => 'SolrUpdaterTest/qdc.xml', 'normalized_data' => null, ], [ @@ -641,7 +641,7 @@ public static function getTestProcessSingleRecordData(): Generator 'updated' => $date, 'date' => $date, 'format' => 'ead3', - 'original_data' => 'record/hierarchy/ead3.xml', + 'original_data' => 'SolrUpdaterTest/ead3.xml', 'normalized_data' => null, ], [ diff --git a/tests/fixtures/Finna/record/hierarchy/ead.xml b/tests/fixtures/Finna/SolrUpdaterTest/ead.xml similarity index 100% rename from tests/fixtures/Finna/record/hierarchy/ead.xml rename to tests/fixtures/Finna/SolrUpdaterTest/ead.xml diff --git a/tests/fixtures/Finna/record/hierarchy/ead3.xml b/tests/fixtures/Finna/SolrUpdaterTest/ead3.xml similarity index 100% rename from tests/fixtures/Finna/record/hierarchy/ead3.xml rename to tests/fixtures/Finna/SolrUpdaterTest/ead3.xml diff --git a/tests/fixtures/Finna/record/hierarchy/lido.xml b/tests/fixtures/Finna/SolrUpdaterTest/lido.xml similarity index 100% rename from tests/fixtures/Finna/record/hierarchy/lido.xml rename to tests/fixtures/Finna/SolrUpdaterTest/lido.xml diff --git a/tests/fixtures/Finna/record/hierarchy/marc.xml b/tests/fixtures/Finna/SolrUpdaterTest/marc_component_part.xml similarity index 100% rename from tests/fixtures/Finna/record/hierarchy/marc.xml rename to tests/fixtures/Finna/SolrUpdaterTest/marc_component_part.xml diff --git a/tests/fixtures/Finna/SolrUpdaterTest/marc_component_part_2.xml b/tests/fixtures/Finna/SolrUpdaterTest/marc_component_part_2.xml new file mode 100644 index 00000000..0d6c458f --- /dev/null +++ b/tests/fixtures/Finna/SolrUpdaterTest/marc_component_part_2.xml @@ -0,0 +1,20 @@ + + + 01195cac a22004094i 4500 + 123 + FI-MELINDA + 20160322194428.0 + 140327s2013 fi 000 0 fin d + + Component part title 2 + + + Test string + 961827 + Test parent string + + + 010101 + + + diff --git a/tests/fixtures/Finna/SolrUpdaterTest/marc_host_record.xml b/tests/fixtures/Finna/SolrUpdaterTest/marc_host_record.xml new file mode 100644 index 00000000..8b5c3493 --- /dev/null +++ b/tests/fixtures/Finna/SolrUpdaterTest/marc_host_record.xml @@ -0,0 +1,12 @@ + + + 01195cam a22004094i 4500 + 123 + FI-MELINDA + 20160322194428.0 + 140327s2013 fi 000 0 fin d + + Host record title 1 + + + diff --git a/tests/fixtures/Finna/record/hierarchy/qdc.xml b/tests/fixtures/Finna/SolrUpdaterTest/qdc.xml similarity index 100% rename from tests/fixtures/Finna/record/hierarchy/qdc.xml rename to tests/fixtures/Finna/SolrUpdaterTest/qdc.xml From 2eb71bb58d332ebd8fa9707ffd6a044dfd212151 Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Wed, 13 May 2026 13:36:30 +0300 Subject: [PATCH 09/14] Remove change made to base solrupdater --- src/RecordManager/Base/Solr/SolrUpdater.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RecordManager/Base/Solr/SolrUpdater.php b/src/RecordManager/Base/Solr/SolrUpdater.php index 96bc05f2..81c53b00 100644 --- a/src/RecordManager/Base/Solr/SolrUpdater.php +++ b/src/RecordManager/Base/Solr/SolrUpdater.php @@ -332,7 +332,7 @@ class SolrUpdater 'dewey-sort', 'illustrated', 'first_indexed', 'last-indexed', - 'container_title', 'container_title_str_mv', 'container_volume', 'container_issue', + 'container_title', 'container_volume', 'container_issue', 'container_start_page', 'container_reference', ]; From a2079f11f9edb1d6f41b0f1d73e25d954d319823 Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Wed, 13 May 2026 13:51:06 +0300 Subject: [PATCH 10/14] Adjust to handle adding the container_title_str_mv field in solrupdater --- src/RecordManager/Finna/Record/Ead.php | 17 -------------- src/RecordManager/Finna/Record/Ead3.php | 17 -------------- src/RecordManager/Finna/Solr/SolrUpdater.php | 22 +++++++++++++++---- .../Finna/Record/Ead3Test.php | 1 - 4 files changed, 18 insertions(+), 39 deletions(-) diff --git a/src/RecordManager/Finna/Record/Ead.php b/src/RecordManager/Finna/Record/Ead.php index 25d820ac..cb3e88d4 100644 --- a/src/RecordManager/Finna/Record/Ead.php +++ b/src/RecordManager/Finna/Record/Ead.php @@ -443,21 +443,4 @@ protected function getTopicIDs(): array $result = parent::getTopicIDs(); return $this->addNamespaceToAuthorityIds($result, 'topic'); } - - /** - * Add hierarchy fields. Must be called after title is present in the array. - * - * @param array $data Reference to the target array - * - * @return void - */ - protected function addHierarchyFields(&$data): void - { - parent::addHierarchyFields($data); - $containerTitleFacetField = $this->config['Solr Fields']['container_title_str_mv'] ?? 'container_title_str_mv'; - $hierarchyTopTitleField = $this->config['Solr Fields']['hierarchy_top_title'] ?? 'hierarchy_top_title'; - if (isset($data[$hierarchyTopTitleField])) { - $data[$containerTitleFacetField] = (array)$data[$hierarchyTopTitleField]; - } - } } diff --git a/src/RecordManager/Finna/Record/Ead3.php b/src/RecordManager/Finna/Record/Ead3.php index 63b928bf..ab0ea461 100644 --- a/src/RecordManager/Finna/Record/Ead3.php +++ b/src/RecordManager/Finna/Record/Ead3.php @@ -1490,21 +1490,4 @@ protected function getResourceIdentifiers(): array $fileIds = [...$ids, ...$fileIds]; return $this->resultCache[$cacheKey] = compact('ids', 'fileIds'); } - - /** - * Add hierarchy fields. Must be called after title is present in the array. - * - * @param array $data Reference to the target array - * - * @return void - */ - protected function addHierarchyFields(&$data): void - { - parent::addHierarchyFields($data); - $containerTitleFacetField = $this->config['Solr Fields']['container_title_str_mv'] ?? 'container_title_str_mv'; - $hierarchyTopTitleField = $this->config['Solr Fields']['hierarchy_top_title'] ?? 'hierarchy_top_title'; - if (isset($data[$hierarchyTopTitleField])) { - $data[$containerTitleFacetField] = (array)$data[$hierarchyTopTitleField]; - } - } } diff --git a/src/RecordManager/Finna/Solr/SolrUpdater.php b/src/RecordManager/Finna/Solr/SolrUpdater.php index ce45e8b7..4c786758 100644 --- a/src/RecordManager/Finna/Solr/SolrUpdater.php +++ b/src/RecordManager/Finna/Solr/SolrUpdater.php @@ -40,6 +40,7 @@ use RecordManager\Base\Utils\MetadataUtils; use RecordManager\Base\Utils\WorkerPoolManager; +use function in_array; use function intval; use function is_callable; use function strlen; @@ -140,14 +141,27 @@ protected function augmentAndProcessFields( $data['catalog_date'] = $date; } } - // Add container title facet field only if it has not been set previously - // and hierarchy parent title field is present. - if (!isset($data[$this->containerTitleFacetField]) && isset($data[$this->hierarchyParentTitleField])) { - $data[$this->containerTitleFacetField] = $data[$this->hierarchyParentTitleField]; + // Handle adding container_title_str_mv field for different record types here. + if (in_array($record['format'], ['ead', 'ead3'])) { + if (isset($data['hierarchy_top_title'])) { + $data[$this->containerTitleFacetField] = (array)$data['hierarchy_top_title']; + } + } elseif (isset($data[$this->hierarchyParentTitleField])) { + $data[$this->containerTitleFacetField] = (array)$data[$this->hierarchyParentTitleField]; } $this->addSeriesKeys($data, $metadataRecord); } + /** + * Add container_title_facet_field + * + * @param array $data Field array + * @param mixed $record Database record + * @param AbstractRecord $metadataRecord Metadata record + * @param string $source Source ID + * @param array $settings Settings + */ + /** * Merge component parts to record * diff --git a/tests/RecordManagerTest/Finna/Record/Ead3Test.php b/tests/RecordManagerTest/Finna/Record/Ead3Test.php index f97dfd21..8f6616ca 100644 --- a/tests/RecordManagerTest/Finna/Record/Ead3Test.php +++ b/tests/RecordManagerTest/Finna/Record/Ead3Test.php @@ -767,7 +767,6 @@ public function testSKS(string $addIdToHierarchyTitle, ?array $expectedTitleInHi 'hierarchy_sequence' => '0000003', 'hierarchy_parent_id' => '237990354_238008149', 'hierarchy_parent_title' => 'Tekstit/Gustaf Edvard Sundvallin kokoelma', - 'container_title_str_mv' => ['Gustaf Edvard Sundvallin kokoelma'], 'unit_daterange' => '[1881-01-01 TO 1881-12-31]', 'search_daterange_mv' => [ '[1881-01-01 TO 1881-12-31]', From aa1fde7fff6f16e0c8b3227e22bce73004891670 Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Wed, 13 May 2026 14:08:47 +0300 Subject: [PATCH 11/14] Remove extra changes --- tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php | 2 +- tests/fixtures/Finna/record/marc4.xml | 6 ++++-- tests/fixtures/Finna/record/marc5.xml | 3 --- tests/fixtures/Finna/record/marc6.xml | 3 --- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php index 9473b12c..c4e7c8e7 100644 --- a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php +++ b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php @@ -801,7 +801,7 @@ protected function getDatabase( ): MockObject&DatabaseInterface { $dbRecords ??= new ArrayIterator([ [ - 'original_data' => $this->getFixture('record/marc4.xml', 'Finna'), + 'original_data' => $this->getFixture('SolrUpdaterTest/marc_host_record.xml', 'Finna'), 'normalized_data' => '', '_id' => 'test123', 'source_id' => 'test', diff --git a/tests/fixtures/Finna/record/marc4.xml b/tests/fixtures/Finna/record/marc4.xml index 8b5c3493..5d5374f6 100644 --- a/tests/fixtures/Finna/record/marc4.xml +++ b/tests/fixtures/Finna/record/marc4.xml @@ -5,8 +5,10 @@ FI-MELINDA 20160322194428.0 140327s2013 fi 000 0 fin d - - Host record title 1 + + Test string + 961827 + Test parent string diff --git a/tests/fixtures/Finna/record/marc5.xml b/tests/fixtures/Finna/record/marc5.xml index 29c04396..9130934f 100644 --- a/tests/fixtures/Finna/record/marc5.xml +++ b/tests/fixtures/Finna/record/marc5.xml @@ -5,9 +5,6 @@ FI-MELINDA 20160322194428.0 140327s2013 fi 000 0 fin d - - Component part title 1 - Test string 961827 diff --git a/tests/fixtures/Finna/record/marc6.xml b/tests/fixtures/Finna/record/marc6.xml index 0d6c458f..86f6ecea 100644 --- a/tests/fixtures/Finna/record/marc6.xml +++ b/tests/fixtures/Finna/record/marc6.xml @@ -5,9 +5,6 @@ FI-MELINDA 20160322194428.0 140327s2013 fi 000 0 fin d - - Component part title 2 - Test string 961827 From 1166818f489104a7f3dbdb832618ae2ee3250f61 Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Wed, 13 May 2026 14:10:19 +0300 Subject: [PATCH 12/14] Adjusted comments --- src/RecordManager/Finna/Solr/SolrUpdater.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/RecordManager/Finna/Solr/SolrUpdater.php b/src/RecordManager/Finna/Solr/SolrUpdater.php index 4c786758..a6c80cf2 100644 --- a/src/RecordManager/Finna/Solr/SolrUpdater.php +++ b/src/RecordManager/Finna/Solr/SolrUpdater.php @@ -141,7 +141,7 @@ protected function augmentAndProcessFields( $data['catalog_date'] = $date; } } - // Handle adding container_title_str_mv field for different record types here. + // Use hierarchy_top_title for ead and ead3 formats instead of hierarchy_parent_title. if (in_array($record['format'], ['ead', 'ead3'])) { if (isset($data['hierarchy_top_title'])) { $data[$this->containerTitleFacetField] = (array)$data['hierarchy_top_title']; @@ -152,16 +152,6 @@ protected function augmentAndProcessFields( $this->addSeriesKeys($data, $metadataRecord); } - /** - * Add container_title_facet_field - * - * @param array $data Field array - * @param mixed $record Database record - * @param AbstractRecord $metadataRecord Metadata record - * @param string $source Source ID - * @param array $settings Settings - */ - /** * Merge component parts to record * From 3d91e0935fe065c4c5c0d4e7cd1b51e90540389e Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Tue, 19 May 2026 10:43:59 +0300 Subject: [PATCH 13/14] Normalize test fixture contents, add test for setting solr field container_title_facet to empty --- conf/recordmanager.ini.sample.finna | 5 + src/RecordManager/Finna/Solr/SolrUpdater.php | 84 +--- .../Finna/Solr/SolrUpdaterTest.php | 386 +++++++++--------- tests/fixtures/Finna/SolrUpdaterTest/ead.xml | 78 +--- tests/fixtures/Finna/SolrUpdaterTest/ead3.xml | 42 +- 5 files changed, 244 insertions(+), 351 deletions(-) diff --git a/conf/recordmanager.ini.sample.finna b/conf/recordmanager.ini.sample.finna index 1a5d8122..67fd089b 100644 --- a/conf/recordmanager.ini.sample.finna +++ b/conf/recordmanager.ini.sample.finna @@ -27,3 +27,8 @@ ; Example for allowing IIIF json files. ;allowed_media_types[] = application/ld+json;profile="http://iiif.io/api/presentation/3/context.json" +; The following section can be used to change the Solr fields used when indexing +; records, particularly for hierarchical records. Any field can also be set to empty +; to disable it. +;[Solr Fields] +;container_title_facet = diff --git a/src/RecordManager/Finna/Solr/SolrUpdater.php b/src/RecordManager/Finna/Solr/SolrUpdater.php index a6c80cf2..6b0490ba 100644 --- a/src/RecordManager/Finna/Solr/SolrUpdater.php +++ b/src/RecordManager/Finna/Solr/SolrUpdater.php @@ -29,16 +29,7 @@ namespace RecordManager\Finna\Solr; -use RecordManager\Base\Database\DatabaseInterface as Database; -use RecordManager\Base\Enrichment\PluginManager as EnrichmentPluginManager; -use RecordManager\Base\Http\HttpService as HttpService; use RecordManager\Base\Record\AbstractRecord; -use RecordManager\Base\Record\PluginManager as RecordPluginManager; -use RecordManager\Base\Settings\Ini; -use RecordManager\Base\Utils\FieldMapper; -use RecordManager\Base\Utils\Logger; -use RecordManager\Base\Utils\MetadataUtils; -use RecordManager\Base\Utils\WorkerPoolManager; use function in_array; use function intval; @@ -58,64 +49,6 @@ */ class SolrUpdater extends \RecordManager\Base\Solr\SolrUpdater { - /** - * Container title facet field - * - * @var string - */ - protected string $containerTitleFacetField = 'container_title_str_mv'; - - /** - * Constructor - * - * @param array $config Main configuration - * @param array $dataSourceConfig Data source settings - * @param ?Database $db Database connection - * @param Logger $log Logger - * @param RecordPluginManager $recordPM Record plugin manager - * @param EnrichmentPluginManager $enrichmentPM Enrichment plugin manager - * @param HttpService $httpService HTTP service - * @param Ini $configReader Configuration reader - * @param FieldMapper $fieldMapper Field mapper - * @param MetadataUtils $metadataUtils Metadata utilities - * @param WorkerPoolManager $workerPoolManager Worker pool manager - * - * @throws \Exception - * - * @psalm-suppress DuplicateArrayKey - */ - public function __construct( - array $config, - array $dataSourceConfig, - ?Database $db, - Logger $log, - RecordPluginManager $recordPM, - EnrichmentPluginManager $enrichmentPM, - HttpService $httpService, - Ini $configReader, - FieldMapper $fieldMapper, - MetadataUtils $metadataUtils, - WorkerPoolManager $workerPoolManager - ) { - parent::__construct( - $config, - $dataSourceConfig, - $db, - $log, - $recordPM, - $enrichmentPM, - $httpService, - $configReader, - $fieldMapper, - $metadataUtils, - $workerPoolManager - ); - $fields = $config['Solr Fields'] ?? []; - if (isset($fields['container_title_str_mv'])) { - $this->containerTitleFacetField = $fields['container_title_str_mv']; - } - } - /** * Add extra fields from settings etc. and map the values * @@ -141,13 +74,18 @@ protected function augmentAndProcessFields( $data['catalog_date'] = $date; } } - // Use hierarchy_top_title for ead and ead3 formats instead of hierarchy_parent_title. - if (in_array($record['format'], ['ead', 'ead3'])) { - if (isset($data['hierarchy_top_title'])) { - $data[$this->containerTitleFacetField] = (array)$data['hierarchy_top_title']; + if ( + $containerTitleFacetField = $this->config['Solr Fields']['container_title_facet'] + ?? 'container_title_str_mv' + ) { + // Use hierarchy_top_title for ead and ead3 formats instead of hierarchy_parent_title. + if (in_array($record['format'], ['ead', 'ead3'])) { + if (isset($data['hierarchy_top_title'])) { + $data[$containerTitleFacetField] = (array)$data['hierarchy_top_title']; + } + } elseif (isset($data[$this->hierarchyParentTitleField])) { + $data[$containerTitleFacetField] = (array)$data[$this->hierarchyParentTitleField]; } - } elseif (isset($data[$this->hierarchyParentTitleField])) { - $data[$this->containerTitleFacetField] = (array)$data[$this->hierarchyParentTitleField]; } $this->addSeriesKeys($data, $metadataRecord); } diff --git a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php index c4e7c8e7..889ea8a9 100644 --- a/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php +++ b/tests/RecordManagerTest/Finna/Solr/SolrUpdaterTest.php @@ -352,101 +352,72 @@ public static function getTestProcessSingleRecordData(): Generator [ 'record_format' => 'ead', 'allfields' => [ - 'blorf mipmip zaarl frrrp tikka meowzorp flibbin 1977 glarp', - 'mrrrp-blib-zoink', - 'zz-ploof-9911', - 'fiftypurr snorfle meep', - 'gribble snarrk floomtar wubbadee', - 'grk', - 'fnrr', + 'Ead record test title', + 'Test identifier', + '12-12-1999', + 'Test physical description', + 'Test physical location', + 'fin', + 'eng', 'Kralloo Mipsten', 'Snerpaloosi Instiploop', - 'flarpo 1', - 'glimfadoo 15 snarr Väinö Talas blorptik Floridana snooflepuff 5+5 min floof cutoff', - 'blip/intervuu', - 'Yhdysblat', + 'In web', + 'Test scope content', + 'test/interview', + 'Saksa', '11.11111, 22.22222', - 'Asikblar', - '33.33333, 44.44444', - 'Päijät-Hömp', - '55.55555, 66.66666', - 'Helsinkloof', - '77.77777, 88.88888', - 'Uusimrr', - '99.99999, -11.11111', - 'Clevorland', - '-22.22222, 33.33333', - 'Detroink', - '-44.44444, 55.55555', - 'Montablaa', - '-66.66666, 77.77777', - 'Duluthnoo', - '-88.88888, 99.99999', - 'Fort Loodle', - '12.34567, -76.54321', - 'Lake Worf', - 'mootlik', - 'sirtooz', - 'sirtiloot', - 'ulkosnarf', - 'amerisnarf', - 'floridansnarf', - 'eläkeblorp', - 'työbloop', - 'työnteek', - 'työväää', - 'talonrakblip', - 'järjestööf', + 'Somewhere', + 'Something', + 'Person interview', 'CC BY 4.0', - 'blorptik snoofle 1977-1978', - 'snarfloota kokoelma', + 'Hierarchy top title', + 'Hierarchy parent title', ], 'author2' => [ 'Kralloo Mipsten', ], - 'description' => 'glimfadoo 15 snarr Väinö Talas blorptik Floridana snooflepuff 5+5 min floof cutoff', - 'format' => 'blip/intervuu', + 'description' => 'Test scope content', + 'format' => 'test/interview', 'institution' => 'Snerpaloosi Instiploop', - 'language' => ['grk', 'fnrr'], - 'physical' => ['fiftypurr snorfle meep'], - 'title_full' => 'mrrrp-blib-zoink blorf mipmip zaarl frrrp tikka meowzorp flibbin 1977 glarp (9911)', - 'title_short' => 'blorf mipmip zaarl frrrp tikka', - 'title_sort' => 'blorf mipmip zaarl frrrp tikka meowzorp ', - 'title_sub' => 'mrrrp-blib-zoink', - 'title' => 'mrrrp-blib-zoink blorf mipmip zaarl frrrp tikka meowzorp flibbin 1977 glarp (9911)', + 'language' => ['fin', 'eng'], + 'physical' => ['Test physical description'], + 'title_full' => 'Test identifier Ead record test title (1999)', + 'title_short' => 'Ead record test title (1999)', + 'title_sort' => 'ead record test title (1999)', + 'title_sub' => 'Test identifier', + 'title' => 'Test identifier Ead record test title (1999)', 'topic_facet' => [ - 'mootlik','sirtooz','sirtiloot','ulkosnarf','amerisnarf','floridansnarf', - 'eläkeblorp','työbloop','työnteek','työväää','talonrakblip','järjestööf', + 'Something', + 'Person interview', ], 'topic' => [ - 'mootlik','sirtooz','sirtiloot','ulkosnarf','amerisnarf','floridansnarf', - 'eläkeblorp','työbloop','työnteek','työväää','talonrakblip','järjestööf', + 'Something', + 'Person interview', ], - 'location_geo' => 'POINT(-76.54321 12.34567)', - 'center_coords' => '-76.54321 12.34567', + 'location_geo' => 'POINT(22.22222 11.11111)', + 'center_coords' => '22.22222 11.11111', 'geographic_facet' => [ - 'Yhdysblat','Asikblar','Päijät-Hömp','Helsinkloof','Uusimrr','Clevorland', - 'Detroink','Montablaa','Duluthnoo','Fort Loodle','Lake Worf', + 'Saksa', + 'Somewhere', ], 'geographic' => [ - 'Yhdysblat','Asikblar','Päijät-Hömp','Helsinkloof','Uusimrr','Clevorland', - 'Detroink','Montablaa','Duluthnoo','Fort Loodle','Lake Worf', + 'Saksa', + 'Somewhere', ], 'hierarchytype' => 'Default', - 'hierarchy_top_id' => 'tost.272', - 'hierarchy_top_title' => 'blorptik snoofle 1977-1978', + 'hierarchy_top_id' => 'tost.271', + 'hierarchy_top_title' => 'Hierarchy top title', 'hierarchy_sequence' => '0000020', 'hierarchy_parent_id' => 'tost.272', - 'hierarchy_parent_title' => 'snarfloota kokoelma', + 'hierarchy_parent_title' => 'Hierarchy parent title', 'title_in_hierarchy' => [ - 'mrrrp-blib-zoink mrrrp-blib-zoink' - . ' blorf mipmip zaarl frrrp tikka meowzorp flibbin 1977 glarp', - ], - 'container_title_str_mv' => ['blorptik snoofle 1977-1978'], - 'unit_daterange' => '[9911-01-01 TO 9911-12-31]', - 'search_daterange_mv' => '[9911-01-01 TO 9911-12-31]', - 'main_date_str' => '9911', - 'main_date' => '9911-01-01T00:00:00Z', + 'Test identifier Test identifier Ead record test title', + ], + 'container_title_str_mv' => ['Hierarchy top title'], + 'unit_daterange' => '1999-12-12', + 'search_daterange_mv' => '1999-12-12', + 'main_date_str' => '1999', + 'main_date' => '1999-12-12T00:00:00Z', 'hierarchy_sequence_str' => '0000020', 'source_str_mv' => 'Snerpaloosi Instiploop', 'datasource_str_mv' => 'tost', @@ -454,17 +425,18 @@ public static function getTestProcessSingleRecordData(): Generator 'online_str_mv' => 'Snerpaloosi Instiploop', 'free_online_boolean' => '1', 'free_online_str_mv' => 'Snerpaloosi Instiploop', - 'identifier' => 'mrrrp-blib-zoink', + 'identifier' => 'Test identifier', 'material' => "\n \n ", 'usage_rights_str_mv' => ['CC BY 4.0'], 'usage_rights_ext_str_mv' => ['CC BY 4.0'], 'author_facet' => ['Kralloo Mipsten'], - 'format_ext_str_mv' => ['blip/intervuu'], + 'format_ext_str_mv' => ['test/interview'], 'media_type_str_mv' => ['audio/mpeg'], 'id' => 'test456', 'first_indexed' => '1970-01-01T00:00:00Z', 'last_indexed' => '1970-01-01T00:00:00Z', 'catalog_date' => '1970-01-01T00:00:00Z', + 'series' => 'Hierarchy parent title', ], ]; @@ -630,6 +602,121 @@ public static function getTestProcessSingleRecordData(): Generator ], ]; + $expectedEad3Results = [ + 'record_format' => 'ead3', + 'allfields' => [ + 'Test did note', + 'Test swe name', + 'Test eng name', + 'Test fin name', + 'Test id', + 'purr-238', + 'Test analogic id', + 'Test old id', + '1880-XX-XX/1880-XX-XX', + 'Test main title', + 'Reinmrr, Agaprr', + 'Suomi', + 'Image of test', + 'Tietosisältö', + 'Testi kuvaus', + 'Käyttöehdot', + 'CC BY-NC-ND 4.0 (miau-miau)', + 'Asiasanat ja luokat', + 'Testi 1', + 'Test 1', + 'Testi 2', + 'Test 2', + 'Etelä-Karjala-mrr', + 'Test hierarchy top title', + '173852008554500', + ], + 'author' => [ + 'Reinmrr, Agaprr', + ], + 'author_sort' => 'Reinmrr, Agaprr', + 'description' => 'Testi kuvaus', + 'format' => 'Testi 1/Testi 2', + 'geographic_facet' => [ + 'Etelä-Karjala-mrr', + ], + 'geographic' => [ + 'Etelä-Karjala-mrr', + ], + 'institution' => 'SKS KRA', + 'language' => [ + 'fin', + ], + 'series' => 'Test hierarchy parent title', + 'thumbnail' => 'https://example.com/frobnar/thumb', + 'title_full' => 'Test id Test main title‎ (1880)', + 'title_short' => 'Test main title‎ (1880)', + 'title_sort' => 'test id test main title‎ (1880)', + 'title_sub' => 'Test id', + 'title' => 'Test id Test main title‎ (1880)', + 'hierarchytype' => 'Default', + 'hierarchy_top_id' => 'cat_archive.173852005642800', + 'hierarchy_top_title' => 'Test hierarchy top title', + 'hierarchy_sequence' => '0000464', + 'hierarchy_parent_id' => 'cat_archive.173852005642800_173852006211600', + 'hierarchy_parent_title' => 'Test hierarchy parent title', + 'title_in_hierarchy' => [ + 'Test id Test id Test main title', + ], + 'container_title_str_mv' => [ + 'Test hierarchy top title', + ], + 'unit_daterange' => '[1880-01-01 TO 1880-12-31]', + 'search_daterange_mv' => [ + '[1880-01-01 TO 1880-12-31]', + ], + 'era_facet' => '1880', + 'main_date_str' => '1880', + 'main_date' => '1880-01-01T00:00:00Z', + 'hierarchy_sequence_str' => '0000464', + 'source_str_mv' => 'SKS KRA', + 'datasource_str_mv' => 'cat_archive', + 'online_boolean' => '1', + 'online_str_mv' => 'SKS KRA', + 'free_online_boolean' => '1', + 'free_online_str_mv' => 'SKS KRA', + 'identifier' => '173852008554500', + 'media_type_str_mv' => [ + 'image/jpeg', + ], + 'usage_rights_str_mv' => [ + 'https://creativecommons.org/licenses/by-nc-nd/4.0/deed.fi', + ], + 'usage_rights_ext_str_mv' => [ + 'https://creativecommons.org/licenses/by-nc-nd/4.0/deed.fi', + ], + 'author_facet' => [ + 'Reinmrr, Agaprr', + ], + 'author2_id_str_mv' => [ + 'EAC_228481117', + ], + 'author2_id_role_str_mv' => [ + 'EAC_228481117###Arkistonmuodostaja', + 'EAC_228481117###Kuvataiteilija', + ], + 'format_ext_str_mv' => 'Testi 1/Testi 2', + 'geographic_id_str_mv' => [ + 'http://www.yso.fi/onto/yso/p94106', + ], + 'file_identifier_str_mv' => [ + 'mrr_full.tif', + 'mrr_thumb.tif', + ], + 'id' => 'ttt111', + 'work_keys_str_mv' => [ + 'AT reinmrragaprr tes', + ], + 'first_indexed' => '1970-01-01T00:00:00Z', + 'last_indexed' => '1970-01-01T00:00:00Z', + 'catalog_date' => '1970-01-01T00:00:00Z', + ]; + yield 'Test single ead3 record with hierarchy top title' => [ [ '_id' => 'ttt111', @@ -644,123 +731,28 @@ public static function getTestProcessSingleRecordData(): Generator 'original_data' => 'SolrUpdaterTest/ead3.xml', 'normalized_data' => null, ], + $expectedEad3Results, + ]; + unset($expectedEad3Results['container_title_str_mv']); + yield 'Test single ead3 record with setting container_title_facet setting to an empty value' => [ [ - 'record_format' => 'ead3', - 'allfields' => [ - 'Mrr-fluff nyaff', - 'Mjaau skrelli prr-vump', - 'Nya-frobble prrr-chant', - 'Prrlax miau-ponkeli strav-mrr', - 'mrr-glimzor', - 'purr-238', - 'miau-floo 1880:85:311-85:311', - 'ffrrp-245348772', - '1880–mrr-grunk', - 'Miauska skreppa-prr', - 'Reinmrr, Agaprr', - 'Kattin kieli', - 'Ilmentymä: Prr-kuva (Digimiau)', - 'Tietosisältö', - 'Mrr-maalaus maisemasta, jossa on kallioita, metsää ja järvi-miau.' - . ' Aihe mahdollisesti Jaakkimasta, mutta kissa ei kerro.', - 'Käyttöehdot', - 'CC BY-NC-ND 4.0 (miau-miau)', - 'Asiasanat ja luokat', - 'Kuva-mrr', - 'Bild-mjaau', - 'Image-nya', - 'Maalaus-prr', - 'Målning-mjaau', - 'Painting-nyaff', - 'Etelä-Karjala-mrr', - 'Random collection title', - '173852008554500', - ], - 'author' => [ - 'Reinmrr, Agaprr', - ], - 'author_sort' => 'Reinmrr, Agaprr', - 'description' => 'Mrr-maalaus maisemasta, jossa on kallioita,' - . ' metsää ja järvi-miau. Aihe mahdollisesti Jaakkimasta, mutta kissa ei kerro.', - 'format' => 'Kuva-mrr/Maalaus-prr', - 'geographic_facet' => [ - 'Etelä-Karjala-mrr', - ], - 'geographic' => [ - 'Etelä-Karjala-mrr', - ], - 'institution' => 'SKS KRA', - 'language' => [ - 'fin', - ], - 'series' => 'Kansatieteellisiä piirroksia Etelä-Karjalasta', - 'thumbnail' => 'https://example.com/frobnar/thumb', - 'title_full' => 'mrr-glimzor Miauska skreppa-prr‎ (1880)', - 'title_short' => 'Miauska skreppa-prr‎ (1880)', - 'title_sort' => 'mrr glimzor miauska skreppa prr‎ (1880)', - 'title_sub' => 'mrr-glimzor', - 'title' => 'mrr-glimzor Miauska skreppa-prr‎ (1880)', - 'hierarchytype' => 'Default', - 'hierarchy_top_id' => 'cat_archive.173852005642800', - 'hierarchy_top_title' => 'Random collection title', - 'hierarchy_sequence' => '0000464', - 'hierarchy_parent_id' => 'cat_archive.173852005642800_173852006211600', - 'hierarchy_parent_title' => 'Kansatieteellisiä piirroksia Etelä-Karjalasta', - 'title_in_hierarchy' => [ - 'mrr-glimzor mrr-glimzor Miauska skreppa-prr', - ], - 'container_title_str_mv' => [ - 'Random collection title', - ], - 'unit_daterange' => '[1880-01-01 TO 1880-12-31]', - 'search_daterange_mv' => [ - '[1880-01-01 TO 1880-12-31]', - ], - 'era_facet' => '1880', - 'main_date_str' => '1880', - 'main_date' => '1880-01-01T00:00:00Z', - 'hierarchy_sequence_str' => '0000464', - 'source_str_mv' => 'SKS KRA', - 'datasource_str_mv' => 'cat_archive', - 'online_boolean' => '1', - 'online_str_mv' => 'SKS KRA', - 'free_online_boolean' => '1', - 'free_online_str_mv' => 'SKS KRA', - 'identifier' => '173852008554500', - 'media_type_str_mv' => [ - 'image/jpeg', - ], - 'usage_rights_str_mv' => [ - 'https://creativecommons.org/licenses/by-nc-nd/4.0/deed.fi', - ], - 'usage_rights_ext_str_mv' => [ - 'https://creativecommons.org/licenses/by-nc-nd/4.0/deed.fi', - ], - 'author_facet' => [ - 'Reinmrr, Agaprr', - ], - 'author2_id_str_mv' => [ - 'EAC_228481117', - ], - 'author2_id_role_str_mv' => [ - 'EAC_228481117###Arkistonmuodostaja', - 'EAC_228481117###Kuvataiteilija', - ], - 'format_ext_str_mv' => 'Kuva-mrr/Maalaus-prr', - 'geographic_id_str_mv' => [ - 'http://www.yso.fi/onto/yso/p94106', - ], - 'file_identifier_str_mv' => [ - 'mrr_full.tif', - 'mrr_thumb.tif', - ], - 'id' => 'ttt111', - 'work_keys_str_mv' => [ - 'AT reinmrragaprr mrr', + '_id' => 'ttt111', + 'oai_id' => '', + 'linking_id' => [], + 'source_id' => 'cat_archive', + 'deleted' => false, + 'created' => $date, + 'updated' => $date, + 'date' => $date, + 'format' => 'ead3', + 'original_data' => 'SolrUpdaterTest/ead3.xml', + 'normalized_data' => null, + ], + $expectedEad3Results, + [ + 'Solr Fields' => [ + 'container_title_facet' => '', ], - 'first_indexed' => '1970-01-01T00:00:00Z', - 'last_indexed' => '1970-01-01T00:00:00Z', - 'catalog_date' => '1970-01-01T00:00:00Z', ], ]; } @@ -770,15 +762,17 @@ public static function getTestProcessSingleRecordData(): Generator * * @param array $dbRecord Array presenting a record from database to be processed. * @param array $expected Array for expected test results + * @param array $config Main config * * @return void */ #[\PHPUnit\Framework\Attributes\DataProvider('getTestProcessSingleRecordData')] - public function testProcessSingleRecord(array $dbRecord, array $expected): void + public function testProcessSingleRecord(array $dbRecord, array $expected, array $config = []): void { $dbRecord['original_data'] = $this->getFixture($dbRecord['original_data'], 'Finna'); + $config = array_merge_recursive($this->config, $config); $database = $this->getDatabase(); - $solrUpdater = $this->getSolrUpdater(database: $database); + $solrUpdater = $this->getSolrUpdater(database: $database, config: $config); $result = $solrUpdater->processSingleRecord($dbRecord); $testRecord = $result['records'][0]; // Leave out testing full record but confirm that it exists. @@ -834,13 +828,15 @@ protected function getDatabase( * @param array $dsConfigOverrides Data source config overrides * @param array $dbRecord Database record * @param MockObject|DatabaseInterface|null $database Database mock object + * @param array $config Main config * * @return SolrUpdater */ protected function getSolrUpdater( array $dsConfigOverrides = [], array $dbRecord = [], - MockObject|DatabaseInterface|null $database = null + MockObject|DatabaseInterface|null $database = null, + array $config = [] ): SolrUpdater { $dsConfig = array_merge_recursive( $this->dataSourceConfig, @@ -948,7 +944,7 @@ function ($format, $data, $oaiID, $source, $extraData = []) use ($marcRecord) { $this->dataSourceConfig ); $solrUpdater = new SolrUpdater( - $this->config, + $config, $dsConfig, $database, $logger, diff --git a/tests/fixtures/Finna/SolrUpdaterTest/ead.xml b/tests/fixtures/Finna/SolrUpdaterTest/ead.xml index d6b981b9..6bdbc70d 100644 --- a/tests/fixtures/Finna/SolrUpdaterTest/ead.xml +++ b/tests/fixtures/Finna/SolrUpdaterTest/ead.xml @@ -1,16 +1,16 @@ - blorf mipmip zaarl frrrp tikka meowzorp flibbin 1977 glarp - mrrrp-blib-zoink - zz-ploof-9911 + Ead record test title + Test identifier + 12-12-1999 - fiftypurr snorfle meep + Test physical description - gribble snarrk floomtar wubbadee + Test physical location - grk - fnrr + fin + eng Kralloo Mipsten @@ -20,82 +20,36 @@ -

flarpo 1

+

In web

-

glimfadoo 15 snarr Väinö Talas blorptik Floridana snooflepuff 5+5 min floof cutoff

+

Test scope content

- blip/intervuu + test/interview - Yhdysblat + Saksa 11.11111, 22.22222 - Asikblar - - - 33.33333, 44.44444 - Päijät-Hömp - - - 55.55555, 66.66666 - Helsinkloof - - - 77.77777, 88.88888 - Uusimrr - - - 99.99999, -11.11111 - Clevorland - - - -22.22222, 33.33333 - Detroink - - - -44.44444, 55.55555 - Montablaa - - - -66.66666, 77.77777 - Duluthnoo - - - -88.88888, 99.99999 - Fort Loodle - - - 12.34567, -76.54321 - Lake Worf + Somewhere - mootlik - sirtooz - sirtiloot - ulkosnarf - amerisnarf - floridansnarf - eläkeblorp - työbloop - työnteek - työväää - talonrakblip - järjestööf + Something + Person interview

CC BY 4.0

- - + +
diff --git a/tests/fixtures/Finna/SolrUpdaterTest/ead3.xml b/tests/fixtures/Finna/SolrUpdaterTest/ead3.xml index 751dcf6b..ef2ed543 100644 --- a/tests/fixtures/Finna/SolrUpdaterTest/ead3.xml +++ b/tests/fixtures/Finna/SolrUpdaterTest/ead3.xml @@ -1,39 +1,39 @@ - Mrr-fluff nyaff + Test did note - Mjaau skrelli prr-vump - Nya-frobble prrr-chant - Prrlax miau-ponkeli strav-mrr + Test swe name + Test eng name + Test fin name - mrr-glimzor + Test id purr-238 - miau-floo 1880:85:311-85:311 - ffrrp-245348772 - 1880–mrr-grunk - Miauska skreppa-prr + Test analogic id + Test old id + 1880-XX-XX/1880-XX-XX + Test main title Reinmrr, Agaprr - Kattin kieli + Suomi -

Ilmentymä: Prr-kuva (Digimiau)

+

Image of test

Tietosisältö -

Mrr-maalaus maisemasta, jossa on kallioita, metsää ja järvi-miau. Aihe mahdollisesti Jaakkimasta, mutta kissa ei kerro.

+

Testi kuvaus

Käyttöehdot @@ -49,22 +49,22 @@ Asiasanat ja luokat - Kuva-mrr - Bild-mjaau - Image-nya + Testi 1 + Test 1 + Test 1 - Maalaus-prr - Målning-mjaau - Painting-nyaff + Testi 2 + Test 2 + Test 2 Etelä-Karjala-mrr - - - + + +
From 5a5f986777463c247007da6f14a2353b3d708f14 Mon Sep 17 00:00:00 2001 From: Juha Luoma Date: Tue, 26 May 2026 08:12:53 +0300 Subject: [PATCH 14/14] Added check for empty hierarchyParentTitleField --- src/RecordManager/Finna/Solr/SolrUpdater.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RecordManager/Finna/Solr/SolrUpdater.php b/src/RecordManager/Finna/Solr/SolrUpdater.php index 6b0490ba..5b026ce2 100644 --- a/src/RecordManager/Finna/Solr/SolrUpdater.php +++ b/src/RecordManager/Finna/Solr/SolrUpdater.php @@ -83,7 +83,7 @@ protected function augmentAndProcessFields( if (isset($data['hierarchy_top_title'])) { $data[$containerTitleFacetField] = (array)$data['hierarchy_top_title']; } - } elseif (isset($data[$this->hierarchyParentTitleField])) { + } elseif ($this->hierarchyParentTitleField && isset($data[$this->hierarchyParentTitleField])) { $data[$containerTitleFacetField] = (array)$data[$this->hierarchyParentTitleField]; } }