first commit
This commit is contained in:
@@ -27,7 +27,7 @@ namespace WapplerSystems\Meilisearch\IndexQueue;
|
||||
use WapplerSystems\Meilisearch\ContentObject\Classification;
|
||||
use WapplerSystems\Meilisearch\ContentObject\Multivalue;
|
||||
use WapplerSystems\Meilisearch\ContentObject\Relation;
|
||||
use WapplerSystems\Meilisearch\System\Solr\Document\Document;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Document\Document;
|
||||
use TYPO3\CMS\Core\Core\Environment;
|
||||
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
@@ -57,12 +57,12 @@ abstract class AbstractIndexer
|
||||
protected static $unAllowedOverrideFields = ['type'];
|
||||
|
||||
/**
|
||||
* @param string $solrFieldName
|
||||
* @param string $meilisearchFieldName
|
||||
* @return bool
|
||||
*/
|
||||
public static function isAllowedToOverrideField($solrFieldName)
|
||||
public static function isAllowedToOverrideField($meilisearchFieldName)
|
||||
{
|
||||
return !in_array($solrFieldName, static::$unAllowedOverrideFields);
|
||||
return !in_array($meilisearchFieldName, static::$unAllowedOverrideFields);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,28 +76,28 @@ abstract class AbstractIndexer
|
||||
protected function addDocumentFieldsFromTyposcript(Document $document, array $indexingConfiguration, array $data) {
|
||||
$data = static::addVirtualContentFieldToRecord($document, $data);
|
||||
|
||||
// mapping of record fields => solr document fields, resolving cObj
|
||||
foreach ($indexingConfiguration as $solrFieldName => $recordFieldName) {
|
||||
// mapping of record fields => meilisearch document fields, resolving cObj
|
||||
foreach ($indexingConfiguration as $meilisearchFieldName => $recordFieldName) {
|
||||
if (is_array($recordFieldName)) {
|
||||
// configuration for a content object, skipping
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!static::isAllowedToOverrideField($solrFieldName)) {
|
||||
if (!static::isAllowedToOverrideField($meilisearchFieldName)) {
|
||||
throw new InvalidFieldNameException(
|
||||
'Must not overwrite field .' . $solrFieldName,
|
||||
'Must not overwrite field .' . $meilisearchFieldName,
|
||||
1435441863
|
||||
);
|
||||
}
|
||||
|
||||
$fieldValue = $this->resolveFieldValue($indexingConfiguration, $solrFieldName, $data);
|
||||
$fieldValue = $this->resolveFieldValue($indexingConfiguration, $meilisearchFieldName, $data);
|
||||
|
||||
if (is_array($fieldValue)) {
|
||||
// multi value
|
||||
$document->setField($solrFieldName, $fieldValue);
|
||||
$document->setField($meilisearchFieldName, $fieldValue);
|
||||
} else {
|
||||
if ($fieldValue !== '' && $fieldValue !== null) {
|
||||
$document->setField($solrFieldName, $fieldValue);
|
||||
$document->setField($meilisearchFieldName, $fieldValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ abstract class AbstractIndexer
|
||||
|
||||
|
||||
/**
|
||||
* Add's the content of the field 'content' from the solr document as virtual field __solr_content in the record,
|
||||
* Add's the content of the field 'content' from the meilisearch document as virtual field __meilisearch_content in the record,
|
||||
* to have it available in typoscript.
|
||||
*
|
||||
* @param Document $document
|
||||
@@ -117,7 +117,7 @@ abstract class AbstractIndexer
|
||||
public static function addVirtualContentFieldToRecord(Document $document, array $data): array
|
||||
{
|
||||
if (isset($document['content'])) {
|
||||
$data['__solr_content'] = $document['content'];
|
||||
$data['__meilisearch_content'] = $document['content'];
|
||||
return $data;
|
||||
}
|
||||
return $data;
|
||||
@@ -131,18 +131,18 @@ abstract class AbstractIndexer
|
||||
* is taken.
|
||||
*
|
||||
* @param array $indexingConfiguration Indexing configuration as defined in plugin.tx_meilisearch_index.queue.[indexingConfigurationName].fields
|
||||
* @param string $solrFieldName A Solr field name that is configured in the indexing configuration
|
||||
* @param string $meilisearchFieldName A Meilisearch field name that is configured in the indexing configuration
|
||||
* @param array $data A record or item's data
|
||||
* @return string The resolved string value to be indexed
|
||||
*/
|
||||
protected function resolveFieldValue(
|
||||
array $indexingConfiguration,
|
||||
$solrFieldName,
|
||||
$meilisearchFieldName,
|
||||
array $data
|
||||
) {
|
||||
$contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
|
||||
|
||||
if (isset($indexingConfiguration[$solrFieldName . '.'])) {
|
||||
if (isset($indexingConfiguration[$meilisearchFieldName . '.'])) {
|
||||
// configuration found => need to resolve a cObj
|
||||
|
||||
// need to change directory to make IMAGE content objects work in BE context
|
||||
@@ -152,21 +152,21 @@ abstract class AbstractIndexer
|
||||
|
||||
$contentObject->start($data, $this->type);
|
||||
$fieldValue = $contentObject->cObjGetSingle(
|
||||
$indexingConfiguration[$solrFieldName],
|
||||
$indexingConfiguration[$solrFieldName . '.']
|
||||
$indexingConfiguration[$meilisearchFieldName],
|
||||
$indexingConfiguration[$meilisearchFieldName . '.']
|
||||
);
|
||||
|
||||
chdir($backupWorkingDirectory);
|
||||
|
||||
if ($this->isSerializedValue($indexingConfiguration,
|
||||
$solrFieldName)
|
||||
$meilisearchFieldName)
|
||||
) {
|
||||
$fieldValue = unserialize($fieldValue);
|
||||
}
|
||||
} elseif (substr($indexingConfiguration[$solrFieldName], 0,
|
||||
} elseif (substr($indexingConfiguration[$meilisearchFieldName], 0,
|
||||
1) === '<'
|
||||
) {
|
||||
$referencedTsPath = trim(substr($indexingConfiguration[$solrFieldName],
|
||||
$referencedTsPath = trim(substr($indexingConfiguration[$meilisearchFieldName],
|
||||
1));
|
||||
$typoScriptParser = GeneralUtility::makeInstance(TypoScriptParser::class);
|
||||
// $name and $conf is loaded with the referenced values.
|
||||
@@ -184,18 +184,18 @@ abstract class AbstractIndexer
|
||||
chdir($backupWorkingDirectory);
|
||||
|
||||
if ($this->isSerializedValue($indexingConfiguration,
|
||||
$solrFieldName)
|
||||
$meilisearchFieldName)
|
||||
) {
|
||||
$fieldValue = unserialize($fieldValue);
|
||||
}
|
||||
} else {
|
||||
$fieldValue = $data[$indexingConfiguration[$solrFieldName]];
|
||||
$fieldValue = $data[$indexingConfiguration[$meilisearchFieldName]];
|
||||
}
|
||||
|
||||
// detect and correct type for dynamic fields
|
||||
|
||||
// find last underscore, substr from there, cut off last character (S/M)
|
||||
$fieldType = substr($solrFieldName, strrpos($solrFieldName, '_') + 1,
|
||||
$fieldType = substr($meilisearchFieldName, strrpos($meilisearchFieldName, '_') + 1,
|
||||
-1);
|
||||
if (is_array($fieldValue)) {
|
||||
foreach ($fieldValue as $key => $value) {
|
||||
@@ -217,17 +217,17 @@ abstract class AbstractIndexer
|
||||
* unserialized.
|
||||
*
|
||||
* @param array $indexingConfiguration Current item's indexing configuration
|
||||
* @param string $solrFieldName Current field being indexed
|
||||
* @param string $meilisearchFieldName Current field being indexed
|
||||
* @return bool TRUE if the value is expected to be serialized, FALSE otherwise
|
||||
*/
|
||||
public static function isSerializedValue(array $indexingConfiguration, $solrFieldName)
|
||||
public static function isSerializedValue(array $indexingConfiguration, $meilisearchFieldName)
|
||||
{
|
||||
$isSerialized = static::isSerializedResultFromRegisteredHook($indexingConfiguration, $solrFieldName);
|
||||
$isSerialized = static::isSerializedResultFromRegisteredHook($indexingConfiguration, $meilisearchFieldName);
|
||||
if ($isSerialized === true) {
|
||||
return $isSerialized;
|
||||
}
|
||||
|
||||
$isSerialized = static::isSerializedResultFromCustomContentElement($indexingConfiguration, $solrFieldName);
|
||||
$isSerialized = static::isSerializedResultFromCustomContentElement($indexingConfiguration, $meilisearchFieldName);
|
||||
return $isSerialized;
|
||||
}
|
||||
|
||||
@@ -235,25 +235,25 @@ abstract class AbstractIndexer
|
||||
* Checks if the response comes from a custom content element that returns a serialized value.
|
||||
*
|
||||
* @param array $indexingConfiguration
|
||||
* @param string $solrFieldName
|
||||
* @param string $meilisearchFieldName
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isSerializedResultFromCustomContentElement(array $indexingConfiguration, $solrFieldName): bool
|
||||
protected static function isSerializedResultFromCustomContentElement(array $indexingConfiguration, $meilisearchFieldName): bool
|
||||
{
|
||||
$isSerialized = false;
|
||||
|
||||
// SOLR_CLASSIFICATION - always returns serialized array
|
||||
if ($indexingConfiguration[$solrFieldName] == Classification::CONTENT_OBJECT_NAME) {
|
||||
if ($indexingConfiguration[$meilisearchFieldName] == Classification::CONTENT_OBJECT_NAME) {
|
||||
$isSerialized = true;
|
||||
}
|
||||
|
||||
// SOLR_MULTIVALUE - always returns serialized array
|
||||
if ($indexingConfiguration[$solrFieldName] == Multivalue::CONTENT_OBJECT_NAME) {
|
||||
if ($indexingConfiguration[$meilisearchFieldName] == Multivalue::CONTENT_OBJECT_NAME) {
|
||||
$isSerialized = true;
|
||||
}
|
||||
|
||||
// SOLR_RELATION - returns serialized array if multiValue option is set
|
||||
if ($indexingConfiguration[$solrFieldName] == Relation::CONTENT_OBJECT_NAME && !empty($indexingConfiguration[$solrFieldName . '.']['multiValue'])) {
|
||||
if ($indexingConfiguration[$meilisearchFieldName] == Relation::CONTENT_OBJECT_NAME && !empty($indexingConfiguration[$meilisearchFieldName . '.']['multiValue'])) {
|
||||
$isSerialized = true;
|
||||
}
|
||||
|
||||
@@ -264,23 +264,23 @@ abstract class AbstractIndexer
|
||||
* Checks registered hooks if a SerializedValueDetector detects a serialized response.
|
||||
*
|
||||
* @param array $indexingConfiguration
|
||||
* @param string $solrFieldName
|
||||
* @param string $meilisearchFieldName
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isSerializedResultFromRegisteredHook(array $indexingConfiguration, $solrFieldName)
|
||||
protected static function isSerializedResultFromRegisteredHook(array $indexingConfiguration, $meilisearchFieldName)
|
||||
{
|
||||
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['detectSerializedValue'])) {
|
||||
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['meilisearch']['detectSerializedValue'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['detectSerializedValue'] as $classReference) {
|
||||
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['meilisearch']['detectSerializedValue'] as $classReference) {
|
||||
$serializedValueDetector = GeneralUtility::makeInstance($classReference);
|
||||
if (!$serializedValueDetector instanceof SerializedValueDetector) {
|
||||
$message = get_class($serializedValueDetector) . ' must implement interface ' . SerializedValueDetector::class;
|
||||
throw new \UnexpectedValueException($message, 1404471741);
|
||||
}
|
||||
|
||||
$isSerialized = (boolean)$serializedValueDetector->isSerializedValue($indexingConfiguration, $solrFieldName);
|
||||
$isSerialized = (boolean)$serializedValueDetector->isSerializedValue($indexingConfiguration, $meilisearchFieldName);
|
||||
if ($isSerialized) {
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user