Example #1
0
 /**
  * Merge with another field, returning the new instance
  *
  * @param Field $other
  * @return Field
  * @throws MergeException
  */
 public function mergeWith(Field $other)
 {
     if (($name = $other->getName()) !== $this->name) {
         throw new MergeException(sprintf("Fields have different names (%s vs %s)", $this->name, $name));
     }
     // Since mapping is merged between databoxes, two fields may
     // have conflicting names. Indexing is the same for a given
     // type so we reject only those with different types.
     if (($type = $other->getType()) !== $this->type) {
         throw new MergeException(sprintf("Field %s can't be merged, incompatible types (%s vs %s)", $name, $type, $this->type));
     }
     if ($other->isPrivate() !== $this->is_private) {
         throw new MergeException(sprintf("Field %s can't be merged, could not mix private and public fields with same name", $name));
     }
     if ($other->isSearchable() !== $this->is_searchable) {
         throw new MergeException(sprintf("Field %s can't be merged, incompatible searchablility", $name));
     }
     if ($other->getFacetValuesLimit() !== $this->facet) {
         throw new MergeException(sprintf("Field %s can't be merged, incompatible facet eligibility", $name));
     }
     $thesaurus_roots = null;
     if ($this->thesaurus_roots !== null || $other->thesaurus_roots !== null) {
         $thesaurus_roots = array_merge((array) $this->thesaurus_roots, (array) $other->thesaurus_roots);
     }
     $used_by_collections = array_values(array_unique(array_merge($this->used_by_collections, $other->used_by_collections), SORT_REGULAR));
     return $this->withOptions(['thesaurus_roots' => $thesaurus_roots, 'used_by_collections' => $used_by_collections]);
 }
Example #2
0
 private function addFieldToMapping(Field $field, Mapping $mapping)
 {
     $type = $field->getType();
     $mapping->add($field->getName(), $type);
     if ($type === Mapping::TYPE_DATE) {
         $mapping->format(Mapping::DATE_FORMAT_CAPTION);
     }
     if ($type === Mapping::TYPE_STRING) {
         $searchable = $field->isSearchable();
         $facet = $field->isFacet();
         if (!$searchable && !$facet) {
             $mapping->notIndexed();
         } else {
             $mapping->addRawVersion();
             $mapping->addAnalyzedVersion($this->locales);
             $mapping->enableTermVectors(true);
         }
     }
 }