/**
  * @test
  */
 public function verifyKeywordsGetsSetWithFieldEnrichments()
 {
     $fixtureEnrichment = new Enrichment();
     $fieldEnrichmentLow = new FieldEnrichment();
     $fieldEnrichmentLow->setFieldName('lowboostw');
     $fieldEnrichmentLow->setContent('low low low');
     $fixtureEnrichment->addFieldEnrichment($fieldEnrichmentLow);
     $fieldEnrichmentNormal = new FieldEnrichment();
     $fieldEnrichmentNormal->setFieldName('normalboostw');
     $fieldEnrichmentNormal->setContent('normal normal normal');
     $fixtureEnrichment->addFieldEnrichment($fieldEnrichmentNormal);
     $fieldEnrichmentHigh = new FieldEnrichment();
     $fieldEnrichmentHigh->setFieldName('highboostw');
     $fieldEnrichmentHigh->setContent('high high high');
     $fixtureEnrichment->addFieldEnrichment($fieldEnrichmentHigh);
     $this->enrichment->setLowBoostedKeywords('low low low');
     $this->enrichment->setNormalBoostedKeywords('normal normal normal');
     $this->enrichment->setHighBoostedKeywords('high high high');
     $this->assertEquals($this->enrichment, $fixtureEnrichment);
 }
 /**
  * @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;
 }
 /**
  * Set field enrichment by field name
  *
  * @param string $fieldName
  * @param $value
  */
 protected function setBoostWordsByFieldName($fieldName, $value)
 {
     //if we have allready enrichments for this fieldName we remove them
     //and create a new fieldEnrichment right away
     if ($this->hasFieldEnrichmentForFieldName($fieldName)) {
         $this->removeFieldEnrichmentsForFieldName($fieldName);
     }
     //when we set the boostword fieldValue to an empty value, we semantically remove the field enrichment
     $wasFieldReset = trim($value) == '';
     if ($wasFieldReset) {
         return;
     }
     $fieldEnrichment = new FieldEnrichment();
     $fieldEnrichment->setFieldName($fieldName);
     $fieldEnrichment->setContent($value);
     $this->addFieldEnrichment($fieldEnrichment);
 }