/**
  * @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 $boostFieldName
  * @param $boostFieldValue
  * @param $boostOptionName
  * @param $boostOptionValue
  * @param $boostingValue
  * @param $count
  * @return array
  */
 protected function generateContextsBoosting($boostFieldName, $boostFieldValue, $boostOptionName, $boostOptionValue, $boostingValue, $count)
 {
     $result = [];
     for ($i = 0; $i < $count; $i++) {
         $contextsBoosting = new ContextsBoosting();
         $contextsBoosting->setBoostFieldName($boostFieldName . $i);
         $contextsBoosting->setBoostFieldValue($boostFieldValue . $i);
         $contextsBoosting->setBoostOptionName($boostOptionName . $i);
         $contextsBoosting->setBoostOptionValue($boostOptionValue);
         $contextsBoosting->setBoostingValue($boostingValue + $i);
         $result[] = $contextsBoosting;
     }
     return $result;
 }