/** * modifies a document according to the given configuration * * @param Apache_Solr_Document $document * @param array $processingConfiguration */ public function processDocument(Apache_Solr_Document $document, array $processingConfiguration) { foreach ($processingConfiguration as $fieldName => $instruction) { $fieldInformation = $document->getField($fieldName); $isSingleValueField = FALSE; if ($fieldInformation !== FALSE) { $fieldValue = $fieldInformation['value']; if (!is_array($fieldValue)) { // turn single value field into multi value field $fieldValue = array($fieldValue); $isSingleValueField = TRUE; } switch ($instruction) { case 'timestampToIsoDate': $processor = t3lib_div::makeInstance('tx_solr_fieldprocessor_TimestampToIsoDate'); $fieldValue = $processor->process($fieldValue); break; case 'uppercase': $fieldValue = array_map('strtoupper', $fieldValue); break; } if ($isSingleValueField) { // turn multi value field back into single value field $fieldValue = $fieldValue[0]; } $document->setField($fieldName, $fieldValue); } } }
/** * @test */ public function transformsUnixTimestampToIsoDateOnMultiValuedField() { $this->documentMock->addField('dateField', '1262343600'); // 2010-01-01 12:00 $this->documentMock->addField('dateField', '1262343601'); // 2010-01-01 12:01 $configuration = array('dateField' => 'timestampToIsoDate'); $this->service->processDocument($this->documentMock, $configuration); $value = $this->documentMock->getField('dateField'); $this->assertEquals($value['value'], array('2010-01-01T12:00:00Z', '2010-01-01T12:00:01Z'), 'field was not processed with timestampToIsoDate'); }
public function testMagicSetForFieldValues() { $field = 'field'; $value = 'value'; // set field value with magic __set $this->_fixture->{$field} = $value; $fieldArray = $this->_fixture->getField($field); // set values $this->assertEquals($field, $fieldArray['name']); $this->assertEquals($value, $fieldArray['value']); $this->assertTrue($fieldArray['boost'] === false); }
/** * modifies a document according to the given configuration * * @param \Apache_Solr_Document $document * @param array $processingConfiguration */ public function processDocument(\Apache_Solr_Document $document, array $processingConfiguration) { foreach ($processingConfiguration as $fieldName => $instruction) { $fieldInformation = $document->getField($fieldName); $isSingleValueField = false; if ($fieldInformation !== false) { $fieldValue = $fieldInformation['value']; if (!is_array($fieldValue)) { // turn single value field into multi value field $fieldValue = array($fieldValue); $isSingleValueField = true; } switch ($instruction) { case 'timestampToUtcIsoDate': $processor = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\FieldProcessor\\TimestampToUtcIsoDate'); $fieldValue = $processor->process($fieldValue); break; case 'timestampToIsoDate': $processor = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\FieldProcessor\\TimestampToIsoDate'); $fieldValue = $processor->process($fieldValue); break; case 'pathToHierarchy': $processor = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\FieldProcessor\\PathToHierarchy'); $fieldValue = $processor->process($fieldValue); break; case 'pageUidToHierarchy': $processor = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\FieldProcessor\\PageUidToHierarchy'); $fieldValue = $processor->process($fieldValue); break; case 'categoryUidToHierarchy': $processor = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\FieldProcessor\\CategoryUidToHierarchy'); $fieldValue = $processor->process($fieldValue); break; case 'uppercase': $fieldValue = array_map('strtoupper', $fieldValue); break; } if ($isSingleValueField) { // turn multi value field back into single value field $fieldValue = $fieldValue[0]; } $document->setField($fieldName, $fieldValue); } } }
/** * modifies a document according to the given configuration * * @param Apache_Solr_Document $document * @param array $processingConfiguration */ public function processDocument(Apache_Solr_Document $document, array $processingConfiguration) { foreach ($processingConfiguration as $fieldName => $instruction) { $fieldInformation = $document->getField($fieldName); $isSingleValueField = FALSE; if ($fieldInformation !== FALSE) { $fieldValue = $fieldInformation['value']; if (!is_array($fieldValue)) { // turn single value field into multi value field $fieldValue = array($fieldValue); $isSingleValueField = TRUE; } switch ($instruction) { case 'timestampToUtcIsoDate': $processor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_FieldProcessor_TimestampToUtcIsoDate'); $fieldValue = $processor->process($fieldValue); break; case 'timestampToIsoDate': $processor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_FieldProcessor_TimestampToIsoDate'); $fieldValue = $processor->process($fieldValue); break; case 'pathToHierarchy': $processor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_FieldProcessor_PathToHierarchy'); $fieldValue = $processor->process($fieldValue); break; case 'pageUidToHierarchy': $processor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_FieldProcessor_PageUidToHierarchy'); $fieldValue = $processor->process($fieldValue); break; case 'categoryUidToHierarchy': $processor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_FieldProcessor_CategoryUidToHierarchy'); $fieldValue = $processor->process($fieldValue); break; case 'uppercase': $fieldValue = array_map('strtoupper', $fieldValue); break; } if ($isSingleValueField) { // turn multi value field back into single value field $fieldValue = $fieldValue[0]; } $document->setField($fieldName, $fieldValue); } } }
<?php require dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new limeade_test(2, limeade_output::get()); $t->diag('document format a document'); $document = new Apache_Solr_Document(); $document->setBoost(10); $document->setField('sfl_guid', 'GUID_1234'); $document->setField('name', 'Thomas Rabaix', 1); $document->setMultiValue('skills', 'php'); $document->setMultiValue('skills', 'symfony'); $document->addField('skills', 'objective-c'); $expected = array('name' => 'skills', 'value' => array(0 => 'php', 1 => 'symfony', 2 => 'objective-c'), 'boost' => false); $t->cmp_ok($document->getField('skills'), '==', $expected, '::getField test multivalue setter'); $expected = array('name' => 'name', 'value' => 'Thomas Rabaix', 'boost' => 1); $t->cmp_ok($document->getField('name'), '==', $expected, '::getField test setter');