Skip to content

Commit fc39af5

Browse files
authored
Merge pull request #9 from michaelkubina-subhh/5.0.6_subhh_improve_indexer
[FEATURE] Include facets from all associated metadata sections for fulltext pages
2 parents b959499 + e5c3ce3 commit fc39af5

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

Classes/Common/Indexer.php

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,9 @@ protected static function processPhysical(Document $document, int $page, array $
407407

408408
$solrDoc->setField('fulltext', $fullText);
409409
if (is_array($doc->metadataArray[$doc->toplevelId])) {
410-
self::addFaceting($doc, $solrDoc);
411-
}
412-
// Add collection information to physical sub-elements if applicable.
413-
if (
414-
in_array('collection', self::$fields['facets'])
415-
&& !empty($doc->metadataArray[$doc->toplevelId]['collection'])
416-
) {
417-
$solrDoc->setField('collection_faceting', $doc->metadataArray[$doc->toplevelId]['collection']);
410+
self::addFaceting($doc, $solrDoc, $physicalUnit);
418411
}
412+
419413
try {
420414
$updateQuery->addDocument($solrDoc);
421415
self::$solr->service->update($updateQuery);
@@ -502,26 +496,56 @@ private static function processMetadata($document, $metadata, &$solrDoc): array
502496
*
503497
* @param AbstractDocument $doc
504498
* @param DocumentInterface &$solrDoc
499+
* @param array $physicalUnit Array of the physical unit to process
505500
*
506501
* @return void
507502
*/
508-
private static function addFaceting($doc, &$solrDoc): void
503+
private static function addFaceting($doc, &$solrDoc, $physicalUnit): void
509504
{
510-
foreach ($doc->metadataArray[$doc->toplevelId] as $indexName => $data) {
505+
// this variable holds all possible facet-values for the index names
506+
$facets = [];
507+
// use the structlink information
508+
foreach ($doc->smLinks['l2p'] as $logicalId => $physicalId) {
509+
// find page in structlink
510+
if (in_array($physicalUnit['id'], $physicalId)) {
511+
// for each associated metadata of structlink
512+
foreach ($doc->metadataArray[$logicalId] as $indexName => $data) {
513+
if (
514+
!empty($data)
515+
&& substr($indexName, -8) !== '_sorting'
516+
) {
517+
if (in_array($indexName, self::$fields['facets'])) {
518+
// Remove appended "valueURI" from authors' names for indexing.
519+
if ($indexName == 'author') {
520+
$data = self::removeAppendsFromAuthor($data);
521+
}
522+
// Add facets to facet-array and flatten the values
523+
if (is_array($data)) {
524+
foreach ($data as $value) {
525+
if (!empty($value)) {
526+
$facets[$indexName][] = $value;
527+
}
528+
}
529+
} else {
530+
$facets[$indexName][] = $data;
531+
}
532+
}
533+
}
534+
}
535+
}
536+
}
537+
538+
// write all facet values of associated metadata to the page (self & ancestors)
539+
foreach ($facets as $indexName => $data) {
511540
if (
512541
!empty($data)
513-
&& substr($indexName, -8) !== '_sorting'
514542
) {
515-
516-
if (in_array($indexName, self::$fields['facets'])) {
517-
// Remove appended "valueURI" from authors' names for indexing.
518-
if ($indexName == 'author') {
519-
$data = self::removeAppendsFromAuthor($data);
520-
}
521-
// Add facets to index.
522-
$solrDoc->setField($indexName . '_faceting', $data);
523-
}
543+
$solrDoc->setField($indexName . '_faceting', $data);
524544
}
545+
}
546+
547+
// add sorting information
548+
foreach ($doc->metadataArray[$doc->toplevelId] as $indexName => $data) {
525549
// Add sorting information to physical sub-elements if applicable.
526550
if (
527551
!empty($data)

0 commit comments

Comments
 (0)