Created
January 30, 2017 08:02
-
-
Save NeoBlack/10b40419f2836cd29efe88fc165495b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace FooBar\BarFoo\Solr\IndexQueue; | |
use ApacheSolrForTypo3\Solr\IndexQueue\InvalidFieldNameException; | |
/** | |
* Class Indexer | |
* | |
* @package FooBar\BarFoo\Solr\IndexQueue | |
*/ | |
class Indexer extends \ApacheSolrForTypo3\Solr\IndexQueue\Indexer | |
{ | |
/** | |
* Holds field names that are denied to overwrite in thy indexing configuration. | |
* | |
* @var array | |
*/ | |
protected static $unAllowedOverrideFields = []; | |
/** | |
* @param string $solrFieldName | |
* @return bool | |
*/ | |
public static function isAllowedToOverrideField($solrFieldName) | |
{ | |
return !in_array($solrFieldName, static::$unAllowedOverrideFields); | |
} | |
/** | |
* Adds fields to the document as defined in $indexingConfiguration | |
* | |
* @param \Apache_Solr_Document $document base document to add fields to | |
* @param array $indexingConfiguration Indexing configuration / mapping | |
* @param array $data Record data | |
* | |
* @return \Apache_Solr_Document Modified document with added fields | |
* @throws \ApacheSolrForTypo3\Solr\IndexQueue\InvalidFieldNameException | |
*/ | |
protected function addDocumentFieldsFromTyposcript( | |
\Apache_Solr_Document $document, | |
array $indexingConfiguration, | |
array $data | |
) { | |
// mapping of record fields => solr document fields, resolving cObj | |
foreach ($indexingConfiguration as $solrFieldName => $recordFieldName) { | |
if (is_array($recordFieldName)) { | |
// configuration for a content object, skipping | |
continue; | |
} | |
if (!static::isAllowedToOverrideField($solrFieldName)) { | |
throw new InvalidFieldNameException( | |
'Must not overwrite field .' . $solrFieldName, | |
1435441863 | |
); | |
} | |
$fieldValue = $this->resolveFieldValue($indexingConfiguration, | |
$solrFieldName, $data); | |
if (is_array($fieldValue)) { | |
// multi value | |
foreach ($fieldValue as $multiValue) { | |
$document->addField($solrFieldName, $multiValue); | |
} | |
} else { | |
if ($fieldValue !== '' && $fieldValue !== null) { | |
$document->setField($solrFieldName, $fieldValue); | |
} | |
} | |
} | |
return $document; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment