diff --git a/classes/search/PreprintSearch.php b/classes/search/PreprintSearch.php index 75669d6b63..12491ed441 100644 --- a/classes/search/PreprintSearch.php +++ b/classes/search/PreprintSearch.php @@ -23,9 +23,7 @@ use APP\core\Request; use APP\facades\Repo; use APP\server\Server; -use PKP\controlledVocab\ControlledVocab; use PKP\db\DAORegistry; -use PKP\facades\Locale; use PKP\plugins\Hook; use PKP\search\SubmissionSearch; use PKP\submission\PKPSubmission; @@ -320,16 +318,16 @@ public function getSimilarityTerms($submissionId) $preprint = Repo::submission()->get($submissionId); if ($preprint->getData('status') === PKPSubmission::STATUS_PUBLISHED) { // Retrieve keywords (if any). - $allSearchTerms = array_filter( - Repo::controlledVocab()->getBySymbolic( - ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, - Application::ASSOC_TYPE_PUBLICATION, - $preprint->getId(), - [Locale::getLocale(), $preprint->getData('locale'), Locale::getPrimaryLocale()] + $allSearchTerms = collect($article->getCurrentPublication()->getData('keywords')) + ->map( + fn (array $items): array => collect($items) + ->pluck('name') + ->all() ) - ); + ->all(); + foreach ($allSearchTerms as $locale => $localeSearchTerms) { - $searchTerms += $localeSearchTerms; + $searchTerms = array_merge($searchTerms, $localeSearchTerms); } } } diff --git a/classes/search/PreprintSearchIndex.php b/classes/search/PreprintSearchIndex.php index eb9a1a53b6..31763139af 100644 --- a/classes/search/PreprintSearchIndex.php +++ b/classes/search/PreprintSearchIndex.php @@ -391,12 +391,16 @@ protected function _updateTextIndex($preprintId, $type, $text, $assocId = null) protected function _flattenLocalizedArray($arrayWithLocales) { $flattenedArray = []; + foreach ($arrayWithLocales as $localeArray) { - $flattenedArray = array_merge( - $flattenedArray, + $names = array_map( + static fn ($item) => $item['name'], $localeArray ); + + $flattenedArray = array_merge($flattenedArray, $names); } + return $flattenedArray; } } diff --git a/lib/pkp b/lib/pkp index 3d0d78f292..9416a42243 160000 --- a/lib/pkp +++ b/lib/pkp @@ -1 +1 @@ -Subproject commit 3d0d78f292adc2d9e43d9f9f182fbaf5eec3cf9e +Subproject commit 9416a42243274916a49f21ea7d0bd9b9fec44f43 diff --git a/plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php b/plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php index d9235ba412..c335e63f11 100644 --- a/plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php +++ b/plugins/metadata/dc11/filter/Dc11SchemaPreprintAdapter.php @@ -26,7 +26,6 @@ use APP\oai\ops\OAIDAO; use APP\plugins\PubIdPlugin; use APP\submission\Submission; -use PKP\controlledVocab\ControlledVocab; use PKP\db\DAORegistry; use PKP\metadata\MetadataDataObjectAdapter; use PKP\metadata\MetadataDescription; @@ -87,16 +86,20 @@ public function &extractMetadataFromDataObject(&$submission) // Subject $subjects = array_merge_recursive( - Repo::controlledVocab()->getBySymbolic( - ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, - Application::ASSOC_TYPE_PUBLICATION, - $publication->getId() - ), - Repo::controlledVocab()->getBySymbolic( - ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, - Application::ASSOC_TYPE_PUBLICATION, - $publication->getId() - ) + collect($publication->getData('keywords')) + ->map( + fn (array $items): array => collect($items) + ->pluck('name') + ->all() + ) + ->all(), + collect($publication->getData('subjects')) + ->map( + fn (array $items): array => collect($items) + ->pluck('name') + ->all() + ) + ->all() ); $this->_addLocalizedElements($dc11Description, 'dc:subject', $subjects); diff --git a/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php b/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php index 69c4ec2bd4..fae3d3cc3e 100755 --- a/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php +++ b/plugins/oaiMetadataFormats/dc/tests/OAIMetadataFormat_DCTest.php @@ -38,6 +38,7 @@ use Mockery; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; +use PKP\controlledVocab\ControlledVocab; use PKP\controlledVocab\Repository as ControlledVocabRepository; use PKP\core\Dispatcher; use PKP\core\Registry; @@ -96,6 +97,27 @@ public function testToXml() ]); $author->setEmail('someone@example.com'); + /** @var ControlledVocabRepository|MockObject */ + $controlledVocabRepoMock = Mockery::mock(ControlledVocabRepository::class) + ->makePartial() + ->shouldReceive('getBySymbolic') + ->twice() + ->andReturn( + [ + 'en' => [ + ['name' => 'preprint-keyword'], + ] + ], + [ + 'en' => [ + ['name' => 'preprint-subject'], + ['name' => 'preprint-subject-class'], + ] + ] + ) + ->getMock(); + app()->instance(ControlledVocabRepository::class, $controlledVocabRepoMock); + /** @var Publication|MockObject */ $publication = $this->getMockBuilder(Publication::class) ->onlyMethods([]) @@ -113,6 +135,24 @@ public function testToXml() $publication->setData('copyrightYear', 'year'); $publication->setData('datePublished', '2010-11-05'); $publication->setData('authors', collect([$author])); + $publication->setData( + 'keywords', + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_KEYWORD, + 0, + Application::ASSOC_TYPE_PUBLICATION + )['en'], + 'en' + ); + $publication->setData( + 'subjects', + Repo::controlledVocab()->getBySymbolic( + ControlledVocab::CONTROLLED_VOCAB_SUBMISSION_SUBJECT, + 0, + Application::ASSOC_TYPE_PUBLICATION + )['en'], + 'en' + ); // Preprint /** @var Submission|MockObject */ @@ -241,19 +281,6 @@ public function testToXml() ->willReturn(LazyCollection::wrap($galleys)); app()->instance(GalleyCollector::class, $mockGalleyCollector); - $controlledVocabRepoMock = Mockery::mock(ControlledVocabRepository::class) - ->makePartial() - ->shouldReceive('getBySymbolic') - ->twice() - ->withAnyArgs() - ->andReturn( - ['en' => ['preprint-keyword']], - ['en' => ['preprint-subject', 'preprint-subject-class']] - ) - ->getMock(); - - app()->instance(ControlledVocabRepository::class, $controlledVocabRepoMock); - // // Test // diff --git a/templates/frontend/objects/preprint_details.tpl b/templates/frontend/objects/preprint_details.tpl index daa05717c1..01a2e05a87 100644 --- a/templates/frontend/objects/preprint_details.tpl +++ b/templates/frontend/objects/preprint_details.tpl @@ -183,7 +183,7 @@ {foreach name="keywords" from=$publication->getLocalizedData('keywords') item="keyword"} - {$keyword|escape}{if !$smarty.foreach.keywords.last}{translate key="common.commaListSeparator"}{/if} + {$keyword.name|escape}{if $keyword.identifier} ({$keyword.identifier|escape}){/if}{if !$smarty.foreach.keywords.last}{translate key="common.commaListSeparator"}{/if} {/foreach} diff --git a/templates/frontend/objects/preprint_summary.tpl b/templates/frontend/objects/preprint_summary.tpl index 2d693b65ef..2f3a69cbd8 100644 --- a/templates/frontend/objects/preprint_summary.tpl +++ b/templates/frontend/objects/preprint_summary.tpl @@ -83,7 +83,7 @@