Skip to content

Commit

Permalink
Refactor solr mapping from arSolrPlugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung committed Aug 28, 2024
1 parent 488cfb5 commit fd9068d
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 38 deletions.
78 changes: 78 additions & 0 deletions plugins/arSolrPlugin/lib/arSolrMapping.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public function loadArray($mapping_array)
$this->fixYamlShorthands();

$this->excludeNestedOnlyTypes();

$this->addMultivalueExceptions();
}
}

Expand Down Expand Up @@ -499,4 +501,80 @@ protected function addSortFields($nestedI18nFields, $typeProperties)

return $nestedI18nFields;
}

protected function addMultivalueExceptions()
{
$multivalueFields = [
'QubitInformationObject.dates.sourceCulture',
'QubitInformationObject.names.otherNames.sourceCulture',
'QubitInformationObject.creators.otherNames.sourceCulture',
'QubitInformationObject.inheritedCreators.otherNames.sourceCulture',
'QubitInformationObject.generalNotes.sourceCulture',
'QubitActor.otherNames.sourceCulture',
'QubitRepository.contactInformations.sourceCulture',
'QubitActor.otherNames.i18n.*.name',
'QubitActor.occupations.i18n.*.name',
'QubitActor.occupations.i18n.*.content',
'QubitActor.parallelNames.i18n.*.name',
'QubitActor.standardizedNames.i18n.*.name',
'QubitRepository.contactInformations.i18n.*.contactType',
'QubitRepository.contactInformations.i18n.*.city',
'QubitRepository.contactInformations.i18n.*.region',
'QubitInformationObject.creators.i18n.*.authorizedFormOfName',
'QubitInformationObject.creators.i18n.*.history',
'QubitInformationObject.creators.otherNames.i18n.*.name',
'QubitInformationObject.genres.i18n.*.name',
'QubitInformationObject.places.i18n.*.name',
'QubitInformationObject.subjects.i18n.*.name',
'QubitInformationObject.inheritedCreators.i18n.*.authorizedFormOfName',
'QubitInformationObject.inheritedCreators.otherNames.i18n.*.name',
'QubitInformationObject.names.otherNames.i18n.*.name',
'QubitInformationObject.generalNotes.i18n.*.content',
'QubitInformationObject.names.i18n.*.authorizedFormOfName',
'QubitInformationObject.dates.i18n.*.date',
];

foreach ($multivalueFields as $field) {
$properties = explode('.', $field);
$properties[0] = str_replace('Qubit', '', $properties[0]);
$properties[0] = lcfirst($properties[0]);

if ('*' == $properties[count($properties) - 2]) {
foreach (sfConfig::get('app_i18n_languages') as $lang) {
$path = [];
foreach ($properties as $property) {
if ('*' == $property) {
array_push($path, $lang);
} else {
array_push($path, $property);
}
array_push($path, 'properties');
}
array_pop($path);
$this->setMultivalueException($path);
}
} else {
$path = [];
foreach ($properties as $property) {
array_push($path, $property);
array_push($path, 'properties');
}

array_pop($path);
$this->setMultivalueException($path);
}
}
}

protected function setMultivalueException($keypath)
{
$mapping = &$this->mapping;
foreach ($keypath as $key) {
if (!array_key_exists($key, $mapping)) {
$mapping[$key] = [];
}
$mapping = &$mapping[$key];
}
$mapping['multivalue'] = 'true';
}
}
63 changes: 25 additions & 38 deletions plugins/arSolrPlugin/lib/arSolrPlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,40 +363,11 @@ private function addSubProperties($properties, &$propertyFields, $parentType = '
array_push($this->langs, $lang);
}

// TODO: avoid adding multivalue fields via a large list of exceptions and patterns
$i18nIndex = array_search('i18n', $fields);
if ('languages' == $propertyName
|| 'QubitInformationObject.dates.sourceCulture' == $fieldName
|| 'QubitInformationObject.names.otherNames.sourceCulture' == $fieldName
|| 'QubitInformationObject.creators.otherNames.sourceCulture' == $fieldName
|| 'QubitInformationObject.inheritedCreators.otherNames.sourceCulture' == $fieldName
|| 'QubitInformationObject.generalNotes.sourceCulture' == $fieldName
|| 'QubitActor.otherNames.sourceCulture' == $fieldName
|| 'QubitRepository.contactInformations.sourceCulture' == $fieldName
|| fnmatch('QubitActor.otherNames.i18n.*.name', $fieldName)
|| fnmatch('QubitActor.occupations.i18n.*.name', $fieldName)
|| fnmatch('QubitActor.occupations.i18n.*.content', $fieldName)
|| fnmatch('QubitActor.parallelNames.i18n.*.name', $fieldName)
|| fnmatch('QubitActor.standardizedNames.i18n.*.name', $fieldName)
|| fnmatch('QubitRepository.contactInformations.i18n.*.contactType', $fieldName)
|| fnmatch('QubitRepository.contactInformations.i18n.*.city', $fieldName)
|| fnmatch('QubitRepository.contactInformations.i18n.*.region', $fieldName)
|| fnmatch('QubitInformationObject.creators.i18n.*.authorizedFormOfName', $fieldName)
|| fnmatch('QubitInformationObject.creators.i18n.*.history', $fieldName)
|| fnmatch('QubitInformationObject.creators.otherNames.i18n.*.name', $fieldName)
|| fnmatch('QubitInformationObject.genres.i18n.*.name', $fieldName)
|| fnmatch('QubitInformationObject.places.i18n.*.name', $fieldName)
|| fnmatch('QubitInformationObject.subjects.i18n.*.name', $fieldName)
|| fnmatch('QubitInformationObject.inheritedCreators.i18n.*.authorizedFormOfName', $fieldName)
|| fnmatch('QubitInformationObject.generalNotes.i18n.*.content', $fieldName)
|| fnmatch('QubitInformationObject.names.i18n.*.authorizedFormOfName', $fieldName)
|| fnmatch('QubitInformationObject.dates.i18n.*.date', $fieldName)
) {
$multiValue = true;
} elseif ($value['multivalue'] && false == $i18nIndex) {
if ('languages' == $propertyName || ($value['multivalue'] && false == $i18nIndex)) {
$multiValue = true;
} else {
$multiValue = $this->getMultiValue($parentProperties[$fields[$i18nIndex - 2]]['properties']);
$multiValue = $this->getMultiValue($fieldName);
}

if (in_array($value['type'], $atomicTypes)) {
Expand All @@ -418,17 +389,33 @@ private function addSubProperties($properties, &$propertyFields, $parentType = '
}
}

private function getMultiValue($properties)
private function getMultiValue($fieldName)
{
$properties = explode('.', $fieldName);
$properties[0] = str_replace('Qubit', '', $properties[0]);
$properties[0] = lcfirst($properties[0]);

$path = [];
foreach ($properties as $property) {
if (null != $property['type']) {
if ($property['multivalue']) {
return true;
}
} else {
$this->getMultiValue($property);
array_push($path, $property);
array_push($path, 'properties');
}

array_pop($path);

$mapping = &$this->mappings;
foreach ($path as $key) {
if (!array_key_exists($key, $mapping)) {
$mapping[$key] = [];
}
$mapping = &$mapping[$key];
}

if (array_key_exists('multivalue', $mapping)) {
return true;
}

return false;
}

private function setLanguageType($fieldName)
Expand Down

0 comments on commit fd9068d

Please sign in to comment.