/** * @param \SimpleXMLElement $xml * * @return \Searchperience\Api\Client\Domain\Enrichment\EnrichmentCollection */ protected function buildEnrichmentsFromXml(\SimpleXMLElement $xml) { $enrichmentCollection = new EnrichmentCollection(); if ($xml->totalCount instanceof \SimpleXMLElement) { $enrichmentCollection->setTotalCount((int) $xml->totalCount->__toString()); } $enrichments = $xml->xpath('enrichment'); foreach ($enrichments as $enrichment) { $enrichmentAttributeArray = (array) $enrichment->attributes(); $enrichmentObject = new \Searchperience\Api\Client\Domain\Enrichment\Enrichment(); $enrichmentObject->__setProperty('id', (int) $enrichmentAttributeArray['@attributes']['id']); $enrichmentObject->__setProperty('title', (string) $enrichment->title); $enrichmentObject->__setProperty('addBoost', (string) $enrichment->addBoost); $enrichmentObject->__setProperty('description', (string) $enrichment->description); $enrichmentObject->__setProperty('enabled', (bool) (int) $enrichment->status); if (isset($enrichment->matchingrules->matchingrule)) { foreach ($enrichment->matchingrules->matchingrule as $matchingrule) { $matchingRuleObject = new \Searchperience\Api\Client\Domain\Enrichment\MatchingRule(); $matchingRuleObject->__setProperty('operator', (string) $matchingrule->operator); $matchingRuleObject->__setProperty('fieldName', (string) $matchingrule->fieldName); $matchingRuleObject->__setProperty('operandValue', (string) $matchingrule->operandValue); $matchingRules = $enrichmentObject->getMatchingRules(); $matchingRules->append($matchingRuleObject); $matchingRuleObject->afterReconstitution(); $enrichmentObject->__setProperty('matchingRules', $matchingRules); } } if (isset($enrichment->fieldenrichments->fieldenrichment)) { foreach ($enrichment->fieldenrichments->fieldenrichment as $fieldenrichment) { $fieldEnrichmentObject = new \Searchperience\Api\Client\Domain\Enrichment\FieldEnrichment(); $fieldEnrichmentObject->__setProperty('fieldName', (string) $fieldenrichment->fieldName); $fieldEnrichmentObject->__setProperty('content', (string) $fieldenrichment->content); $fieldEnrichments = $enrichmentObject->getFieldEnrichments(); $fieldEnrichments->append($fieldEnrichmentObject); $fieldEnrichmentObject->afterReconstitution(); $enrichmentObject->__setProperty('fieldEnrichments', $fieldEnrichments); } } if (isset($enrichment->contextsBoosting->context)) { foreach ($enrichment->contextsBoosting->context as $context) { $contextsBoostingObject = new ContextsBoosting(); $contextsBoostingObject->__setProperty('boostFieldName', (string) $context->boostFieldName); $contextsBoostingObject->__setProperty('boostFieldValue', (string) $context->boostFieldValue); $contextsBoostingObject->__setProperty('boostOptionName', (string) $context->boostOptionName); $contextsBoostingObject->__setProperty('boostOptionValue', (bool) (int) $context->boostOptionValue); $contextsBoostingObject->__setProperty('boostingValue', (double) $context->boostingValue); $contextsBoosting = $enrichmentObject->getContextsBoosting(); $contextsBoosting->append($contextsBoostingObject); $contextsBoostingObject->afterReconstitution(); $enrichmentObject->__setProperty('contextsBoosting', $contextsBoosting); } } $enrichmentObject->afterReconstitution(); $enrichmentCollection->append($enrichmentObject); } return $enrichmentCollection; }
/** * @param EnrichmentCollection $enrichments * @return EnrichmentCollection */ private function decorateEnrichments(EnrichmentCollection $enrichments) { $newCollection = new EnrichmentCollection(); $newCollection->setTotalCount($enrichments->getTotalCount()); foreach ($enrichments as $enrichment) { $newCollection->append($this->checkTypeAndDecorate($enrichment)); } return $newCollection; }